src/newgrf.cpp
author celestar
Wed, 13 Jun 2007 12:05:56 +0000
branchgamebalance
changeset 9912 1ac8aac92385
parent 9911 0b8b245a2391
child 9913 e79cd19772dd
permissions -rw-r--r--
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
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
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
     3
/** @file newgrf.cpp */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
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 "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "fileio.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
    13
#include "functions.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "engine.h"
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
    15
#include "spritecache.h"
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    16
#include "station.h"
405
6830ae7a0d5d (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents: 404
diff changeset
    17
#include "sprite.h"
452
520e4ed6945d (svn r662) [newgrf] Moved grfspecial.c to newgrf.c/newgrf.h
dominik
parents: 449
diff changeset
    18
#include "newgrf.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2013
diff changeset
    19
#include "variables.h"
3566
7bdf06a03960 (svn r4447) - NewGRF: It seems I committed printing action NOP Action 0x0C which is mainly used for comments. So leave it in, but fix the created warning. Use proper action name for check_length() in Action 0x10
Darkvater
parents: 3561
diff changeset
    20
#include "string.h"
3821
2bb8a2643fdf (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3814
diff changeset
    21
#include "table/strings.h"
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
    22
#include "bridge.h"
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
    23
#include "town.h"
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
    24
#include "economy.h"
2962
dbd168a4703a (svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents: 2958
diff changeset
    25
#include "newgrf_engine.h"
3577
9e345c932ba2 (svn r4463) -Codechange. Include vehicle.h directly instead of implicitly via station.h in a number of source files
celestar
parents: 3571
diff changeset
    26
#include "vehicle.h"
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
    27
#include "newgrf_text.h"
3708
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
    28
#include "table/sprites.h"
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
    29
#include "fontcache.h"
4293
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4230
diff changeset
    30
#include "date.h"
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
    31
#include "currency.h"
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
    32
#include "landscape.h"
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    33
#include "sound.h"
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
    34
#include "newgrf_config.h"
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
    35
#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
    36
#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
    37
#include "newgrf_spritegroup.h"
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    38
#include "helpers.hpp"
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
    39
#include "table/town_land.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
    40
#include "cargotype.h"
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
    41
#include "industry.h"
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
    42
#include "newgrf_canal.h"
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
    43
#include "newgrf_commons.h"
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
    44
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
/* TTDPatch extended GRF format codec
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
 * (c) Petr Baudis 2004 (GPL'd)
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
    47
 * 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
    48
 *
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
 * Contains portions of documentation by TTDPatch team.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
 * 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
    51
 * 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
    52
 * 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
    53
455
e7ac799e1437 (svn r665) code fixes for newgrf.c/newgrf.h
dominik
parents: 452
diff changeset
    54
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
    55
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
    56
static uint _file_index; // XXX
5209
fa3ad39e2fa7 (svn r7324) -Codechange: reset newgrf signal location data
peter1138
parents: 5161
diff changeset
    57
SpriteID _signal_base;
5210
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
    58
SpriteID _coast_base;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
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
    60
static GRFFile *_cur_grffile;
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    61
GRFFile *_first_grffile;
3707
2999a89e8abd (svn r4650) - NewGRF: use the correct type for _cur_spriteid
peter1138
parents: 3704
diff changeset
    62
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
    63
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
    64
static uint32 _nfo_line;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
    66
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
    67
3814
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
    68
/* 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
    69
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
    70
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
    71
/* 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
    72
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
    73
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
    74
/* 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
    75
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
    76
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
    77
/* Indicates which are the newgrf features currently loaded ingame */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
    78
uint8 _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
    79
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
    80
enum GrfDataType {
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    81
	GDT_SOUND,
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
    82
};
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    83
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    84
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
    85
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
    86
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    87
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
    88
enum grfspec_feature {
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    89
	GSF_TRAIN,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    90
	GSF_ROAD,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    91
	GSF_SHIP,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    92
	GSF_AIRCRAFT,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    93
	GSF_STATION,
2438
eaef2b29fa3d (svn r2964) Fix: newgrf: Include missing grf feature canal.
peter1138
parents: 2421
diff changeset
    94
	GSF_CANAL,
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
    95
	GSF_BRIDGE,
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
    96
	GSF_TOWNHOUSE,
3620
b459e678a003 (svn r4517) - NewGRF: fix and complete the feature list
peter1138
parents: 3614
diff changeset
    97
	GSF_GLOBALVAR,
b459e678a003 (svn r4517) - NewGRF: fix and complete the feature list
peter1138
parents: 3614
diff changeset
    98
	GSF_INDUSTRYTILES,
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
    99
	GSF_INDUSTRIES,
3620
b459e678a003 (svn r4517) - NewGRF: fix and complete the feature list
peter1138
parents: 3614
diff changeset
   100
	GSF_CARGOS,
b459e678a003 (svn r4517) - NewGRF: fix and complete the feature list
peter1138
parents: 3614
diff changeset
   101
	GSF_SOUNDFX,
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   102
};
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   103
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   104
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
typedef void (*SpecialSpriteHandler)(byte *buf, int len);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   107
static const uint _vehcounts[4] = {
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   108
	/* GSF_TRAIN */    NUM_TRAIN_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   109
	/* GSF_ROAD */     NUM_ROAD_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   110
	/* GSF_SHIP */     NUM_SHIP_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   111
	/* GSF_AIRCRAFT */ NUM_AIRCRAFT_ENGINES
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   112
};
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   113
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   114
static const uint _vehshifts[4] = {
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   115
	/* GSF_TRAIN */    0,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   116
	/* GSF_ROAD */     ROAD_ENGINES_INDEX,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   117
	/* GSF_SHIP */     SHIP_ENGINES_INDEX,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   118
	/* GSF_AIRCRAFT */ AIRCRAFT_ENGINES_INDEX,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
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
   121
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
   122
	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
   123
};
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
   124
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   125
static uint16 cargo_allowed[TOTAL_NUM_ENGINES];
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   126
static uint16 cargo_disallowed[TOTAL_NUM_ENGINES];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
   128
/* Contains the GRF ID of the owner of a vehicle if it has been reserved */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
   129
static uint32 _grm_engines[TOTAL_NUM_ENGINES];
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
   130
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   131
/* Contains the GRF ID of the owner of a cargo if it has been reserved */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   132
static uint32 _grm_cargos[NUM_CARGO];
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   133
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   134
/** 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
   135
 * 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
   136
 * 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
   137
 * 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
   138
 * 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
   139
 * 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
   140
 * @param severity debugging severity level, see debug.h
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
   141
 * @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
   142
void CDECL grfmsg(int severity, const char *str, ...)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
{
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 51
diff changeset
   144
	char buf[1024];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
	va_start(va, str);
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   148
	vsnprintf(buf, sizeof(buf), str, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
	va_end(va);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   150
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   151
	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
   152
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
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
   154
static inline bool check_length(int real, int wanted, const char *str)
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
   155
{
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
   156
	if (real >= wanted) return true;
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
   157
	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
   158
	return false;
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
   159
}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   160
500
ef288590e096 (svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents: 490
diff changeset
   161
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
   162
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	return *(*buf)++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
static uint16 grf_load_word(byte **buf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
{
3711
4a0d1c635b56 (svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.
Darkvater
parents: 3709
diff changeset
   168
	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
   169
	return val | (grf_load_byte(buf) << 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   172
static uint16 grf_load_extended(byte** buf)
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   173
{
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   174
	uint16 val;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   175
	val = grf_load_byte(buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   176
	if (val == 0xFF) val = grf_load_word(buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   177
	return val;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   178
}
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   179
2324
117bd73a0731 (svn r2850) [newgrf] Patch from peter1139
miham
parents: 2204
diff changeset
   180
static uint32 grf_load_dword(byte **buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
{
3711
4a0d1c635b56 (svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.
Darkvater
parents: 3709
diff changeset
   182
	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
   183
	return val | (grf_load_word(buf) << 16);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
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
   186
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
   187
{
d7ed0a867b49 (svn 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
	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
   189
		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
   190
		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
   191
		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
   192
		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
   193
			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
   194
			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
   195
	}
d7ed0a867b49 (svn 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
}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   197
6416
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   198
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
   199
{
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   200
	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
   201
	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
   202
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   203
	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
   204
		/* 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
   205
		(*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
   206
		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
   207
	} else {
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   208
		/* 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
   209
		string_length++;
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   210
	}
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   211
	*buf += 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
	return string;
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
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   216
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
   217
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   218
	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
   219
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   220
	for (file = _first_grffile; file != NULL; file = file->next) {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   221
		if (file->grfid == grfid) break;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   222
	}
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
   223
	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
   224
}
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
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   226
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
   227
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   228
	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
   229
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   230
	for (file = _first_grffile; file != NULL; file = file->next) {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   231
		if (strcmp(file->filename, filename) == 0) break;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   232
	}
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   233
	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
   234
}
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
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
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   237
/** Used when setting an object's property to map to the GRF's strings
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   238
 * while taking in consideration the "drift" between TTDPatch string system and OpenTTD's one
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
   239
 * @param grfid Id of the grf file
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   240
 * @param str StringID that we want to have the equivalent in OoenTTD
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   241
 * @return the properly adjusted StringID
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   242
 */
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   243
static StringID MapGRFStringID(uint32 grfid, StringID str)
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   244
{
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   245
	/* 0xD0 and 0xDC stand for all the TextIDs in the range
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   246
	 * of 0xD000 (misc graphics texts) and 0xDC00 (misc persistent texts).
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   247
	 * These strings are unique to each grf file, and thus require to be used with the
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   248
	 * grfid in which they are declared */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   249
	if (GB(str, 8, 8) == 0xD0 || GB(str, 8, 8) == 0xDC) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   250
		return GetGRFStringID(grfid, str);
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   251
	}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   252
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   253
	/* We have some changes in our cargo strings, resulting in some missing. */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   254
	if (str >= 0x006E && str <= 0x008D) return str - 0x20;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   255
	if (str >= 0x008E && str <= 0x00AD) return str - 0x20;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   256
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   257
	/* Map building names according to our lang file changes
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   258
	 * 0x200F = Tall Office Block, first house name in the original data, the one that TTDPatch stil uses
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   259
	 * 0x201F = Old houses is the last house name.
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   260
	 * OpenTTD does not have exactly the same order aymore, so, the code below allows
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   261
	 * to compensate for the difference */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   262
	if (str >= 0x200F && str <= 0x201F) return str + (STR_200F_TALL_OFFICE_BLOCK - 0x200F);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   263
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   264
	return str;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   265
}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   266
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   267
static uint8 MapDOSColour(uint8 colour)
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   268
{
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   269
	if (_use_dos_palette) return colour;
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   270
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   271
	if (colour < 10) {
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   272
		static uint8 dos_to_win_colour_map[] = { 0, 215, 216, 136, 88, 106, 32, 33, 40, 245 };
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   273
		return dos_to_win_colour_map[colour];
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   274
	}
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   275
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   276
	if (colour >= 245 && colour < 254) return colour - 28;
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   277
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   278
	return colour;
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   279
}
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   280
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
   281
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   282
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
   283
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   284
#define FOR_EACH_OBJECT for (i = 0; i < numinfo; i++)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
static void dewagonize(int condition, int engine)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
	EngineInfo *ei = &_engine_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   291
	if (condition != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
		ei->unk2 &= ~0x80;
6356
688f81d17aec (svn r8753) -Regression (r8455): Do not unilateraly decide that this engine is a single-headed. Only do it if it previously had no power and that now there is. Or something...
belugas
parents: 6223
diff changeset
   293
		if (rvi->railveh_type == RAILVEH_WAGON)
688f81d17aec (svn r8753) -Regression (r8455): Do not unilateraly decide that this engine is a single-headed. Only do it if it previously had no power and that now there is. Or something...
belugas
parents: 6223
diff changeset
   294
			rvi->railveh_type = RAILVEH_SINGLEHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
		ei->unk2 |= 0x80;
6119
b47985557d1e (svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents: 6106
diff changeset
   297
		rvi->railveh_type = RAILVEH_WAGON;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   301
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
   302
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
	EngineInfo *ei = &_engine_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
	byte *buf = *bufp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
	int i;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   307
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
	switch (prop) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   310
		case 0x05: // Track type
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   311
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
				uint8 tracktype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
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
   314
				switch (tracktype) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   315
					case 0: rvi[i].railtype = rvi[i].engclass >= 2 ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL; break;
6014
f3f333d167c4 (svn r8314) -Fix
tron
parents: 5919
diff changeset
   316
					case 1: rvi[i].railtype = RAILTYPE_MONO; break;
f3f333d167c4 (svn r8314) -Fix
tron
parents: 5919
diff changeset
   317
					case 2: rvi[i].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
   318
					default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   319
						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
   320
						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
   321
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
			}
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
   323
			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
   324
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   325
		case 0x08: // AI passenger service
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   326
			/* @todo missing feature */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   327
			FOR_EACH_OBJECT grf_load_byte(&buf);
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   328
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   329
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   330
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   331
		case 0x09: // Speed (1 unit is 1 kmh)
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   332
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
				uint16 speed = grf_load_word(&buf);
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   334
				if (speed == 0xFFFF) speed = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
				rvi[i].max_speed = speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   338
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   339
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   340
		case 0x0B: // Power
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   341
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
				uint16 power = grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
6119
b47985557d1e (svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents: 6106
diff changeset
   344
				if (rvi[i].railveh_type == RAILVEH_MULTIHEAD) power /= 2;
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   345
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
				rvi[i].power = power;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
				dewagonize(power, engine + i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   349
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   350
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   351
		case 0x0D: // Running cost factor
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   352
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
				uint8 runcostfact = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
6119
b47985557d1e (svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents: 6106
diff changeset
   355
				if (rvi[i].railveh_type == RAILVEH_MULTIHEAD) runcostfact /= 2;
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   356
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
				rvi[i].running_cost_base = runcostfact;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   359
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   360
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   361
		case 0x0E: // Running cost base
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   362
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
				uint32 base = grf_load_dword(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
				switch (base) {
2840
d68a605b2087 (svn r3388) - NewGRF: Allow train running cost class to differ from engine class. Also fix typo in r3384.
peter1138
parents: 2838
diff changeset
   366
					case 0x4C30: rvi[i].running_cost_class = 0; break;
d68a605b2087 (svn r3388) - NewGRF: Allow train running cost class to differ from engine class. Also fix typo in r3384.
peter1138
parents: 2838
diff changeset
   367
					case 0x4C36: rvi[i].running_cost_class = 1; break;
d68a605b2087 (svn r3388) - NewGRF: Allow train running cost class to differ from engine class. Also fix typo in r3384.
peter1138
parents: 2838
diff changeset
   368
					case 0x4C3C: rvi[i].running_cost_class = 2; break;
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   369
					case 0: break; // Used by wagons
5324
b2429a2def00 (svn r7485) -Codechange: [NewGRF] Add debug warning for unsupported running cost bases for rail vehicles.
peter1138
parents: 5317
diff changeset
   370
					default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   371
						grfmsg(1, "RailVehicleChangeInfo: Unsupported running cost base 0x%04X, ignoring", base);
5324
b2429a2def00 (svn r7485) -Codechange: [NewGRF] Add debug warning for unsupported running cost bases for rail vehicles.
peter1138
parents: 5317
diff changeset
   372
						break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   375
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   376
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   377
		case 0x12: // Sprite ID
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   378
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
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
   381
				/* 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
   382
				 * 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
   383
				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
   384
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
				rvi[i].image_index = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   387
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   388
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   389
		case 0x13: // Dual-headed
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   390
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
				uint8 dual = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   393
				if (dual != 0) {
6119
b47985557d1e (svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents: 6106
diff changeset
   394
					if (rvi[i].railveh_type != RAILVEH_MULTIHEAD) {
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   395
						// adjust power and running cost if needed
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   396
						rvi[i].power /= 2;
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   397
						rvi[i].running_cost_base /= 2;
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   398
					}
6119
b47985557d1e (svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents: 6106
diff changeset
   399
					rvi[i].railveh_type = RAILVEH_MULTIHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
				} else {
6119
b47985557d1e (svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents: 6106
diff changeset
   401
					if (rvi[i].railveh_type == RAILVEH_MULTIHEAD) {
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   402
						// adjust power and running cost if needed
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   403
						rvi[i].power *= 2;
2840
d68a605b2087 (svn r3388) - NewGRF: Allow train running cost class to differ from engine class. Also fix typo in r3384.
peter1138
parents: 2838
diff changeset
   404
						rvi[i].running_cost_base *= 2;
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   405
					}
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
   406
					rvi[i].railveh_type = rvi[i].power == 0 ?
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
   407
						RAILVEH_WAGON : RAILVEH_SINGLEHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   410
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   411
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   412
		case 0x14: // Cargo capacity
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   413
			FOR_EACH_OBJECT rvi[i].capacity = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   414
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   415
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   416
		case 0x15: // Cargo type
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   417
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
				uint8 ctype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   420
				if (ctype < NUM_CARGO && HASBIT(_cargo_mask, 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
   421
					rvi[i].cargo_type = ctype;
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   422
				} else {
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
   423
					rvi[i].cargo_type = CT_INVALID;
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
   424
					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
   425
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
			}
3023
e56ff3134c77 (svn r3603) - NewGRF: Support loading of AI rank data
peter1138
parents: 3006
diff changeset
   427
			break;
e56ff3134c77 (svn r3603) - NewGRF: Support loading of AI rank data
peter1138
parents: 3006
diff changeset
   428
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   429
		case 0x16: // Weight
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   430
			FOR_EACH_OBJECT SB(rvi[i].weight, 0, 8, grf_load_byte(&buf));
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   431
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   432
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   433
		case 0x17: // Cost factor
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   434
			FOR_EACH_OBJECT rvi[i].base_cost = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   435
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   436
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   437
		case 0x18: // AI rank
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   438
			FOR_EACH_OBJECT rvi[i].ai_rank = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   439
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   440
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   441
		case 0x19: // Engine traction type
2838
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   442
			/* What do the individual numbers mean?
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   443
			 * 0x00 .. 0x07: Steam
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   444
			 * 0x08 .. 0x27: Diesel
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   445
			 * 0x28 .. 0x31: Electric
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   446
			 * 0x32 .. 0x37: Monorail
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   447
			 * 0x38 .. 0x41: Maglev
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   448
			 */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   449
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
				uint8 traction = grf_load_byte(&buf);
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   451
				EngineClass engclass;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   453
				if (traction <= 0x07) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   454
					engclass = EC_STEAM;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   455
				} else if (traction <= 0x27) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   456
					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
   457
				} else if (traction <= 0x31) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   458
					engclass = EC_ELECTRIC;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   459
				} else if (traction <= 0x37) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   460
					engclass = EC_MONORAIL;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   461
				} else if (traction <= 0x41) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   462
					engclass = EC_MAGLEV;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   463
				} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
					break;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   465
				}
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   466
				if (rvi[i].railtype == RAILTYPE_RAIL     && engclass >= EC_ELECTRIC) rvi[i].railtype = RAILTYPE_ELECTRIC;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   467
				if (rvi[i].railtype == RAILTYPE_ELECTRIC && engclass  < EC_ELECTRIC) rvi[i].railtype = RAILTYPE_RAIL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
				rvi[i].engclass = engclass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   471
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   472
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   473
		case 0x1A: // Alter purchase list sort order
2971
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   474
			FOR_EACH_OBJECT {
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   475
				EngineID pos = grf_load_byte(&buf);
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   476
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   477
				if (pos < NUM_TRAIN_ENGINES) {
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   478
					AlterRailVehListOrder(engine + i, pos);
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   479
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   480
					grfmsg(2, "RailVehicleChangeInfo: Invalid train engine ID %d, ignoring", pos);
2971
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   481
				}
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   482
			}
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   483
			break;
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   484
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   485
		case 0x1B: // Powered wagons power bonus
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   486
			FOR_EACH_OBJECT rvi[i].pow_wag_power = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   487
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   488
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   489
		case 0x1C: // Refit cost
3997
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   490
			FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf);
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   491
			break;
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   492
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   493
		case 0x1D: // Refit cargo
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   494
			FOR_EACH_OBJECT ei[i].refit_mask = grf_load_dword(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   495
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   496
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   497
		case 0x1E: // Callback
3956
0f43adbc293a (svn r5105) - NewGRF: Move callbackmask from *VehicleInfo to EngineInfo. This simplifies code that works with more than one vehicle type.
peter1138
parents: 3924
diff changeset
   498
			FOR_EACH_OBJECT ei[i].callbackmask = grf_load_byte(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   499
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   500
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   501
		case 0x1F: // Tractive effort coefficient
5588
1bcb6b4c01d8 (svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents: 5570
diff changeset
   502
			FOR_EACH_OBJECT rvi[i].tractive_effort = grf_load_byte(&buf);
1bcb6b4c01d8 (svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents: 5570
diff changeset
   503
			break;
1bcb6b4c01d8 (svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents: 5570
diff changeset
   504
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   505
		case 0x21: // Shorter vehicle
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   506
			FOR_EACH_OBJECT rvi[i].shorten_factor = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   507
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   508
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   509
		case 0x22: // Visual effect
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   510
			/* see note in engine.h about rvi->visual_effect */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   511
			FOR_EACH_OBJECT rvi[i].visual_effect = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   512
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   513
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   514
		case 0x23: // Powered wagons weight bonus
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   515
			FOR_EACH_OBJECT rvi[i].pow_wag_weight = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   516
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   517
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   518
		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
   519
			FOR_EACH_OBJECT {
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   520
				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
   521
2545
d1965652e523 (svn r3074) -NewGrf: Fix stupid typo in weight setting.
peter1138
parents: 2542
diff changeset
   522
				if (weight > 4) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   523
					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
   524
				} else {
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   525
					SB(rvi[i].weight, 8, 8, weight);
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   526
				}
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   527
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   528
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   529
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   530
		case 0x25: // User-defined bit mask to set when checking veh. var. 42
3862
898c8212afa1 (svn r4896) - NewGRF: add support for vehicle property 0x25 (user defined data) used by variable 0x42.
peter1138
parents: 3845
diff changeset
   531
			FOR_EACH_OBJECT rvi[i].user_def_data = grf_load_byte(&buf);
898c8212afa1 (svn r4896) - NewGRF: add support for vehicle property 0x25 (user defined data) used by variable 0x42.
peter1138
parents: 3845
diff changeset
   532
			break;
898c8212afa1 (svn r4896) - NewGRF: add support for vehicle property 0x25 (user defined data) used by variable 0x42.
peter1138
parents: 3845
diff changeset
   533
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   534
		case 0x26: // Retire vehicle early
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   535
			FOR_EACH_OBJECT ei[i].retire_early = grf_load_byte(&buf);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   536
			break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   537
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   538
		case 0x27: // Miscellaneous flags
4742
d5a2d3da5002 (svn r6654) - Codechange: If no 2cc vehicles are available, hide the secondary colour choice.
peter1138
parents: 4711
diff changeset
   539
			FOR_EACH_OBJECT {
d5a2d3da5002 (svn r6654) - Codechange: If no 2cc vehicles are available, hide the secondary colour choice.
peter1138
parents: 4711
diff changeset
   540
				ei[i].misc_flags = grf_load_byte(&buf);
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   541
				if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) SETBIT(_loaded_newgrf_features, GRFLOADED_2CC);
4742
d5a2d3da5002 (svn r6654) - Codechange: If no 2cc vehicles are available, hide the secondary colour choice.
peter1138
parents: 4711
diff changeset
   542
			}
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   543
			break;
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   544
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   545
		case 0x28: // Cargo classes allowed
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   546
			FOR_EACH_OBJECT cargo_allowed[engine + i] = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   547
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   548
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   549
		case 0x29: // Cargo classes disallowed
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   550
			FOR_EACH_OBJECT cargo_disallowed[engine + i] = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   551
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   552
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   553
		case 0x2A: // Long format introduction date (days since year 0)
5114
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   554
			FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf);
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   555
			break;
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   556
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   557
		/* @todo air drag and retire vehicle early
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   558
		 * Fall-through for unimplemented one byte long properties. */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   559
		case 0x20: // Air drag
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   560
			FOR_EACH_OBJECT grf_load_byte(&buf);
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   561
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   562
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   563
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
		default:
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   565
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   566
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   572
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
   573
{
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   574
	EngineInfo *ei = &_engine_info[ROAD_ENGINES_INDEX + engine];
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   575
	RoadVehicleInfo *rvi = &_road_vehicle_info[engine];
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   576
	byte *buf = *bufp;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   577
	int i;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   578
	bool ret = false;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   579
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   580
	switch (prop) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   581
		case 0x08: // Speed (1 unit is 0.5 kmh)
3488
d1d5c0f3f69d (svn r4339) - Comment Change: NewGRF, update comments for units of speed
peter1138
parents: 3355
diff changeset
   582
			FOR_EACH_OBJECT rvi[i].max_speed = grf_load_byte(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   583
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   584
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   585
		case 0x09: // Running cost factor
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   586
			FOR_EACH_OBJECT rvi[i].running_cost = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   587
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   588
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   589
		case 0x0A: // Running cost base
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   590
			/* @todo : I have no idea. --pasky
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   591
			 * I THINK it is used for overriding the base cost of all road vehicle (_price.roadveh_base) --belugas */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   592
			FOR_EACH_OBJECT grf_load_dword(&buf);
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   593
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   594
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   595
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   596
		case 0x0E: // Sprite ID
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   597
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   598
				uint8 spriteid = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   599
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   600
				/* 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
   601
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   602
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   603
				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
   604
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   605
				rvi[i].image_index = spriteid;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   606
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   607
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   608
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   609
		case 0x0F: // Cargo capacity
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   610
			FOR_EACH_OBJECT rvi[i].capacity = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   611
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   612
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   613
		case 0x10: // Cargo type
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   614
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   615
				uint8 cargo = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   616
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   617
				if (cargo < NUM_CARGO && HASBIT(_cargo_mask, 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
   618
					rvi[i].cargo_type = cargo;
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   619
				} else {
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
   620
					rvi[i].cargo_type = CT_INVALID;
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
   621
					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
   622
				}
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   623
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   624
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   625
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   626
		case 0x11: // Cost factor
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   627
			FOR_EACH_OBJECT rvi[i].base_cost = grf_load_byte(&buf); // ?? is it base_cost?
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   628
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   629
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   630
		case 0x12: // SFX
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   631
			FOR_EACH_OBJECT rvi[i].sfx = (SoundFx)grf_load_byte(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   632
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   633
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   634
		case 0x13: // Power in 10hp
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   635
		case 0x14: // Weight in 1/4 tons
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   636
		case 0x15: // Speed in mph*0.8
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   637
			/* TODO: Support for road vehicles realistic power
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   638
			 * computations (called rvpower in TTDPatch) is just
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   639
			 * missing in OTTD yet. --pasky */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   640
			FOR_EACH_OBJECT grf_load_byte(&buf);
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   641
			ret = true;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   642
			break;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   643
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   644
		case 0x16: // Cargos available for refitting
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   645
			FOR_EACH_OBJECT ei[i].refit_mask = grf_load_dword(&buf);
3006
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   646
			break;
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   647
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   648
		case 0x17: // Callback mask
3956
0f43adbc293a (svn r5105) - NewGRF: Move callbackmask from *VehicleInfo to EngineInfo. This simplifies code that works with more than one vehicle type.
peter1138
parents: 3924
diff changeset
   649
			FOR_EACH_OBJECT ei[i].callbackmask = grf_load_byte(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   650
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   651
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   652
		case 0x1A: // Refit cost
3997
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   653
			FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf);
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   654
			break;
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   655
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   656
		case 0x1B: // Retire vehicle early
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   657
			FOR_EACH_OBJECT ei[i].retire_early = grf_load_byte(&buf);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   658
			break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   659
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   660
		case 0x1C: // Miscellaneous flags
4952
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   661
			FOR_EACH_OBJECT {
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   662
				ei[i].misc_flags = grf_load_byte(&buf);
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   663
				if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) SETBIT(_loaded_newgrf_features, GRFLOADED_2CC);
4952
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   664
			}
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   665
			break;
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   666
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   667
		case 0x1D: // Cargo classes allowed
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   668
			FOR_EACH_OBJECT cargo_allowed[ROAD_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   669
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   670
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   671
		case 0x1E: // Cargo classes disallowed
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   672
			FOR_EACH_OBJECT cargo_disallowed[ROAD_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   673
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   674
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   675
		case 0x1F: // Long format introduction date (days since year 0)
5114
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   676
			FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf);
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   677
			break;
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   678
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   679
		case 0x18: // Tractive effort
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   680
		case 0x19: // Air drag
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   681
			/* @todo */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   682
			FOR_EACH_OBJECT grf_load_byte(&buf);
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   683
			ret = true;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   684
			break;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   685
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   686
		default:
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   687
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   688
			break;
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   689
	}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   690
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   691
	*bufp = buf;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   692
	return ret;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   693
}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   694
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   695
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
   696
{
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   697
	EngineInfo *ei = &_engine_info[SHIP_ENGINES_INDEX + engine];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
	ShipVehicleInfo *svi = &_ship_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
	byte *buf = *bufp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
	int i;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   701
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
	//printf("e %x prop %x?\n", engine, prop);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
	switch (prop) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   705
		case 0x08: // Sprite ID
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   706
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   709
				/* 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
   710
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   711
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   712
				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
   713
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
				svi[i].image_index = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   716
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   717
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   718
		case 0x09: // Refittable
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   719
			FOR_EACH_OBJECT svi[i].refittable = (grf_load_byte(&buf) != 0);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   720
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   721
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   722
		case 0x0A: // Cost factor
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   723
			FOR_EACH_OBJECT svi[i].base_cost = grf_load_byte(&buf); // ?? is it base_cost?
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   724
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   725
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   726
		case 0x0B: // Speed (1 unit is 0.5 kmh)
3488
d1d5c0f3f69d (svn r4339) - Comment Change: NewGRF, update comments for units of speed
peter1138
parents: 3355
diff changeset
   727
			FOR_EACH_OBJECT svi[i].max_speed = grf_load_byte(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   728
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   729
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   730
		case 0x0C: // Cargo type
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   731
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
				uint8 cargo = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   734
				if (cargo < NUM_CARGO && HASBIT(_cargo_mask, 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
   735
					svi[i].cargo_type = cargo;
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   736
				} else {
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
   737
					svi[i].cargo_type = CT_INVALID;
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
   738
					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
   739
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   740
			}
3006
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   741
			break;
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   742
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   743
		case 0x0D: // Cargo capacity
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   744
			FOR_EACH_OBJECT svi[i].capacity = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   745
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   746
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   747
		case 0x0F: // Running cost factor
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   748
			FOR_EACH_OBJECT svi[i].running_cost = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   749
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   750
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   751
		case 0x10: // SFX
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   752
			FOR_EACH_OBJECT svi[i].sfx = (SoundFx)grf_load_byte(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   753
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   754
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   755
		case 0x11: // Cargos available for refitting
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   756
			FOR_EACH_OBJECT ei[i].refit_mask = grf_load_dword(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   757
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   758
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   759
		case 0x12: // Callback mask
3956
0f43adbc293a (svn r5105) - NewGRF: Move callbackmask from *VehicleInfo to EngineInfo. This simplifies code that works with more than one vehicle type.
peter1138
parents: 3924
diff changeset
   760
			FOR_EACH_OBJECT ei[i].callbackmask = grf_load_byte(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   761
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   762
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   763
		case 0x13: // Refit cost
3997
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   764
			FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf);
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   765
			break;
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   766
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   767
		case 0x16: // Retire vehicle early
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   768
			FOR_EACH_OBJECT ei[i].retire_early = grf_load_byte(&buf);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   769
			break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   770
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   771
		case 0x17: // Miscellaneous flags
4952
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   772
			FOR_EACH_OBJECT {
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   773
				ei[i].misc_flags = grf_load_byte(&buf);
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   774
				if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) SETBIT(_loaded_newgrf_features, GRFLOADED_2CC);
4952
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   775
			}
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   776
			break;
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   777
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   778
		case 0x18: // Cargo classes allowed
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   779
			FOR_EACH_OBJECT cargo_allowed[SHIP_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   780
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   781
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   782
		case 0x19: // Cargo classes disallowed
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   783
			FOR_EACH_OBJECT cargo_disallowed[SHIP_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   784
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   785
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   786
		case 0x1A: // Long format introduction date (days since year 0)
5114
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   787
			FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf);
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   788
			break;
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   789
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   790
		case 0x14: // Ocean speed fraction
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   791
		case 0x15: // Canal speed fraction
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   792
			/* @todo */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   793
			FOR_EACH_OBJECT grf_load_byte(&buf);
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   794
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   795
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   796
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
		default:
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   798
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   799
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
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
   806
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
   807
{
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   808
	EngineInfo *ei = &_engine_info[AIRCRAFT_ENGINES_INDEX + engine];
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   809
	AircraftVehicleInfo *avi = &_aircraft_vehicle_info[engine];
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   810
	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
   811
	int i;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   812
	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
   813
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
   814
	//printf("e %x prop %x?\n", engine, prop);
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   815
	switch (prop) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   816
		case 0x08: // Sprite ID
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   817
			FOR_EACH_OBJECT {
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   818
				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
   819
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   820
				/* 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
   821
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   822
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   823
				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
   824
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   825
				avi[i].image_index = spriteid;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   826
			}
3006
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   827
			break;
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   828
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   829
		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
   830
			FOR_EACH_OBJECT {
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   831
				if (grf_load_byte(&buf) == 0) {
6106
0c9b10a8fedf (svn r8429) -Codechange: Add a name for AircraftVehicleInfo subtype helicopter and remove some magic numbers related to the subtype.
Darkvater
parents: 6014
diff changeset
   832
					avi[i].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
   833
				} else {
6106
0c9b10a8fedf (svn r8429) -Codechange: Add a name for AircraftVehicleInfo subtype helicopter and remove some magic numbers related to the subtype.
Darkvater
parents: 6014
diff changeset
   834
					SB(avi[i].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
   835
				}
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   836
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   837
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   838
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   839
		case 0x0A: // Large
6106
0c9b10a8fedf (svn r8429) -Codechange: Add a name for AircraftVehicleInfo subtype helicopter and remove some magic numbers related to the subtype.
Darkvater
parents: 6014
diff changeset
   840
			FOR_EACH_OBJECT SB(avi[i].subtype, 1, 1, (grf_load_byte(&buf) != 0 ? 1 : 0)); // AIR_FAST
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   841
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   842
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   843
		case 0x0B: // Cost factor
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   844
			FOR_EACH_OBJECT avi[i].base_cost = grf_load_byte(&buf); // ?? is it base_cost?
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   845
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   846
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   847
		case 0x0C: // Speed (1 unit is 8 mph, we translate to 1 unit is 1 km/h)
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6512
diff changeset
   848
			FOR_EACH_OBJECT avi[i].max_speed = (grf_load_byte(&buf) * 129) / 10;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   849
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   850
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   851
		case 0x0D: // Acceleration
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6512
diff changeset
   852
			FOR_EACH_OBJECT avi[i].acceleration = (grf_load_byte(&buf) * 129) / 10;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   853
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   854
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   855
		case 0x0E: // Running cost factor
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   856
			FOR_EACH_OBJECT avi[i].running_cost = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   857
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   858
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   859
		case 0x0F: // Passenger capacity
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   860
			FOR_EACH_OBJECT avi[i].passenger_capacity = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   861
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   862
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   863
		case 0x11: // Mail capacity
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   864
			FOR_EACH_OBJECT avi[i].mail_capacity = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   865
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   866
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   867
		case 0x12: // SFX
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   868
			FOR_EACH_OBJECT avi[i].sfx = (SoundFx)grf_load_byte(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   869
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   870
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   871
		case 0x13: // Cargos available for refitting
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   872
			FOR_EACH_OBJECT ei[i].refit_mask = grf_load_dword(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   873
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   874
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   875
		case 0x14: // Callback mask
3956
0f43adbc293a (svn r5105) - NewGRF: Move callbackmask from *VehicleInfo to EngineInfo. This simplifies code that works with more than one vehicle type.
peter1138
parents: 3924
diff changeset
   876
			FOR_EACH_OBJECT ei[i].callbackmask = grf_load_byte(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   877
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   878
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   879
		case 0x15: // Refit cost
3997
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   880
			FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf);
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   881
			break;
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   882
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   883
		case 0x16: // Retire vehicle early
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   884
			FOR_EACH_OBJECT ei[i].retire_early = grf_load_byte(&buf);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   885
			break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   886
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   887
		case 0x17: // Miscellaneous flags
4952
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   888
			FOR_EACH_OBJECT {
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   889
				ei[i].misc_flags = grf_load_byte(&buf);
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   890
				if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) SETBIT(_loaded_newgrf_features, GRFLOADED_2CC);
4952
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   891
			}
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   892
			break;
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   893
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   894
		case 0x18: // Cargo classes allowed
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   895
			FOR_EACH_OBJECT cargo_allowed[AIRCRAFT_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   896
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   897
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   898
		case 0x19: // Cargo classes disallowed
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   899
			FOR_EACH_OBJECT cargo_disallowed[AIRCRAFT_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   900
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   901
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   902
		case 0x1A: // Long format introduction date (days since year 0)
5114
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   903
			FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf);
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   904
			break;
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   905
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
   906
		default:
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   907
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   908
			break;
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   909
	}
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
   910
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
   911
	*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
   912
	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
   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
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   915
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
   916
{
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   917
	StationSpec **statspec;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   918
	byte *buf = *bufp;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   919
	int i;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   920
	bool ret = false;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   921
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
   922
	if (stid + numinfo > MAX_STATIONS) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   923
		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
   924
		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
   925
	}
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
   926
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
   927
	/* 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
   928
	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
   929
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
   930
	statspec = &_cur_grffile->stations[stid];
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   931
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   932
	if (prop != 0x08) {
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   933
		/* Check that all stations we are modifying are defined. */
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   934
		FOR_EACH_OBJECT {
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   935
			if (statspec[i] == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   936
				grfmsg(2, "StationChangeInfo: Attempt to modify undefined station %u, ignoring", stid + i);
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   937
				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
   938
			}
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
   939
		}
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
   940
	}
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
   941
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   942
	switch (prop) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   943
		case 0x08: // Class ID
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   944
			FOR_EACH_OBJECT {
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   945
				/* Property 0x08 is special; it is where the station is allocated */
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
   946
				if (statspec[i] == NULL) statspec[i] = 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
   947
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
   948
				/* Swap classid because we read it in BE meaning WAYP or DFLT */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   949
				uint32 classid = grf_load_dword(&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
   950
				statspec[i]->sclass = AllocateStationClass(BSWAP32(classid));
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   951
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   952
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   953
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   954
		case 0x09: // Define sprite layout
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   955
			FOR_EACH_OBJECT {
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   956
				StationSpec *statspec = _cur_grffile->stations[stid + i];
398
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
   957
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   958
				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
   959
				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
   960
				statspec->copied_renderdata = false;
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
   961
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   962
				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
   963
					DrawTileSprites *dts = &statspec->renderdata[t];
3570
f9749bae861e (svn r4452) - NewGRF: switch to unsigned ints for array indices.
peter1138
parents: 3566
diff changeset
   964
					uint seq_count = 0;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   965
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
   966
					dts->seq = NULL;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   967
					dts->ground_sprite = grf_load_word(&buf);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   968
					dts->ground_pal = grf_load_word(&buf);
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   969
					if (dts->ground_sprite == 0) continue;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   970
					if (HASBIT(dts->ground_pal, 15)) {
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   971
						CLRBIT(dts->ground_pal, 15);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   972
						SETBIT(dts->ground_sprite, SPRITE_MODIFIER_USE_OFFSET);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   973
					}
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   974
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   975
					while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   976
						DrawTileSeqStruct *dtss;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   977
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   978
						/* 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
   979
						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
   980
						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
   981
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   982
						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
   983
						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
   984
						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
   985
						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
   986
						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
   987
						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
   988
						dtss->size_z = grf_load_byte(&buf);
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   989
						dtss->image = grf_load_word(&buf);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   990
						dtss->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
   991
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   992
						/* Remap flags as ours collide */
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   993
						if (HASBIT(dtss->pal, 15)) {
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   994
							CLRBIT(dtss->pal, 15);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   995
							SETBIT(dtss->image, SPRITE_MODIFIER_USE_OFFSET);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   996
						}
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   997
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   998
						if (HASBIT(dtss->image, 15)) {
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   999
							CLRBIT(dtss->image, 15);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1000
							SETBIT(dtss->image, PALETTE_MODIFIER_COLOR);
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  1001
						}
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
  1002
						if (HASBIT(dtss->image, 14)) {
b34d07131ad1 (svn r4763) - Newstations: revert r4762, instead map bit the palette modifier from bit 14 to bit 31 on GRF load.
peter1138
parents: 3768
diff changeset
  1003
							CLRBIT(dtss->image, 14);
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1004
							SETBIT(dtss->image, PALETTE_MODIFIER_TRANSPARENT);
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
  1005
						}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1006
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1007
				}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1008
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1009
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1010
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1011
		case 0x0A: // Copy sprite layout
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1012
			FOR_EACH_OBJECT {
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1013
				StationSpec *statspec = _cur_grffile->stations[stid + i];
398
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
  1014
				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
  1015
				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
  1016
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1017
				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
  1018
				statspec->renderdata = srcstatspec->renderdata;
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  1019
				statspec->copied_renderdata = true;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1020
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1021
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1022
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1023
		case 0x0B: // Callback mask
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1024
			FOR_EACH_OBJECT statspec[i]->callbackmask = grf_load_byte(&buf);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1025
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1026
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1027
		case 0x0C: // Disallowed number of platforms
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1028
			FOR_EACH_OBJECT statspec[i]->disallowed_platforms = grf_load_byte(&buf);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1029
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1030
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1031
		case 0x0D: // Disallowed platform lengths
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1032
			FOR_EACH_OBJECT statspec[i]->disallowed_lengths = grf_load_byte(&buf);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1033
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1034
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1035
		case 0x0E: // Define custom layout
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1036
			FOR_EACH_OBJECT {
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1037
				StationSpec *statspec = _cur_grffile->stations[stid + i];
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1038
5060
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1039
				statspec->copied_layouts = false;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1040
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1041
				while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1042
					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
  1043
					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
  1044
					StationLayout layout;
3570
f9749bae861e (svn r4452) - NewGRF: switch to unsigned ints for array indices.
peter1138
parents: 3566
diff changeset
  1045
					uint l, p;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1046
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1047
					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
  1048
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1049
					//debug("l %d > %d ?", length, stat->lengths);
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1050
					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
  1051
						statspec->platforms = ReallocT(statspec->platforms, length);
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1052
						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
  1053
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
  1054
						statspec->layouts = ReallocT(statspec->layouts, length);
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1055
						memset(statspec->layouts + statspec->lengths, 0,
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1056
						       (length - statspec->lengths) * sizeof(*statspec->layouts));
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1057
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1058
						statspec->lengths = length;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1059
					}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1060
					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
  1061
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1062
					//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
  1063
					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
  1064
						statspec->layouts[l] = ReallocT(statspec->layouts[l], number);
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1065
						/* 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
  1066
						memset(statspec->layouts[l] + statspec->platforms[l], 0,
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1067
						       (number - statspec->platforms[l]) * sizeof(**statspec->layouts));
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1068
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1069
						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
  1070
					}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1071
542
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
  1072
					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
  1073
					layout = MallocT<byte>(length * number);
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1074
					for (l = 0; l < length; l++) {
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1075
						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
  1076
							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
  1077
						}
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1078
					}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1079
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1080
					l--;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1081
					p--;
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1082
					free(statspec->layouts[l][p]);
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1083
					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
  1084
				}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1085
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1086
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1087
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1088
		case 0x0F: // Copy custom layout
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1089
			FOR_EACH_OBJECT {
5060
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1090
				StationSpec *statspec = _cur_grffile->stations[stid + i];
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1091
				byte srcid = grf_load_byte(&buf);
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1092
				const StationSpec *srcstatspec = _cur_grffile->stations[srcid];
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1093
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1094
				statspec->lengths   = srcstatspec->lengths;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1095
				statspec->platforms = srcstatspec->platforms;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1096
				statspec->layouts   = srcstatspec->layouts;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1097
				statspec->copied_layouts = true;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1098
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1099
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1100
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1101
		case 0x10: // Little/lots cargo threshold
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1102
			FOR_EACH_OBJECT statspec[i]->cargo_threshold = grf_load_word(&buf);
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1103
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1104
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1105
		case 0x11: // Pylon placement
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1106
			FOR_EACH_OBJECT statspec[i]->pylons = grf_load_byte(&buf);
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1107
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1108
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1109
		case 0x12: // Cargo types for random triggers
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1110
			FOR_EACH_OBJECT statspec[i]->cargo_triggers = grf_load_dword(&buf);
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1111
			break;
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1112
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1113
		case 0x13: // General flags
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1114
			FOR_EACH_OBJECT statspec[i]->flags = grf_load_byte(&buf);
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1115
			break;
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1116
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1117
		case 0x14: // Overhead wire placement
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1118
			FOR_EACH_OBJECT statspec[i]->wires = grf_load_byte(&buf);
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1119
			break;
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1120
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1121
		case 0x15: // Blocked tiles
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1122
			FOR_EACH_OBJECT statspec[i]->blocked = grf_load_byte(&buf);
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1123
			break;
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1124
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1125
		case 0x16: // @todo Animation info
6154
dac2e6d13112 (svn r8526) -Codechange: add stubs for unsupported newgrf station properties
peter1138
parents: 6140
diff changeset
  1126
			FOR_EACH_OBJECT grf_load_word(&buf);
dac2e6d13112 (svn r8526) -Codechange: add stubs for unsupported newgrf station properties
peter1138
parents: 6140
diff changeset
  1127
			ret = true;
dac2e6d13112 (svn r8526) -Codechange: add stubs for unsupported newgrf station properties
peter1138
parents: 6140
diff changeset
  1128
			break;
dac2e6d13112 (svn r8526) -Codechange: add stubs for unsupported newgrf station properties
peter1138
parents: 6140
diff changeset
  1129
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1130
		case 0x17: // @todo Animation speed
6154
dac2e6d13112 (svn r8526) -Codechange: add stubs for unsupported newgrf station properties
peter1138
parents: 6140
diff changeset
  1131
			FOR_EACH_OBJECT grf_load_byte(&buf);
dac2e6d13112 (svn r8526) -Codechange: add stubs for unsupported newgrf station properties
peter1138
parents: 6140
diff changeset
  1132
			ret = true;
dac2e6d13112 (svn r8526) -Codechange: add stubs for unsupported newgrf station properties
peter1138
parents: 6140
diff changeset
  1133
			break;
dac2e6d13112 (svn r8526) -Codechange: add stubs for unsupported newgrf station properties
peter1138
parents: 6140
diff changeset
  1134
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1135
		case 0x18: // @todo Animation triggers
6154
dac2e6d13112 (svn r8526) -Codechange: add stubs for unsupported newgrf station properties
peter1138
parents: 6140
diff changeset
  1136
			FOR_EACH_OBJECT grf_load_word(&buf);
dac2e6d13112 (svn r8526) -Codechange: add stubs for unsupported newgrf station properties
peter1138
parents: 6140
diff changeset
  1137
			ret = true;
dac2e6d13112 (svn r8526) -Codechange: add stubs for unsupported newgrf station properties
peter1138
parents: 6140
diff changeset
  1138
			break;
dac2e6d13112 (svn r8526) -Codechange: add stubs for unsupported newgrf station properties
peter1138
parents: 6140
diff changeset
  1139
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1140
		default:
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1141
			ret = true;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1142
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1143
	}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1144
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1145
	*bufp = buf;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1146
	return ret;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1147
}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1148
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
  1149
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
  1150
{
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
  1151
	byte *buf = *bufp;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1152
	int i;
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1153
	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
  1154
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1155
	switch (prop) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1156
		case 0x08: // Year of availability
4322
0bee6d9bc452 (svn r5975) -Cleanup: use ORIGINAL_BASE_YEAR & ORIGINAL_MAX_YEAR where the functions really depend on the original date format.
rubidium
parents: 4321
diff changeset
  1157
			FOR_EACH_OBJECT _bridge[brid + i].avail_year = ORIGINAL_BASE_YEAR + grf_load_byte(&buf);
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1158
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1159
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1160
		case 0x09: // Minimum length
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1161
			FOR_EACH_OBJECT _bridge[brid + i].min_length = grf_load_byte(&buf);
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1162
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1163
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1164
		case 0x0A: // Maximum length
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1165
			FOR_EACH_OBJECT _bridge[brid + i].max_length = grf_load_byte(&buf);
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1166
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1167
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1168
		case 0x0B: // Cost factor
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1169
			FOR_EACH_OBJECT _bridge[brid + i].price = grf_load_byte(&buf);
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1170
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1171
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1172
		case 0x0C: // Maximum speed
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1173
			FOR_EACH_OBJECT _bridge[brid + i].speed = grf_load_word(&buf);
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1174
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1175
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1176
		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
  1177
			FOR_EACH_OBJECT {
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1178
				Bridge *bridge = &_bridge[brid + i];
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1179
				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
  1180
				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
  1181
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
  1182
				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
  1183
					/* 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
  1184
					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
  1185
				}
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
  1186
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
  1187
				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
  1188
					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
  1189
						grfmsg(1, "BridgeChangeInfo: Table %d >= 7, skipping", tableid);
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1190
						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
  1191
						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
  1192
					}
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
  1193
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
  1194
					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
  1195
						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
  1196
					}
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
  1197
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1198
					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
  1199
						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
  1200
						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
  1201
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1202
						if (HASBIT(pal, 15)) {
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1203
							SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1204
						}
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1205
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1206
						/* Clear old color modifer bit */
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1207
						CLRBIT(image, 15);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1208
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1209
						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
  1210
						bridge->sprite_table[tableid][sprite].pal    = pal;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1211
					}
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
  1212
				}
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
  1213
			}
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
  1214
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1215
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1216
		case 0x0E: // Flags; bit 0 - disable far pillars
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1217
			FOR_EACH_OBJECT _bridge[brid + i].flags = grf_load_byte(&buf);
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1218
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1219
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1220
		case 0x0F: // Long format year of availability (year since year 0)
5114
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
  1221
			FOR_EACH_OBJECT _bridge[brid + i].avail_year = clamp(grf_load_dword(&buf), MIN_YEAR, MAX_YEAR);
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
  1222
			break;
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
  1223
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
  1224
		default:
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1225
			ret = true;
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1226
	}
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
  1227
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
  1228
	*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
  1229
	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
  1230
}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1231
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1232
static bool TownHouseChangeInfo(uint hid, int numinfo, int prop, byte **bufp, int len)
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1233
{
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1234
	HouseSpec **housespec;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1235
	byte *buf = *bufp;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1236
	int i;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1237
	bool ret = false;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1238
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1239
	if (hid + numinfo >= HOUSE_MAX) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1240
		grfmsg(1, "TownHouseChangeInfo: Too many houses loaded (%u), max (%u). Ignoring.", hid + numinfo, HOUSE_MAX-1);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1241
		return false;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1242
	}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1243
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1244
	/* Allocate house specs if they haven't been allocated already. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1245
	if (_cur_grffile->housespec == NULL) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1246
		_cur_grffile->housespec = CallocT<HouseSpec*>(HOUSE_MAX);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1247
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1248
		/* Reset any overrides that have been set. */
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1249
		_house_mngr.ResetOverride();
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1250
	}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1251
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1252
	housespec = &_cur_grffile->housespec[hid];
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1253
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1254
	if (prop != 0x08) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1255
		/* Check that all the houses being modified have been defined. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1256
		FOR_EACH_OBJECT {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1257
			if (housespec[i] == NULL) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1258
				grfmsg(2, "TownHouseChangeInfo: Attempt to modify undefined house %u. Ignoring.", hid + i);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1259
				return false;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1260
			}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1261
		}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1262
	}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1263
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1264
	switch (prop) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1265
		case 0x08: // Substitute building type, and definition of a new house
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1266
			FOR_EACH_OBJECT {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1267
				byte subs_id = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1268
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1269
				if (subs_id == 0xFF) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1270
					/* Instead of defining a new house, a substitute house id
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1271
					 * of 0xFF disables the old house with the current id. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1272
					_house_specs[hid + i].enabled = false;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1273
					continue;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1274
				} else if (subs_id >= NEW_HOUSE_OFFSET) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1275
					/* The substitute id must be one of the original houses. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1276
					grfmsg(2, "TownHouseChangeInfo: Attempt to use new house %u as substitute house for %u. Ignoring.", subs_id, hid + i);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1277
					return false;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1278
				}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1279
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1280
				/* Allocate space for this house. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1281
				if (housespec[i] == NULL) housespec[i] = CallocT<HouseSpec>(1);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1282
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1283
				memcpy(housespec[i], &_house_specs[subs_id], sizeof(_house_specs[subs_id]));
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1284
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1285
				housespec[i]->enabled = true;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1286
				housespec[i]->local_id = hid + i;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1287
				housespec[i]->substitute_id = subs_id;
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1288
				housespec[i]->grffile = _cur_grffile;
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1289
				housespec[i]->random_colour[0] = 0x04;  // those 4 random colours are the base colour
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1290
				housespec[i]->random_colour[1] = 0x08;  // for all new houses
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1291
				housespec[i]->random_colour[2] = 0x0C;  // they stand for red, blue, orange and green
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1292
				housespec[i]->random_colour[3] = 0x06;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1293
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1294
				/* New houses do not (currently) expect to have a default start
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1295
				 * date before 1930, as this breaks the build date stuff. See
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1296
				 * FinaliseHouseArray() for more details. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1297
				if (housespec[i]->min_date < 1930) housespec[i]->min_date = 1930;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1298
			}
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1299
			SETBIT(_loaded_newgrf_features, GRFLOADED_NEWHOUSES);
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1300
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1301
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1302
		case 0x09: // Building flags
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1303
			FOR_EACH_OBJECT {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1304
				byte state = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1305
				housespec[i]->building_flags = (BuildingFlags)state;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1306
			}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1307
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1308
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1309
		case 0x0A: // Availability years
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1310
			FOR_EACH_OBJECT {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1311
				uint16 years = grf_load_word(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1312
				housespec[i]->min_date = GB(years, 0, 8) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB(years, 0, 8);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1313
				housespec[i]->max_date = GB(years, 8, 8) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB(years, 8, 8);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1314
			}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1315
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1316
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1317
		case 0x0B: // Population
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1318
			FOR_EACH_OBJECT housespec[i]->population = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1319
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1320
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1321
		case 0x0C: // Mail generation multiplier
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1322
			FOR_EACH_OBJECT housespec[i]->mail_generation = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1323
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1324
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1325
		case 0x0D: // Passenger acceptance
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1326
		case 0x0E: // Mail acceptance
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1327
			FOR_EACH_OBJECT housespec[i]->cargo_acceptance[prop - 0x0D] = grf_load_byte(&buf);
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1328
			break;
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1329
		case 0x0F: // Goods/candy, food/fizzy drinks acceptance
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1330
			FOR_EACH_OBJECT {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1331
				int8 goods = grf_load_byte(&buf);
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1332
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1333
				/* If value of goods is negative, it means in fact food or, if in toyland, fizzy_drink acceptance.
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1334
				 * Else, we have "standard" 3rd cargo type, goods or candy, for toyland once more */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1335
				housespec[i]->accepts_cargo[2] = (goods >= 0) ? ((_opt.landscape == LT_TOYLAND) ? CT_CANDY : CT_GOODS) :
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1336
						((_opt.landscape == LT_TOYLAND) ? CT_FIZZY_DRINKS : CT_FOOD);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1337
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1338
				housespec[i]->cargo_acceptance[2] = abs(goods); // but we do need positive value here
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1339
			}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1340
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1341
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1342
		case 0x10: // Local authority rating decrease on removal
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1343
			FOR_EACH_OBJECT housespec[i]->remove_rating_decrease = grf_load_word(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1344
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1345
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1346
		case 0x11: // Removal cost multiplier
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1347
			FOR_EACH_OBJECT housespec[i]->removal_cost = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1348
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1349
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1350
		case 0x12: // Building name ID
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1351
			FOR_EACH_OBJECT housespec[i]->building_name = MapGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1352
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1353
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1354
		case 0x13: // Building availability mask
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1355
			FOR_EACH_OBJECT {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1356
				uint16 avail = grf_load_word(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1357
				housespec[i]->building_availability = (HouseZones)avail;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1358
			}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1359
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1360
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1361
		case 0x14: // House callback flags
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1362
			FOR_EACH_OBJECT housespec[i]->callback_mask = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1363
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1364
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1365
		case 0x15: // House override byte
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1366
			FOR_EACH_OBJECT {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1367
				byte override = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1368
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1369
				/* The house being overridden must be an original house. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1370
				if (override >= NEW_HOUSE_OFFSET) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1371
					grfmsg(2, "TownHouseChangeInfo: Attempt to override new house %u with house id %u. Ignoring.", override, hid);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1372
					return false;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1373
				}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1374
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1375
				_house_mngr.Add(hid, override);
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1376
			}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1377
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1378
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1379
		case 0x16: // Periodic refresh multiplier
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1380
			FOR_EACH_OBJECT housespec[i]->processing_time = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1381
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1382
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1383
		case 0x17: // Four random colours to use
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1384
			FOR_EACH_OBJECT {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1385
				uint j;
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  1386
				for (j = 0; j < 4; j++) housespec[i]->random_colour[j] = grf_load_byte(&buf);
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1387
			}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1388
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1389
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1390
		case 0x18: // Relative probability of appearing
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1391
			FOR_EACH_OBJECT housespec[i]->probability = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1392
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1393
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1394
		case 0x19: // Extra flags
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1395
			FOR_EACH_OBJECT {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1396
				byte flags = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1397
				housespec[i]->extra_flags = (HouseExtraFlags)flags;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1398
			}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1399
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1400
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1401
		case 0x1A: // Animation frames
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1402
			FOR_EACH_OBJECT housespec[i]->animation_frames = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1403
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1404
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1405
		case 0x1B: // Animation speed
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1406
			FOR_EACH_OBJECT housespec[i]->animation_speed = clamp(grf_load_byte(&buf), 2, 16);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1407
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1408
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1409
		case 0x1C: // Class of the building type
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1410
			FOR_EACH_OBJECT housespec[i]->class_id = AllocateHouseClassID(grf_load_byte(&buf), _cur_grffile->grfid);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1411
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1412
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1413
		case 0x1D: // Callback flags 2
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1414
			FOR_EACH_OBJECT housespec[i]->callback_mask |= (grf_load_byte(&buf) << 8);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1415
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1416
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1417
		case 0x1E: // Accepted cargo types
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1418
			FOR_EACH_OBJECT {
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1419
				uint32 cargotypes = grf_load_dword(&buf);
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1420
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1421
				/* Check if the cargo types should not be changed */
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1422
				if (cargotypes == 0xFFFFFFFF) break;
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1423
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1424
				for (uint j = 0; j < 3; j++) {
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1425
					/* Get the cargo number from the 'list' */
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1426
					uint8 cargo_part = GB(cargotypes, 8 * j, 8);
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1427
					CargoID cargo = GetCargoTranslation(cargo_part, _cur_grffile);
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1428
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1429
					if (cargo == CT_INVALID) {
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1430
						/* Disable acceptance of invalid cargo type */
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1431
						housespec[i]->cargo_acceptance[j] = 0;
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1432
					} else {
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1433
						housespec[i]->accepts_cargo[j] = cargo;
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1434
					}
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1435
				}
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1436
			}
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1437
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1438
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1439
		case 0x1F: // Minimum life span
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1440
			FOR_EACH_OBJECT housespec[i]->minimum_life = grf_load_byte(&buf);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1441
			break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1442
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1443
		default:
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1444
			ret = true;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1445
			break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1446
	}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1447
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1448
	*bufp = buf;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1449
	return ret;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1450
}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1451
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1452
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
  1453
{
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1454
	byte *buf = *bufp;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1455
	int i;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1456
	bool ret = false;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1457
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1458
	switch (prop) {
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1459
		case 0x08: /* Cost base factor */
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1460
			FOR_EACH_OBJECT {
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1461
				byte factor = grf_load_byte(&buf);
2508
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1462
				uint price = gvid + i;
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1463
9903
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9896
diff changeset
  1464
				if (price < CEconomy::MAX_PRICE) {
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9896
diff changeset
  1465
					//SetPriceBaseMultiplier(price, factor);
2508
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1466
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1467
					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
  1468
				}
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1469
			}
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1470
			break;
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1471
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1472
		case 0x09: /* Cargo translation table */
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1473
			/* This is loaded during the initialisation stage, so just skip it here. */
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1474
			/* Each entry is 4 bytes. */
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1475
			buf += numinfo * 4;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1476
			break;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1477
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1478
		case 0x0A: // Currency display names
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1479
			FOR_EACH_OBJECT {
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1480
				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
  1481
				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
  1482
4504
3d20af4bd525 (svn r6289) -Fix(r6108) : case 0x48 (generic text) should not have been set over newstations.
belugas
parents: 4434
diff changeset
  1483
				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
  1484
					_currency_specs[curidx].name = newone;
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1485
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1486
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1487
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1488
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1489
		case 0x0B: // Currency multipliers
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1490
			FOR_EACH_OBJECT {
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1491
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1492
				uint32 rate = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1493
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1494
				if (curidx < NUM_CURRENCY) {
4602
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1495
					/* 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
  1496
					 * 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
  1497
					 * to be compatible */
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1498
					_currency_specs[curidx].rate = rate / 1000;
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1499
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1500
					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
  1501
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1502
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1503
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1504
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1505
		case 0x0C: // Currency options
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1506
			FOR_EACH_OBJECT {
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1507
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1508
				uint16 options = grf_load_word(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1509
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1510
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1511
					_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
  1512
					/* 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
  1513
					 * 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
  1514
					_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
  1515
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1516
					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
  1517
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1518
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1519
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1520
4602
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1521
		case 0x0D: // Currency prefix symbol
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1522
			FOR_EACH_OBJECT {
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1523
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1524
				uint32 tempfix = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1525
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1526
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1527
					memcpy(_currency_specs[curidx].prefix,&tempfix,4);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1528
					_currency_specs[curidx].prefix[4] = 0;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1529
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1530
					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
  1531
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1532
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1533
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1534
4602
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1535
		case 0x0E: // Currency suffix symbol
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1536
			FOR_EACH_OBJECT {
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1537
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1538
				uint32 tempfix = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1539
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1540
				if (curidx < NUM_CURRENCY) {
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  1541
					memcpy(&_currency_specs[curidx].suffix, &tempfix, 4);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1542
					_currency_specs[curidx].suffix[4] = 0;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1543
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1544
					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
  1545
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1546
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1547
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1548
4504
3d20af4bd525 (svn r6289) -Fix(r6108) : case 0x48 (generic text) should not have been set over newstations.
belugas
parents: 4434
diff changeset
  1549
		case 0x0F: //  Euro introduction dates
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1550
			FOR_EACH_OBJECT {
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1551
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1552
				Year year_euro = grf_load_word(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1553
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1554
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1555
					_currency_specs[curidx].to_euro = year_euro;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1556
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1557
					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
  1558
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1559
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1560
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1561
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1562
		case 0x10: // 12 * 32 * B Snow line height table
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1563
			if (numinfo > 1 || IsSnowLineSet()) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1564
				grfmsg(1, "GlobalVarChangeInfo: The snowline can only be set once (%d)", numinfo);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1565
			} else if (len < SNOW_LINE_MONTHS * SNOW_LINE_DAYS) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1566
				grfmsg(1, "GlobalVarChangeInfo: Not enough entries set in the snowline table (%d)", len);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1567
			} else {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1568
				byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1569
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1570
				for (uint i = 0; i < SNOW_LINE_MONTHS; i++) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1571
					for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1572
						table[i][j] = grf_load_byte(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1573
					}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1574
				}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1575
				SetSnowLine(table);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1576
			}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1577
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1578
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1579
		default:
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1580
			ret = true;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1581
	}
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1582
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1583
	*bufp = buf;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1584
	return ret;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1585
}
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1586
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1587
static bool CargoChangeInfo(uint cid, int numinfo, int prop, byte **bufp, int len)
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1588
{
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1589
	if (cid + numinfo > NUM_CARGO) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1590
		grfmsg(2, "CargoChangeInfo: Cargo type %d out of range (max %d)", cid + numinfo, NUM_CARGO - 1);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1591
		return false;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1592
	}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1593
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1594
	CargoSpec *cs = &_cargo[cid];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1595
	byte *buf = *bufp;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1596
	int i;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1597
	bool ret = false;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1598
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1599
	switch (prop) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1600
		case 0x08: /* Bit number of cargo */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1601
			FOR_EACH_OBJECT {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1602
				cs[i].bitnum = grf_load_byte(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1603
				cs[i].grfid = _cur_grffile->grfid;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1604
				if (cs->IsValid()) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1605
					SETBIT(_cargo_mask, cid + i);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1606
				} else {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1607
					CLRBIT(_cargo_mask, cid + i);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1608
				}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1609
			}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1610
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1611
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1612
		case 0x09: /* String ID for cargo type name */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1613
			FOR_EACH_OBJECT cs[i].name = grf_load_word(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1614
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1615
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1616
		case 0x0A: /* String for cargo name, plural */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1617
			FOR_EACH_OBJECT cs[i].name_plural = grf_load_word(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1618
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1619
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1620
		case 0x0B:
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1621
			/* String for units of cargo. This is different in OpenTTD to TTDPatch
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1622
			 * (e.g. 10 tonnes of coal) */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1623
			FOR_EACH_OBJECT cs[i].units_volume = grf_load_word(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1624
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1625
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1626
		case 0x0C: /* String for quantity of cargo (e.g. 10 tonnes of coal) */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1627
			FOR_EACH_OBJECT cs[i].quantifier = grf_load_word(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1628
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1629
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1630
		case 0x0D: /* String for two letter cargo abbreviation */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1631
			FOR_EACH_OBJECT cs[i].abbrev = grf_load_word(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1632
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1633
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1634
		case 0x0E: /* Sprite ID for cargo icon */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1635
			FOR_EACH_OBJECT cs[i].sprite = grf_load_word(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1636
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1637
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1638
		case 0x0F: /* Weight of one unit of cargo */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1639
			FOR_EACH_OBJECT cs[i].weight = grf_load_byte(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1640
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1641
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1642
		case 0x10: /* Used for payment calculation */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1643
			FOR_EACH_OBJECT cs[i].transit_days[0] = grf_load_byte(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1644
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1645
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1646
		case 0x11: /* Used for payment calculation */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1647
			FOR_EACH_OBJECT cs[i].transit_days[1] = grf_load_byte(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1648
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1649
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1650
		case 0x12: /* Base cargo price */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1651
			FOR_EACH_OBJECT cs[i].initial_payment = grf_load_dword(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1652
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1653
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1654
		case 0x13: /* Colour for station rating bars */
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
  1655
			FOR_EACH_OBJECT cs[i].rating_colour = MapDOSColour(grf_load_byte(&buf));
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1656
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1657
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1658
		case 0x14: /* Colour for cargo graph */
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
  1659
			FOR_EACH_OBJECT cs[i].legend_colour = MapDOSColour(grf_load_byte(&buf));
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1660
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1661
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1662
		case 0x15: /* Freight status */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1663
			FOR_EACH_OBJECT cs[i].is_freight = grf_load_byte(&buf) != 0;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1664
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1665
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1666
		case 0x16: /* Cargo classes */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1667
			FOR_EACH_OBJECT cs[i].classes = grf_load_word(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1668
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1669
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1670
		case 0x17: /* Cargo label */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1671
			FOR_EACH_OBJECT {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1672
				cs[i].label = grf_load_dword(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1673
				cs[i].label = BSWAP32(cs[i].label);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1674
			}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1675
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1676
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1677
		case 0x18: /* Town growth substitute type */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1678
			FOR_EACH_OBJECT {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1679
				uint8 substitute_type = grf_load_byte(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1680
				switch (substitute_type) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1681
					case 0x00: cs[i].town_effect = TE_PASSENGERS; break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1682
					case 0x02: cs[i].town_effect = TE_MAIL; break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1683
					case 0x05: cs[i].town_effect = TE_GOODS; break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1684
					case 0x09: cs[i].town_effect = TE_WATER; break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1685
					case 0x0B: cs[i].town_effect = TE_FOOD; break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1686
					default:
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1687
						grfmsg(1, "CargoChangeInfo: Unknown town growth substitute value %d, setting to none.", substitute_type);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1688
					case 0xFF: cs[i].town_effect = TE_NONE; break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1689
				}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1690
			}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1691
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1692
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1693
		case 0x19: /* Town growth coefficient */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1694
			FOR_EACH_OBJECT cs[i].multipliertowngrowth = grf_load_word(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1695
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1696
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1697
		case 0x1A: /* Bitmask of callbacks to use */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1698
			FOR_EACH_OBJECT cs[i].callback_mask = grf_load_byte(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1699
			break;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1700
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1701
		default:
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1702
			ret = true;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1703
	}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1704
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1705
	*bufp = buf;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1706
	return ret;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1707
}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1708
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1709
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1710
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
  1711
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1712
	byte *buf = *bufp;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1713
	int i;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1714
	bool ret = false;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1715
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1716
	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
  1717
		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
  1718
		return false;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1719
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1720
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1721
	switch (prop) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1722
		case 0x08: // Relative volume
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1723
			FOR_EACH_OBJECT {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1724
				uint sound = sid + i + _cur_grffile->sound_offset - GetNumOriginalSounds();
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1725
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1726
				if (sound >= GetNumSounds()) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1727
					grfmsg(1, "SoundEffectChangeInfo: Sound %d not defined (max %d)", sound, GetNumSounds());
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1728
				} else {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1729
					GetSound(sound)->volume = grf_load_byte(&buf);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1730
				}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1731
			}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1732
			break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1733
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1734
		case 0x09: // Priority
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1735
			FOR_EACH_OBJECT {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1736
				uint sound = sid + i + _cur_grffile->sound_offset - GetNumOriginalSounds();
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1737
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1738
				if (sound >= GetNumSounds()) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1739
					grfmsg(1, "SoundEffectChangeInfo: Sound %d not defined (max %d)", sound, GetNumSounds());
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1740
				} else {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1741
					GetSound(sound)->priority = grf_load_byte(&buf);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1742
				}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1743
			}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1744
			break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1745
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1746
		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
  1747
			FOR_EACH_OBJECT {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1748
				uint sound = sid + i + _cur_grffile->sound_offset - GetNumOriginalSounds();
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1749
				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
  1750
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1751
				if (sound >= GetNumSounds() || orig_sound >= GetNumSounds()) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1752
					grfmsg(1, "SoundEffectChangeInfo: Sound %d or %d not defined (max %d)", sound, orig_sound, GetNumSounds());
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1753
				} else {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1754
					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
  1755
					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
  1756
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1757
					/* 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
  1758
					*oldfe = *newfe;
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1759
				}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1760
			}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1761
			break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1762
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1763
		default:
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1764
			ret = true;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1765
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1766
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1767
	*bufp = buf;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1768
	return ret;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1769
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1770
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1771
/* Action 0x00 */
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1772
static void FeatureChangeInfo(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1773
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1774
	byte *bufend = buf + len;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1775
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1776
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1777
	/* <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
  1778
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1779
	 * 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
  1780
	 *                 4 for defining new train station sets
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1781
	 * 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
  1782
	 * B num-info      how many vehicles/stations to change
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1783
	 * B id            ID of first vehicle/station to change, if num-info is
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1784
	 *                 greater than one, this one and the following
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1785
	 *                 vehicles/stations will be changed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1786
	 * 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
  1787
	 * 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
  1788
	/* TODO: Bridges, town houses. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1789
2438
eaef2b29fa3d (svn r2964) Fix: newgrf: Include missing grf feature canal.
peter1138
parents: 2421
diff changeset
  1790
	static const VCI_Handler handler[] = {
3825
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1791
		/* GSF_TRAIN */        RailVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1792
		/* GSF_ROAD */         RoadVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1793
		/* GSF_SHIP */         ShipVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1794
		/* GSF_AIRCRAFT */     AircraftVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1795
		/* GSF_STATION */      StationChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1796
		/* GSF_CANAL */        NULL,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1797
		/* GSF_BRIDGE */       BridgeChangeInfo,
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1798
		/* GSF_TOWNHOUSE */    TownHouseChangeInfo,
3825
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1799
		/* GSF_GLOBALVAR */    GlobalVarChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1800
		/* GSF_INDUSTRYTILES */NULL,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1801
		/* GSF_INDUSTRIES */   NULL,
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1802
		/* 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
  1803
		/* GSF_SOUNDFX */      SoundEffectChangeInfo,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1804
	};
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1805
542
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
  1806
	EngineInfo *ei = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1807
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
  1808
	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
  1809
	buf++;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1810
	uint8 feature  = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1811
	uint8 numprops = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1812
	uint numinfo  = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1813
	uint engine   = grf_load_byte(&buf);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  1814
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1815
	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
  1816
	               feature, numprops, engine, numinfo);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
  1817
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
  1818
	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
  1819
		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
  1820
		return;
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1821
	}
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1822
2439
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1823
	if (feature <= GSF_AIRCRAFT) {
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1824
		if (engine + numinfo > _vehcounts[feature]) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1825
			grfmsg(0, "FeatureChangeInfo: Last engine ID %d out of bounds (max %d), skipping", engine + numinfo, _vehcounts[feature]);
2439
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1826
			return;
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1827
		}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1828
		ei = &_engine_info[engine + _vehshifts[feature]];
2439
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1829
	}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1830
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1831
	while (numprops-- && buf < bufend) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1832
		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
  1833
		bool ignoring = false;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1834
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1835
		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
  1836
			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
  1837
			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
  1838
			case GSF_SHIP:
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1839
			case GSF_AIRCRAFT:
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1840
				/* Common properties for vehicles */
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1841
				switch (prop) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1842
					case 0x00: // Introduction date
4322
0bee6d9bc452 (svn r5975) -Cleanup: use ORIGINAL_BASE_YEAR & ORIGINAL_MAX_YEAR where the functions really depend on the original date format.
rubidium
parents: 4321
diff changeset
  1843
						FOR_EACH_OBJECT ei[i].base_intro = grf_load_word(&buf) + DAYS_TILL_ORIGINAL_BASE_YEAR;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1844
						break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1845
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1846
					case 0x02: // Decay speed
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1847
						FOR_EACH_OBJECT SB(ei[i].unk2, 0, 7, grf_load_byte(&buf) & 0x7F);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1848
						break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1849
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1850
					case 0x03: // Vehicle life
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1851
						FOR_EACH_OBJECT ei[i].lifelength = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1852
						break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1853
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1854
					case 0x04: // Model life
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1855
						FOR_EACH_OBJECT ei[i].base_life = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1856
						break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1857
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1858
					case 0x06: // Climates available
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1859
						FOR_EACH_OBJECT ei[i].climates = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1860
						break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1861
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1862
					case 0x07: // Loading speed
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1863
						/* Hyronymus explained me what does
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1864
						 * this mean and insists on having a
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1865
						 * credit ;-). --pasky */
5211
651c9272ad22 (svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents: 5210
diff changeset
  1866
						FOR_EACH_OBJECT ei[i].load_amount = grf_load_byte(&buf);
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1867
						break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1868
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1869
					default:
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1870
						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
  1871
							ignoring = true;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1872
						}
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1873
						break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1874
				}
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1875
				break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1876
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1877
			default:
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1878
				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
  1879
					ignoring = true;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1880
				}
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1881
				break;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1882
		}
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1883
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1884
		if (ignoring) grfmsg(2, "FeatureChangeInfo: Ignoring property 0x%02X (not implemented)", prop);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1885
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1886
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1887
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
  1888
/* Action 0x00 (GLS_SAFETYSCAN) */
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
  1889
static void SafeChangeInfo(byte *buf, int len)
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
  1890
{
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
  1891
	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
  1892
	buf++;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1893
	uint8 feature  = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1894
	uint8 numprops = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1895
	grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1896
	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
  1897
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
  1898
	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
  1899
		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
  1900
		/* 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
  1901
		 * 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
  1902
		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
  1903
	}
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
  1904
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
  1905
	SETBIT(_cur_grfconfig->flags, GCF_UNSAFE);
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
  1906
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
  1907
	/* 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
  1908
	_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
  1909
}
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
  1910
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1911
/* Action 0x00 (GLS_INIT) */
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1912
static void InitChangeInfo(byte *buf, int len)
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1913
{
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1914
	byte *bufend = buf + len;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1915
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1916
	if (!check_length(len, 6, "InitChangeInfo")) return;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1917
	buf++;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1918
	uint8 feature  = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1919
	uint8 numprops = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1920
	uint8 numinfo  = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1921
	uint8 index    = grf_load_byte(&buf);
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1922
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1923
	while (numprops-- && buf < bufend) {
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1924
		uint8 prop = grf_load_byte(&buf);
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1925
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1926
		switch (feature) {
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1927
			case GSF_GLOBALVAR:
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1928
				switch (prop) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1929
					case 0x09: // Cargo Translation Table
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1930
						if (index != 0) {
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1931
							grfmsg(1, "InitChangeInfo: Cargo translation table must start at zero");
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1932
							return;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1933
						}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1934
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1935
						free(_cur_grffile->cargo_list);
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1936
						_cur_grffile->cargo_max = numinfo;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1937
						_cur_grffile->cargo_list = MallocT<CargoLabel>(numinfo);
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1938
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1939
						int i;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1940
						FOR_EACH_OBJECT {
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1941
							CargoLabel cl = grf_load_dword(&buf);
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1942
							_cur_grffile->cargo_list[i] = BSWAP32(cl);
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1943
						}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1944
						break;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1945
				}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1946
				break;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1947
		}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1948
	}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1949
}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  1950
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1951
/* Action 0x00 (GLS_RESERVE) */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1952
static void ReserveChangeInfo(byte *buf, int len)
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1953
{
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1954
	byte *bufend = buf + len;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1955
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1956
	if (!check_length(len, 6, "InitChangeInfo")) return;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1957
	buf++;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1958
	uint8 feature  = grf_load_byte(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1959
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1960
	if (feature != GSF_CARGOS) return;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1961
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1962
	uint8 numprops = grf_load_byte(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1963
	uint8 numinfo  = grf_load_byte(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1964
	uint8 index    = grf_load_byte(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1965
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1966
	while (numprops-- && buf < bufend) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1967
		uint8 prop = grf_load_byte(&buf);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1968
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1969
		if (CargoChangeInfo(index, numinfo, prop, &buf, bufend - buf)) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1970
			grfmsg(2, "ReserveChangeInfo: Ignoring property 0x%02X (not implemented)", prop);
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1971
		}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1972
	}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1973
}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1974
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1975
#undef FOR_EACH_OBJECT
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1976
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1977
/**
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1978
 * Creates a spritegroup representing a callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1979
 * @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
  1980
 * @return A spritegroup representing that callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1981
 */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  1982
static const SpriteGroup* NewCallBackResultSpriteGroup(uint16 value)
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1983
{
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  1984
	SpriteGroup *group = AllocateSpriteGroup();
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1985
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1986
	group->type = SGT_CALLBACK;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1987
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1988
	/* Old style callback results have the highest byte 0xFF so signify it is a callback result
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1989
	 * 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
  1990
	if ((value >> 8) == 0xFF) {
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1991
		value &= ~0xFF00;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1992
	} else {
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1993
		value &= ~0x8000;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1994
	}
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1995
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1996
	group->g.callback.result = value;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1997
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1998
	return group;
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1999
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2000
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
  2001
/**
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
  2002
 * Creates a spritegroup representing a sprite number result.
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2003
 * @param sprite The sprite number.
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2004
 * @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
  2005
 * @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
  2006
 */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  2007
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
  2008
{
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  2009
	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
  2010
	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
  2011
	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
  2012
	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
  2013
	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
  2014
}
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
  2015
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2016
/* Action 0x01 */
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  2017
static void NewSpriteSet(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2018
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2019
	/* <01> <feature> <num-sets> <num-ent>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2020
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2021
	 * B feature       feature to define sprites for
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2022
	 *                 0, 1, 2, 3: veh-type, 4: train stations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2023
	 * B num-sets      number of sprite sets
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2024
	 * 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
  2025
	 *                 For vehicles, this is the number of different
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2026
	 *                         vehicle directions in each sprite set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2027
	 *                         Set num-dirs=8, unless your sprites are symmetric.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2028
	 *                         In that case, use num-dirs=4.
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2029
	 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2030
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
  2031
	if (!check_length(len, 4, "NewSpriteSet")) return;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2032
	buf++;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2033
	uint8 feature   = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2034
	uint8 num_sets  = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2035
	uint16 num_ents = grf_load_extended(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2036
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
  2037
	_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
  2038
	_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
  2039
	_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
  2040
	_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
  2041
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2042
	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
  2043
		_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
  2044
	);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2045
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2046
	for (uint16 i = 0; i < num_sets * num_ents; 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
  2047
		LoadNextSprite(_cur_spriteid++, _file_index);
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  2048
		_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
  2049
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2050
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2051
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2052
/* Action 0x01 (SKIP) */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2053
static void SkipAct1(byte *buf, int len)
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2054
{
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2055
	if (!check_length(len, 4, "SkipAct1")) return;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2056
	buf++;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2057
	grf_load_byte(&buf);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2058
	uint8 num_sets  = grf_load_byte(&buf);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2059
	uint16 num_ents = grf_load_extended(&buf);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2060
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2061
	_skip_sprites = num_sets * num_ents;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2062
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2063
	grfmsg(3, "SkipAct1: Skipping %d sprites", _skip_sprites);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2064
}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2065
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
  2066
/* 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
  2067
 * defined spritegroup. */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  2068
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
  2069
{
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
  2070
	if (HASBIT(groupid, 15)) return NewCallBackResultSpriteGroup(groupid);
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  2071
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
  2072
	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2073
		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
  2074
		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
  2075
	}
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
  2076
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
  2077
	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
  2078
}
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
  2079
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
  2080
/* 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
  2081
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
  2082
{
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
  2083
	if (HASBIT(spriteid, 15)) return NewCallBackResultSpriteGroup(spriteid);
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  2084
3667
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  2085
	if (spriteid >= _cur_grffile->spriteset_numsets) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2086
		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
  2087
		return NULL;
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  2088
	}
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  2089
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
  2090
	/* 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
  2091
	 * 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
  2092
	 * 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
  2093
	if (_cur_grffile->spriteset_start + spriteid * num_sprites + num_sprites > _cur_spriteid) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2094
		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
  2095
				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
  2096
				_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
  2097
				_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
  2098
		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
  2099
	}
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
  2100
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  2101
	if (feature != _cur_grffile->spriteset_feature) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2102
		grfmsg(1, "CreateGroupFromGroupID(0x%02X:0x%02X): Sprite set feature 0x%02X does not match action feature 0x%02X, skipping",
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  2103
				_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
  2104
		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
  2105
	}
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  2106
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
  2107
	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
  2108
}
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
  2109
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2110
/* Action 0x02 */
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  2111
static void NewSpriteGroup(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2112
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2113
	/* <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
  2114
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2115
	 * B feature       see action 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2116
	 * B set-id        ID of this particular definition
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2117
	 * B type/num-entries
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2118
	 *                 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
  2119
	 *                 list definition, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2120
	 *                 otherwise it specifies a number of entries, the exact
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2121
	 *                 meaning depends on the feature
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2122
	 * 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
  2123
	SpriteGroup *group = NULL;
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2124
	byte *bufend = buf + len;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  2125
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
  2126
	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
  2127
	buf++;
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2128
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2129
	uint8 feature = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2130
	uint8 setid   = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2131
	uint8 type    = grf_load_byte(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2132
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
  2133
	if (setid >= _cur_grffile->spritegroups_count) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2134
		/* 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
  2135
		_cur_grffile->spritegroups = ReallocT(_cur_grffile->spritegroups, setid + 1);
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2136
		/* 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
  2137
		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
  2138
			_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
  2139
	}
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
  2140
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2141
	switch (type) {
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2142
		/* Deterministic Sprite Group */
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2143
		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
  2144
		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
  2145
		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
  2146
		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
  2147
		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
  2148
		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
  2149
		{
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
  2150
			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
  2151
			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
  2152
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2153
			/* 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
  2154
			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
  2155
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2156
			group = AllocateSpriteGroup();
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2157
			group->type = SGT_DETERMINISTIC;
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2158
			group->g.determ.var_scope = HASBIT(type, 1) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2159
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2160
			switch (GB(type, 2, 2)) {
3672
73caf2e829f8 (svn r4588) - NewGRF: silence a false compiler warning
peter1138
parents: 3668
diff changeset
  2161
				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
  2162
				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
  2163
				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
  2164
				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
  2165
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2166
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
  2167
			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
  2168
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2169
			/* 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
  2170
			 * 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
  2171
			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
  2172
				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
  2173
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2174
				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
  2175
					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
  2176
				}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2177
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2178
				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
  2179
				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
  2180
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2181
				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
  2182
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2183
				/* 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
  2184
				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
  2185
				adjust->variable  = grf_load_byte(&buf);
5868
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2186
				if (adjust->variable == 0x7E) {
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2187
					/* Link subroutine group */
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2188
					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
  2189
				} else {
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2190
					adjust->parameter = IS_BYTE_INSIDE(adjust->variable, 0x60, 0x80) ? grf_load_byte(&buf) : 0;
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2191
				}
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
  2192
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2193
				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
  2194
				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
  2195
				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
  2196
				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
  2197
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2198
				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
  2199
					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
  2200
					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
  2201
				} 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
  2202
					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
  2203
					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
  2204
				}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2205
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2206
				/* Continue reading var adjusts while bit 5 is set. */
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2207
			} while (HASBIT(varadjust, 5));
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2208
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2209
			group->g.determ.num_ranges = grf_load_byte(&buf);
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2210
			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
  2211
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
  2212
			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
  2213
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2214
			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
  2215
				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
  2216
				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
  2217
				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
  2218
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2219
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
  2220
			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
  2221
			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
  2222
		}
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
  2223
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2224
		/* Randomized Sprite Group */
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2225
		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
  2226
		case 0x83: // Parent scope
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2227
		{
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
  2228
			if (!check_length(bufend - buf, 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
  2229
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2230
			group = AllocateSpriteGroup();
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2231
			group->type = SGT_RANDOMIZED;
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2232
			group->g.random.var_scope = HASBIT(type, 1) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2233
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2234
			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
  2235
			group->g.random.triggers       = GB(triggers, 0, 7);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2236
			group->g.random.cmp_mode       = HASBIT(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2237
			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
  2238
			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
  2239
			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
  2240
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
  2241
			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
  2242
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2243
			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
  2244
				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
  2245
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2246
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2247
			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
  2248
		}
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2249
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
  2250
		/* 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
  2251
		default:
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2252
		{
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  2253
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  2254
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
  2255
			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
  2256
				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
  2257
				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
  2258
				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
  2259
				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
  2260
				case GSF_STATION:
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2261
				case GSF_CANAL:
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2262
				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
  2263
				{
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2264
					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
  2265
					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
  2266
					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
  2267
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2268
					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
  2269
						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
  2270
						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
  2271
					}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2272
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
  2273
					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
  2274
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2275
					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
  2276
					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
  2277
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2278
					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
  2279
					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
  2280
					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
  2281
					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
  2282
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2283
					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
  2284
							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
  2285
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2286
					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
  2287
						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
  2288
						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
  2289
						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
  2290
					}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2291
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2292
					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
  2293
						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
  2294
						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
  2295
						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
  2296
					}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2297
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2298
					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
  2299
				}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2300
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2301
				case GSF_TOWNHOUSE: {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2302
					byte sprites     = _cur_grffile->spriteset_numents;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2303
					byte num_sprites = max((uint8)1, type);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2304
					uint i;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2305
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2306
					group = AllocateSpriteGroup();
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2307
					group->type = SGT_TILELAYOUT;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2308
					group->g.layout.num_sprites = sprites;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2309
					group->g.layout.dts = CallocT<DrawTileSprites>(1);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2310
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2311
					/* Groundsprite */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2312
					group->g.layout.dts->ground_sprite = grf_load_word(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2313
					group->g.layout.dts->ground_pal    = grf_load_word(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2314
					/* Remap transparent/colour modifier bits */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2315
					if (HASBIT(group->g.layout.dts->ground_sprite, 14)) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2316
						CLRBIT(group->g.layout.dts->ground_sprite, 14);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2317
						SETBIT(group->g.layout.dts->ground_sprite, PALETTE_MODIFIER_TRANSPARENT);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2318
					}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2319
					if (HASBIT(group->g.layout.dts->ground_sprite, 15)) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2320
						CLRBIT(group->g.layout.dts->ground_sprite, 15);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2321
						SETBIT(group->g.layout.dts->ground_sprite, PALETTE_MODIFIER_COLOR);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2322
					}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2323
					if (HASBIT(group->g.layout.dts->ground_pal, 14)) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2324
						CLRBIT(group->g.layout.dts->ground_pal, 14);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2325
						SETBIT(group->g.layout.dts->ground_sprite, SPRITE_MODIFIER_OPAQUE);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2326
					}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2327
					if (HASBIT(group->g.layout.dts->ground_pal, 15)) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2328
						/* Bit 31 set means this is a custom sprite, so rewrite it to the
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2329
						 * last spriteset defined. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2330
						SpriteID sprite = _cur_grffile->spriteset_start + GB(group->g.layout.dts->ground_sprite, 0, 14) * sprites;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2331
						SB(group->g.layout.dts->ground_sprite, 0, SPRITE_WIDTH, sprite);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2332
						CLRBIT(group->g.layout.dts->ground_pal, 15);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2333
					}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2334
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2335
					group->g.layout.dts->seq = CallocT<DrawTileSeqStruct>(num_sprites + 1);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2336
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2337
					for (i = 0; i < num_sprites; i++) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2338
						DrawTileSeqStruct *seq = (DrawTileSeqStruct*)&group->g.layout.dts->seq[i];
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2339
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2340
						seq->image = grf_load_word(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2341
						seq->pal   = grf_load_word(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2342
						seq->delta_x = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2343
						seq->delta_y = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2344
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2345
						if (HASBIT(seq->image, 14)) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2346
							CLRBIT(seq->image, 14);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2347
							SETBIT(seq->image, PALETTE_MODIFIER_TRANSPARENT);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2348
						}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2349
						if (HASBIT(seq->image, 15)) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2350
							CLRBIT(seq->image, 15);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2351
							SETBIT(seq->image, PALETTE_MODIFIER_COLOR);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2352
						}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2353
						if (HASBIT(seq->pal, 14)) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2354
							CLRBIT(seq->pal, 14);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2355
							SETBIT(seq->image, SPRITE_MODIFIER_OPAQUE);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2356
						}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2357
						if (HASBIT(seq->pal, 15)) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2358
							/* Bit 31 set means this is a custom sprite, so rewrite it to the
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2359
							 * last spriteset defined. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2360
							SpriteID sprite = _cur_grffile->spriteset_start + GB(seq->image, 0, 14) * sprites;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2361
							SB(seq->image, 0, SPRITE_WIDTH, sprite);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2362
							CLRBIT(seq->pal, 15);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2363
						}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2364
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2365
						if (type > 0) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2366
							seq->delta_z = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2367
							if ((byte)seq->delta_z == 0x80) continue;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2368
						}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2369
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2370
						seq->size_x = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2371
						seq->size_y = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2372
						seq->size_z = grf_load_byte(&buf);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2373
					}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2374
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2375
					/* Set the terminator value. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2376
					((DrawTileSeqStruct*)group->g.layout.dts->seq)[i].delta_x = (byte)0x80;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2377
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2378
					break;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2379
				}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2380
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
  2381
				/* 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
  2382
				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
  2383
			}
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
  2384
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2385
	}
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
  2386
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
  2387
	_cur_grffile->spritegroups[setid] = group;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2388
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2389
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2390
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
  2391
{
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2392
	/* 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
  2393
	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
  2394
	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
  2395
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2396
	if (_cur_grffile->cargo_max == 0) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2397
		/* No cargo table, so use bitnum values */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2398
		if (ctype >= 32) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2399
			grfmsg(1, "TranslateCargo: Cargo bitnum %d out of range (max 31), skipping.", ctype);
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2400
			return CT_INVALID;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2401
		}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2402
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2403
		for (CargoID c = 0; c < NUM_CARGO; c++) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2404
			const CargoSpec *cs = GetCargo(c);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2405
			if (!cs->IsValid()) continue;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2406
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2407
			if (cs->bitnum == ctype) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2408
				grfmsg(6, "TranslateCargo: Cargo bitnum %d mapped to cargo type %d.", ctype, c);
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2409
				return c;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2410
			}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2411
		}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2412
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2413
		grfmsg(5, "TranslateCargo: Cargo bitnum %d not available in this climate, skipping.", ctype);
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2414
		return CT_INVALID;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2415
	}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2416
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2417
	/* Check if the cargo type is out of bounds of the cargo translation table */
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2418
	if (ctype >= _cur_grffile->cargo_max) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2419
		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
  2420
		return CT_INVALID;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2421
	}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2422
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2423
	/* Look up the cargo label from the translation table */
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2424
	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
  2425
	if (cl == 0) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2426
		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
  2427
		return CT_INVALID;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2428
	}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2429
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2430
	ctype = GetCargoIDByLabel(cl);
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2431
	if (ctype == CT_INVALID) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2432
		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
  2433
		return CT_INVALID;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2434
	}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2435
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2436
	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
  2437
	return ctype;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2438
}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2439
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2440
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2441
static void VehicleMapSpriteGroup(byte *buf, byte feature, uint8 idcount, uint8 cidcount, bool wagover)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2442
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2443
	static byte *last_engines;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2444
	static int last_engines_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2445
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2446
	if (!wagover) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2447
		if (last_engines_count != idcount) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2448
			last_engines = ReallocT(last_engines, idcount);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2449
			last_engines_count = idcount;
403
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  2450
		}
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2451
	} else {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2452
		if (last_engines_count == 0) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2453
			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
  2454
			return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2455
		}
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2456
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2457
		grfmsg(6, "VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons",
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2458
				last_engines_count, idcount);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2459
	}
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
  2460
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2461
	for (uint i = 0; i < idcount; i++) {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2462
		uint8 engine_id = buf[3 + i];
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2463
		uint8 engine = engine_id + _vehshifts[feature];
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2464
		byte *bp = &buf[4 + idcount];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2465
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2466
		if (engine_id > _vehcounts[feature]) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2467
			grfmsg(0, "Id %u for feature 0x%02X is out of bounds", engine_id, feature);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2468
			return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2469
		}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2470
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2471
		grfmsg(7, "VehicleMapSpriteGroup: [%d] Engine %d...", i, engine);
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2472
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2473
		for (uint c = 0; c < cidcount; c++) {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2474
			uint8 ctype = grf_load_byte(&bp);
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  2475
			uint16 groupid = grf_load_word(&bp);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2476
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2477
			grfmsg(8, "VehicleMapSpriteGroup: * [%d] Cargo type 0x%X, group id 0x%02X", c, ctype, groupid);
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2478
2516
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  2479
			if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2480
				grfmsg(1, "VehicleMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping", groupid, _cur_grffile->spritegroups_count);
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2481
				continue;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2482
			}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2483
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2484
			ctype = TranslateCargo(feature, ctype);
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2485
			if (ctype == CT_INVALID) continue;
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
  2486
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2487
			if (wagover) {
4869
cded5f3a83c9 (svn r6795) - NewGRF: Add support for cargo-specific wagon overrides.
peter1138
parents: 4818
diff changeset
  2488
				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
  2489
			} 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
  2490
				SetCustomEngineSprites(engine, ctype, _cur_grffile->spritegroups[groupid]);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2491
				last_engines[i] = engine;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2492
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2493
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2494
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2495
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2496
	{
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2497
		byte *bp = &buf[4 + idcount + cidcount * 3];
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  2498
		uint16 groupid = grf_load_word(&bp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2499
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2500
		grfmsg(8, "-- Default group id 0x%04X", groupid);
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2501
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2502
		for (uint i = 0; i < idcount; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2503
			uint8 engine = buf[3 + i] + _vehshifts[feature];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2504
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2505
			/* Don't tell me you don't love duplicated code! */
2516
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  2506
			if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2507
				grfmsg(1, "VehicleMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping",
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2508
				       groupid, _cur_grffile->spritegroups_count);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2509
				continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2510
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2511
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2512
			if (wagover) {
3695
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  2513
				/* If the ID for this action 3 is the same as the vehicle ID,
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2514
 * this indicates we have a helicopter rotor override. */
3695
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  2515
				if (feature == GSF_AIRCRAFT && engine == last_engines[i]) {
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  2516
					SetRotorOverrideSprites(engine, _cur_grffile->spritegroups[groupid]);
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  2517
				} else {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2518
					/* TODO: No multiple cargo types per vehicle yet. --pasky */
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
  2519
					SetWagonOverrideSprites(engine, CT_DEFAULT, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count);
3695
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  2520
				}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2521
			} else {
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
  2522
				SetCustomEngineSprites(engine, CT_DEFAULT, _cur_grffile->spritegroups[groupid]);
3924
de86db4fbd1e (svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents: 3895
diff changeset
  2523
				SetEngineGRF(engine, _cur_grffile);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2524
				last_engines[i] = engine;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2525
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2526
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2527
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2528
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2529
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2530
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2531
static void CanalMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2532
{
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2533
	byte *bp = &buf[4 + idcount + cidcount * 3];
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2534
	uint16 groupid = grf_load_word(&bp);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2535
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2536
	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2537
		grfmsg(1, "CanalMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.",
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2538
		       groupid, _cur_grffile->spritegroups_count);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2539
		return;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2540
	}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2541
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2542
	for (uint i = 0; i < idcount; i++) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2543
		CanalFeature cf = (CanalFeature)buf[3 + i];
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2544
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2545
		if (cf >= CF_END) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2546
			grfmsg(1, "CanalMapSpriteGroup: Canal subset %d out of range, skipping", cf);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2547
			continue;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2548
		}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2549
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2550
		_canal_sg[cf] = _cur_grffile->spritegroups[groupid];
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2551
	}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2552
}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2553
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2554
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2555
static void StationMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2556
{
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2557
	for (uint i = 0; i < idcount; i++) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2558
		uint8 stid = buf[3 + i];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2559
		StationSpec *statspec = _cur_grffile->stations[stid];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2560
		byte *bp = &buf[4 + idcount];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2561
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2562
		for (uint c = 0; c < cidcount; c++) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2563
			uint8 ctype = grf_load_byte(&bp);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2564
			uint16 groupid = grf_load_word(&bp);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2565
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2566
			if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2567
				grfmsg(1, "StationMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping",
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2568
				       groupid, _cur_grffile->spritegroups_count);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2569
				continue;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2570
			}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2571
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2572
			ctype = TranslateCargo(GSF_STATION, ctype);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2573
			if (ctype == CT_INVALID) continue;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2574
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2575
			statspec->spritegroup[ctype] = _cur_grffile->spritegroups[groupid];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2576
		}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2577
	}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2578
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2579
	{
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2580
		byte *bp = &buf[4 + idcount + cidcount * 3];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2581
		uint16 groupid = grf_load_word(&bp);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2582
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2583
		if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2584
			grfmsg(1, "StationMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping",
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2585
			       groupid, _cur_grffile->spritegroups_count);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2586
			return;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2587
		}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2588
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2589
		for (uint i = 0; i < idcount; i++) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2590
			uint8 stid = buf[3 + i];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2591
			StationSpec *statspec = _cur_grffile->stations[stid];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2592
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2593
			statspec->spritegroup[CT_DEFAULT] = _cur_grffile->spritegroups[groupid];
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9907
diff changeset
  2594
			statspec->grffile = _cur_grffile;
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2595
			statspec->localidx = stid;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2596
			SetCustomStationSpec(statspec);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2597
		}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2598
	}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2599
}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2600
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2601
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2602
static void TownHouseMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2603
{
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2604
	byte *bp = &buf[4 + idcount + cidcount * 3];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2605
	uint16 groupid = grf_load_word(&bp);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2606
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2607
	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2608
		grfmsg(1, "TownHouseMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.",
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2609
		       groupid, _cur_grffile->spritegroups_count);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2610
		return;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2611
	}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2612
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2613
	for (uint i = 0; i < idcount; i++) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2614
		uint8 hid = buf[3 + i];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2615
		HouseSpec *hs = _cur_grffile->housespec[hid];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2616
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2617
		if (hs == NULL) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2618
			grfmsg(1, "TownHouseMapSpriteGroup: Too many houses defined, skipping");
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2619
			return;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2620
		}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2621
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2622
		hs->spritegroup = _cur_grffile->spritegroups[groupid];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2623
	}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2624
}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2625
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2626
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2627
static void CargoMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2628
{
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2629
	byte *bp = &buf[4 + idcount + cidcount * 3];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2630
	uint16 groupid = grf_load_word(&bp);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2631
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2632
	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2633
		grfmsg(1, "CargoMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.",
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2634
		       groupid, _cur_grffile->spritegroups_count);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2635
		return;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2636
	}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2637
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2638
	for (uint i = 0; i < idcount; i++) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2639
		CargoID cid = buf[3 + i];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2640
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2641
		if (cid >= NUM_CARGO) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2642
			grfmsg(1, "CargoMapSpriteGroup: Cargo ID %d out of range, skipping");
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2643
			continue;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2644
		}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2645
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2646
		CargoSpec *cs = &_cargo[cid];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2647
		cs->grfid = _cur_grffile->grfid;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2648
		cs->group = _cur_grffile->spritegroups[groupid];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2649
	}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2650
}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2651
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2652
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2653
/* Action 0x03 */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2654
static void FeatureMapSpriteGroup(byte *buf, int len)
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2655
{
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2656
	/* <03> <feature> <n-id> <ids>... <num-cid> [<cargo-type> <cid>]... <def-cid>
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2657
	 * id-list    := [<id>] [id-list]
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2658
	 * cargo-list := <cargo-type> <cid> [cargo-list]
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2659
	 *
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2660
	 * B feature       see action 0
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2661
	 * B n-id          bits 0-6: how many IDs this definition applies to
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2662
	 *                 bit 7: if set, this is a wagon override definition (see below)
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2663
	 * B ids           the IDs for which this definition applies
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2664
	 * B num-cid       number of cargo IDs (sprite group IDs) in this definition
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2665
	 *                 can be zero, in that case the def-cid is used always
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2666
	 * B cargo-type    type of this cargo type (e.g. mail=2, wood=7, see below)
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2667
	 * W cid           cargo ID (sprite group ID) for this type of cargo
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2668
	 * W def-cid       default cargo ID (sprite group ID) */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2669
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2670
	if (!check_length(len, 6, "FeatureMapSpriteGroup")) return;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2671
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2672
	uint8 feature = buf[1];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2673
	uint8 idcount = buf[2] & 0x7F;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2674
	bool wagover = (buf[2] & 0x80) == 0x80;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2675
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2676
	if (!check_length(len, 3 + idcount, "FeatureMapSpriteGroup")) return;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2677
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2678
	/* If idcount is zero, this is a feature callback */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2679
	if (idcount == 0) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2680
		grfmsg(2, "FeatureMapSpriteGroup: Feature callbacks not implemented yet");
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2681
		return;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2682
	}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2683
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2684
	uint8 cidcount = buf[3 + idcount];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2685
	if (!check_length(len, 4 + idcount + cidcount * 3, "FeatureMapSpriteGroup")) return;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2686
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2687
	grfmsg(6, "FeatureMapSpriteGroup: Feature %d, %d ids, %d cids, wagon override %d",
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2688
			feature, idcount, cidcount, wagover);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2689
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2690
	if (_cur_grffile->spriteset_start == 0 || _cur_grffile->spritegroups == 0) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2691
		grfmsg(1, "FeatureMapSpriteGroup: No sprite set to work on! Skipping");
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2692
		return;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2693
	}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2694
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2695
	switch (feature) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2696
		case GSF_TRAIN:
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2697
		case GSF_ROAD:
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2698
		case GSF_SHIP:
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2699
		case GSF_AIRCRAFT:
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2700
			VehicleMapSpriteGroup(buf, feature, idcount, cidcount, wagover);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2701
			return;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2702
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2703
		case GSF_CANAL:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2704
			CanalMapSpriteGroup(buf, idcount, cidcount);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2705
			return;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2706
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2707
		case GSF_STATION:
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2708
			StationMapSpriteGroup(buf, idcount, cidcount);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2709
			return;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2710
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2711
		case GSF_TOWNHOUSE:
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2712
			TownHouseMapSpriteGroup(buf, idcount, cidcount);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2713
			return;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2714
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2715
		case GSF_CARGOS:
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2716
			CargoMapSpriteGroup(buf, idcount, cidcount);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2717
			return;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2718
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2719
		default:
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2720
			grfmsg(1, "FeatureMapSpriteGroup: Unsupported feature %d, skipping", feature);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2721
			return;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2722
	}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2723
}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2724
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2725
/* Action 0x04 */
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  2726
static void FeatureNewName(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2727
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2728
	/* <04> <veh-type> <language-id> <num-veh> <offset> <data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2729
	 *
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2730
	 * B veh-type      see action 0 (as 00..07, + 0A
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2731
	 *                 But IF veh-type = 48, then generic text
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2732
	 * 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
  2733
	                   with up to 64 language.
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2734
	                   Otherwise, it is a mapping where set bits have meaning
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2735
	                   0 = american, 1 = english, 2 = german, 3 = french, 4 = spanish
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2736
	                   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
  2737
	 * 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
  2738
	 * 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
  2739
	 *                 Byte : ID of vehicle to change
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2740
	 *                 Word : ID of string to change/add
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2741
	 * 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
  2742
	 *                 which the next name begins. */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2743
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
  2744
	bool new_scheme = _cur_grffile->grf_version >= 7;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2745
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
  2746
	if (!check_length(len, 6, "FeatureNewName")) return;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2747
	buf++;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2748
	uint8 feature  = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2749
	uint8 lang     = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2750
	uint8 num      = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2751
	bool generic   = HASBIT(lang, 7);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2752
	uint16 id      = generic ? grf_load_word(&buf) : grf_load_byte(&buf);
4992
6d0a80c5c654 (svn r6995) - Codechange: NewGRF; strip bit 7 of the language ID earlier and handle handle a language ID of 0x7F as the preferred default language.
peter1138
parents: 4964
diff changeset
  2753
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
  2754
	CLRBIT(lang, 7);
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2755
3760
10a6f762e754 (svn r4751) - NewGRF: when assigning new texts, ignore the feature byte as some sets use generic feature always. Also, don't add vehicle id shifts if the vehicle id is out of range.
peter1138
parents: 3750
diff changeset
  2756
	if (feature <= GSF_AIRCRAFT && id < _vehcounts[feature]) {
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2757
		id += _vehshifts[feature];
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2758
	}
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2759
	uint16 endid = id + num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2760
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2761
	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
  2762
	               id, endid, feature, lang);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2763
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
  2764
	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
  2765
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2766
	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
  2767
		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
  2768
		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
  2769
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
  2770
		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
  2771
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2772
		grfmsg(8, "FeatureNewName: 0x%04X <- %s", id, name);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2773
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2774
		switch (feature) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2775
			case GSF_TRAIN:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2776
			case GSF_ROAD:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2777
			case GSF_SHIP:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2778
			case GSF_AIRCRAFT:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2779
				if (id < TOTAL_NUM_ENGINES) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2780
					StringID string = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_8000_KIRBY_PAUL_TANK_STEAM + id);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2781
					SetCustomEngineName(id, string);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2782
				} else {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2783
					AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, id);
3614
2c75299f54bd (svn r4510) - NewGRF bounds checking:
peter1138
parents: 3604
diff changeset
  2784
				}
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2785
				break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2786
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2787
			case GSF_TOWNHOUSE:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2788
			default:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2789
				switch (GB(id, 8, 8)) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2790
					case 0xC4: // Station class name
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2791
						if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2792
							grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2793
						} else {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2794
							StationClassID sclass = _cur_grffile->stations[GB(id, 0, 8)]->sclass;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2795
							SetStationClassName(sclass, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED));
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2796
						}
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2797
						break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2798
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2799
					case 0xC5: // Station name
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2800
						if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2801
							grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2802
						} else {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2803
							_cur_grffile->stations[GB(id, 0, 8)]->name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2804
						}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2805
						break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2806
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2807
					case 0xC9: // House name
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2808
						if (_cur_grffile->housespec == NULL || _cur_grffile->housespec[GB(id, 0, 8)] == NULL) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2809
							grfmsg(1, "FeatureNewName: Attempt to name undefined house 0x%X, ignoring.", GB(id, 0, 8));
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2810
						} else {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2811
							_cur_grffile->housespec[GB(id, 0, 8)]->building_name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2812
						}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2813
						break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2814
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2815
					case 0xD0:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2816
					case 0xDC:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2817
						AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2818
						break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2819
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2820
					default:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2821
						grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2822
						break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2823
				}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2824
				break;
3642
a247e07fafdf (svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents: 3641
diff changeset
  2825
a247e07fafdf (svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents: 3641
diff changeset
  2826
#if 0
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2827
				case GSF_CANAL :
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2828
				case GSF_BRIDGE :
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2829
					AddGRFString(_cur_spriteid, id, lang, name);
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  2830
					switch (GB(id, 8, 8)) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2831
						case 0xC9: // House name
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2832
						default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2833
							grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2834
					}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2835
					break;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2836
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2837
				case GSF_INDUSTRIES :
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2838
				case 0x48 :   // for generic strings
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2839
					AddGRFString(_cur_spriteid, id, lang, name);
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2840
					break;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2841
				default :
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2842
					grfmsg(7, "FeatureNewName: Unsupported feature (0x%02X)", feature);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2843
					break;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2844
#endif
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2845
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2846
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2847
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2848
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2849
/* Action 0x05 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2850
static void GraphicsNew(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2851
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2852
	/* <05> <graphics-type> <num-sprites> <other data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2853
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2854
	 * 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
  2855
	 * 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
  2856
	 * V other data    Graphics type specific data.  Currently unused. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2857
	/* TODO */
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2858
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
  2859
	SpriteID replace = 0;
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2860
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
  2861
	if (!check_length(len, 2, "GraphicsNew")) return;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2862
	buf++;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2863
	uint8 type = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2864
	uint16 num = grf_load_extended(&buf);
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2865
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
  2866
	switch (type) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2867
		case 0x04: // Signal graphics
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
  2868
			if (num != 112 && num != 240) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2869
				grfmsg(1, "GraphicsNew: Signal graphics sprite count must be 112 or 240, skipping");
3638
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2870
				return;
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2871
			}
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
  2872
			_signal_base = _cur_spriteid;
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2873
			break;
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2874
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2875
		case 0x05: // Catenary graphics
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
  2876
			if (num != 48) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2877
				grfmsg(1, "GraphicsNew: Catenary graphics sprite count must be 48, skipping");
3708
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2878
				return;
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2879
			}
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
  2880
			replace = SPR_ELRAIL_BASE + 3;
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2881
			break;
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2882
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2883
		case 0x06: // Foundations
3709
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2884
			if (num != 74) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2885
				grfmsg(1, "GraphicsNew: Foundation graphics sprite count must be 74, skipping");
3709
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2886
				return;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2887
			}
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2888
			replace = SPR_SLOPES_BASE;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2889
			break;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2890
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2891
		case 0x08: // Canal graphics
3709
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2892
			if (num != 65) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2893
				grfmsg(1, "GraphicsNew: Canal graphics sprite count must be 65, skipping");
3709
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2894
				return;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2895
			}
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2896
			replace = SPR_CANALS_BASE + 5;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2897
			break;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2898
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2899
		case 0x09: // One way graphics
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2900
			if (num != 6) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2901
				grfmsg(1, "GraphicsNew: One way road graphics sprite count must be 6, skipping");
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2902
				return;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2903
			}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2904
			replace = SPR_ONEWAY_BASE;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2905
			break;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2906
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2907
		case 0x0A: // 2CC colour maps
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2908
			if (num != 256) {
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2909
				grfmsg(1, "GraphicsNew: 2CC colour maps sprite count must be 256, skipping");
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2910
				return;
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2911
			}
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2912
			replace = SPR_2CCMAP_BASE;
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2913
			break;
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2914
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2915
		case 0x0B: // tramways
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2916
			if (num != 113) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2917
				grfmsg(1, "GraphicsNew: Tramway graphics sprite count must be 113, skipping");
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2918
				return;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2919
			}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2920
			replace = SPR_TRAMWAY_BASE;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2921
			break;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2922
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2923
		case 0x0D: // Coast graphics
5210
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2924
			if (num != 16) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2925
				grfmsg(1, "GraphicsNew: Coast graphics sprite count must be 16, skipping");
5210
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2926
				return;
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2927
			}
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2928
			_coast_base = _cur_spriteid;
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2929
			break;
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2930
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2931
		case 0x10: // New airport sprites
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2932
			if (num != 15) {
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2933
				grfmsg(1, "GraphicsNew: Airport graphics sprite count must be 15, skipping");
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2934
				return;
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2935
			}
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2936
			replace = SPR_AIRPORTX_BASE;
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2937
			break;
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2938
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2939
		case 0x11: // Road stop sprites
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2940
			if (num != 8) {
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2941
				grfmsg(1, "GraphicsNew: Road stop graphics sprite count must be 8, skipping");
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2942
				return;
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2943
			}
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2944
			replace = SPR_ROADSTOP_BASE;
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2945
			break;
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  2946
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
  2947
		default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2948
			grfmsg(2, "GraphicsNew: Custom graphics (type 0x%02X) sprite block of length %u (unimplemented, ignoring)",
3638
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2949
					type, num);
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2950
			_skip_sprites = num;
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
  2951
			return;
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2952
	}
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
  2953
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
  2954
	if (replace == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2955
		grfmsg(2, "GraphicsNew: Loading %u sprites of type 0x%02X at SpriteID 0x%04X", num, type, _cur_spriteid);
3708
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2956
	} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2957
		grfmsg(2, "GraphicsNew: Replacing %u sprites of type 0x%02X at SpriteID 0x%04X", num, type, replace);
3708
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2958
	}
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
  2959
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
  2960
	for (; num > 0; num--) {
3708
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2961
		LoadNextSprite(replace == 0 ? _cur_spriteid++ : replace++, _file_index);
3638
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2962
		_nfo_line++;
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2963
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2964
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2965
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2966
/* Action 0x05 (SKIP) */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2967
static void SkipAct5(byte *buf, int len)
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2968
{
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2969
	if (!check_length(len, 2, "SkipAct5")) return;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2970
	buf++;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2971
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2972
	/* Ignore type byte */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2973
	grf_load_byte(&buf);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2974
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2975
	/* Skip the sprites of this action */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2976
	_skip_sprites = grf_load_extended(&buf);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2977
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2978
	grfmsg(3, "SkipAct5: Skipping %d sprites", _skip_sprites);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2979
}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2980
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2981
static uint32 GetParamVal(byte param, uint32 *cond_val)
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2982
{
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2983
	switch (param) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2984
		case 0x81: // current year
5340
82c981816fcb (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5338
diff changeset
  2985
			return clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
82c981816fcb (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5338
diff changeset
  2986
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2987
		case 0x83: // current climate, 0=temp, 1=arctic, 2=trop, 3=toyland
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2988
			return _opt.landscape;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2989
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2990
		case 0x84: { // GRF loading stage
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2991
			uint32 res = 0;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2992
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2993
			if (_cur_stage > GLS_INIT) SETBIT(res, 0);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2994
			if (_cur_stage == GLS_RESERVE) SETBIT(res, 8);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2995
			if (_cur_stage == GLS_ACTIVATION) SETBIT(res, 9);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2996
			return res;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2997
		}
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2998
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  2999
		case 0x85: // TTDPatch flags, only for bit tests
3811
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3000
			if (cond_val == NULL) {
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3001
				/* Supported in Action 0x07 and 0x09, not 0x0D */
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3002
				return 0;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3003
			} else {
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3004
				uint32 param_val = _ttdpatch_flags[*cond_val / 0x20];
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3005
				*cond_val %= 0x20;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3006
				return param_val;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3007
			}
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3008
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3009
		case 0x86: // road traffic side, bit 4 clear=left, set=right
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3010
			return _opt.road_side << 4;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3011
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3012
		case 0x88: // GRF ID check
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3013
			return 0;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3014
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3015
		case 0x8B: { // TTDPatch version
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3016
			uint major    = 2;
4993
7d84a318e3a4 (svn r6996) - Codechange: Pretend to be the current version of TTDPatch. This value doesn't anything to us as we don't follow TTDPatch's development timeline...
peter1138
parents: 4992
diff changeset
  3017
			uint minor    = 6;
7d84a318e3a4 (svn r6996) - Codechange: Pretend to be the current version of TTDPatch. This value doesn't anything to us as we don't follow TTDPatch's development timeline...
peter1138
parents: 4992
diff changeset
  3018
			uint revision = 0; // special case: 2.0.1 is 2.0.10
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3019
			uint build    = 1210;
4993
7d84a318e3a4 (svn r6996) - Codechange: Pretend to be the current version of TTDPatch. This value doesn't anything to us as we don't follow TTDPatch's development timeline...
peter1138
parents: 4992
diff changeset
  3020
			return (major << 24) | (minor << 20) | (revision << 16) | build;
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3021
		}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3022
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3023
		case 0x8D: // TTD Version, 00=DOS, 01=Windows
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3024
			return !_use_dos_palette;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3025
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3026
		case 0x8E: // Y-offset for train sprites
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3027
			return _traininfo_vehicle_pitch;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3028
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3029
		case 0x92: // Game mode
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3030
			return _game_mode;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3031
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3032
		case 0x9A: // Always -1
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  3033
			return UINT_MAX;
5287
94a6c3c924b2 (svn r7436) -Codechange: Add action7/9/D variable 0x9A (-1)
peter1138
parents: 5234
diff changeset
  3034
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3035
		case 0x9D: // TTD Platform, 00=TTDPatch, 01=OpenTTD
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3036
			return 1;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3037
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3038
		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
  3039
			return _misc_grf_features;
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  3040
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3041
		default:
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3042
			/* GRF Parameter */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3043
			if (param < 0x80) return _cur_grffile->param[param];
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3044
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3045
			/* In-game variable. */
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3046
			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
  3047
			return UINT_MAX;
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3048
	}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3049
}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3050
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3051
/* Action 0x06 */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3052
static void CfgApply(byte *buf, int len)
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3053
{
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3054
	/* <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
  3055
	 *
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3056
	 * 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
  3057
	 *                 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
  3058
	 * 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
  3059
	 *                 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
  3060
	 *                 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
  3061
	 *                 were specified.
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3062
	 * 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
  3063
	 *                 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
  3064
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3065
	/* Preload the next sprite */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3066
	uint32 pos = FioGetPos();
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3067
	uint16 num = FioReadWord();
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3068
	uint8 type = FioReadByte();
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3069
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3070
	/* 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
  3071
	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
  3072
		_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
  3073
		FioReadBlock(_preload_sprite, num);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3074
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3075
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3076
	/* 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
  3077
	FioSeekTo(pos, SEEK_SET);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3078
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3079
	if (type != 0xFF) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3080
		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
  3081
		return;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3082
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3083
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3084
	/* 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
  3085
	buf++;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3086
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3087
	for (;;) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3088
		uint i;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3089
		uint param_num;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3090
		uint param_size;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3091
		uint offset;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3092
		bool add_value;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3093
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3094
		/* 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
  3095
		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
  3096
		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
  3097
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3098
		/* 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
  3099
		 * 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
  3100
		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
  3101
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3102
		/* 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
  3103
		 * instead of replacing it. */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3104
		add_value  = HASBIT(param_size, 7);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3105
		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
  3106
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3107
		/* 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
  3108
		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
  3109
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3110
		/* 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
  3111
		 * 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
  3112
		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
  3113
			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
  3114
			break;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3115
		}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3116
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3117
		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
  3118
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3119
		bool carry = false;
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3120
		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
  3121
			uint32 value = GetParamVal(param_num + i / 4, NULL);
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3122
			/* Reset carry flag for each iteration of the variable (only really
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3123
			 * matters if param_size is greater than 4) */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3124
			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
  3125
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3126
			if (add_value) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3127
				uint new_value = _preload_sprite[offset + i] + GB(value, (i % 4) * 8, 8) + (carry ? 1 : 0);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3128
				_preload_sprite[offset + i] = GB(new_value, 0, 8);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3129
				/* Check if the addition overflowed */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3130
				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
  3131
			} else {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3132
				_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
  3133
			}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3134
		}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3135
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3136
}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3137
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3138
/* Action 0x07 */
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3139
/* Action 0x09 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3140
static void SkipIf(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3141
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3142
	/* <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
  3143
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3144
	 * B param-num
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3145
	 * B param-size
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3146
	 * B condition-type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3147
	 * V value
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3148
	 * B num-sprites */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3149
	/* 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
  3150
	uint32 cond_val = 0;
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3151
	uint32 mask = 0;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  3152
	bool result;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3153
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
  3154
	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
  3155
	buf++;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3156
	uint8 param     = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3157
	uint8 paramsize = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3158
	uint8 condtype  = grf_load_byte(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3159
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
  3160
	if (condtype < 2) {
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  3161
		/* 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
  3162
		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
  3163
	}
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
  3164
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  3165
	switch (paramsize) {
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3166
		case 4: cond_val = grf_load_dword(&buf); mask = 0xFFFFFFFF; break;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3167
		case 2: cond_val = grf_load_word(&buf);  mask = 0x0000FFFF; break;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3168
		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
  3169
		default: break;
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  3170
	}
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
  3171
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3172
	if (param < 0x80 && _cur_grffile->param_end <= param) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  3173
		grfmsg(7, "SkipIf: Param %d undefined, skipping test", param);
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3174
		return;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3175
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3176
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3177
	uint32 param_val = GetParamVal(param, &cond_val);
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3178
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  3179
	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
  3180
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
  3181
	if (param == 0x88) {
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
  3182
		/* 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
  3183
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
  3184
		const GRFConfig *c = GetGRFConfig(cond_val);
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  3185
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
  3186
		if (condtype != 10 && c == NULL) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  3187
			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
  3188
			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
  3189
		}
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
  3190
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
  3191
		switch (condtype) {
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
  3192
			/* Tests 6 to 10 are only for param 0x88, GRFID checks */
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3193
			case 6: // Is GRFID active?
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3194
				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
  3195
				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
  3196
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3197
			case 7: // Is GRFID non-active?
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3198
				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
  3199
				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
  3200
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3201
			case 8: // GRFID is not but will be active?
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3202
				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
  3203
				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
  3204
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3205
			case 9: // GRFID is or will be active?
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3206
				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
  3207
				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
  3208
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3209
			case 10: // 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
  3210
				/* This is the only condtype that doesn't get ignored if the GRFID is not found */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3211
				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
  3212
				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
  3213
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  3214
			default: grfmsg(1, "SkipIf: Unsupported GRF test %d. Ignoring", condtype); return;
5234
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  3215
		}
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
  3216
	} 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
  3217
		/* 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
  3218
		switch (condtype) {
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
  3219
			case 0: result = !!(param_val & (1 << cond_val));
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  3220
				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
  3221
			case 1: result = !(param_val & (1 << cond_val));
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  3222
				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
  3223
			case 2: result = (param_val & mask) == cond_val;
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  3224
				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
  3225
			case 3: result = (param_val & mask) != cond_val;
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  3226
				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
  3227
			case 4: result = (param_val & mask) < cond_val;
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  3228
				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
  3229
			case 5: result = (param_val & mask) > cond_val;
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  3230
				break;
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3231
			case 11: result = GetCargoIDByLabel(BSWAP32(cond_val)) == CT_INVALID;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3232
				break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3233
			case 12: result = GetCargoIDByLabel(BSWAP32(cond_val)) != CT_INVALID;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3234
				break;
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
  3235
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  3236
			default: grfmsg(1, "SkipIf: Unsupported test %d. Ignoring", condtype); return;
5234
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  3237
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3238
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3239
1607
320079c7ac28 (svn r2111) So, result is bool therefore no need for this horrible == 0 thing.
pasky
parents: 1606
diff changeset
  3240
	if (!result) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  3241
		grfmsg(2, "SkipIf: Not skipping sprites, test was false");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3242
		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
  3243
	}
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
  3244
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3245
	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
  3246
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3247
	/* 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
  3248
	 * 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
  3249
	 * 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
  3250
	 * label in the file is used. */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3251
	GRFLabel *choice = NULL;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3252
	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
  3253
		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
  3254
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3255
		/* 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
  3256
		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
  3257
		/* 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
  3258
		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
  3259
			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
  3260
			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
  3261
		}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3262
	}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3263
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3264
	if (choice != NULL) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  3265
		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
  3266
		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
  3267
		_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
  3268
		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
  3269
	}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3270
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  3271
	grfmsg(2, "SkipIf: Skipping %d sprites, test was true", numsprites);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3272
	_skip_sprites = numsprites;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3273
	if (_skip_sprites == 0) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3274
		/* Zero means there are no sprites to skip, so
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3275
		 * we use -1 to indicate that all further
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3276
		 * sprites should be skipped. */
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3277
		_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
  3278
14794ebde68e (svn r8831) -Feature: If an action 7/9 leads to skipping the rest of the file, disable the
maedhros
parents: 6421
diff changeset
  3279
		/* If an action 8 hasn't been encountered yet, disable the grf. */
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3280
		if (_cur_grfconfig->status != GCS_ACTIVATED) _cur_grfconfig->status = GCS_DISABLED;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3281
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3282
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3283
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  3284
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
  3285
/* Action 0x08 (GLS_FILESCAN) */
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
  3286
static void ScanInfo(byte *buf, int len)
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3287
{
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3288
	if (!check_length(len, 8, "Info")) return;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3289
	buf++;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3290
	grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3291
	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
  3292
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3293
	_cur_grfconfig->grfid = grfid;
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  3294
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
  3295
	/* GRF IDs starting with 0xFF are reserved for internal TTDPatch use */
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3296
	if (GB(grfid, 24, 8) == 0xFF) SETBIT(_cur_grfconfig->flags, GCF_SYSTEM);
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3297
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  3298
	len -= 6;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3299
	const char *name = grf_load_string(&buf, len);
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
  3300
	_cur_grfconfig->name = TranslateTTDPatchCodes(name);
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
  3301
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
  3302
	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
  3303
	if (len > 0) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3304
		const char *info = grf_load_string(&buf, len);
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
  3305
		_cur_grfconfig->info = TranslateTTDPatchCodes(info);
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  3306
	}
5329
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3307
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3308
	/* 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
  3309
	_skip_sprites = -1;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3310
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3311
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  3312
/* Action 0x08 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3313
static void GRFInfo(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3314
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3315
	/* <08> <version> <grf-id> <name> <info>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3316
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3317
	 * B version       newgrf version, currently 06
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3318
	 * 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
  3319
	 * S name          name of this .grf set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3320
	 * S info          string describing the set, and e.g. author and copyright */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3321
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3322
	if (!check_length(len, 8, "GRFInfo")) return;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3323
	buf++;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3324
	uint8 version    = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3325
	uint32 grfid     = grf_load_dword(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3326
	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
  3327
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
  3328
	_cur_grffile->grfid = grfid;
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  3329
	_cur_grffile->grf_version = version;
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3330
	_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
  3331
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
  3332
	/* Do swap the GRFID for displaying purposes since people expect that */
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  3333
	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
  3334
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3335
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  3336
/* Action 0x0A */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3337
static void SpriteReplace(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3338
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3339
	/* <0A> <num-sets> <set1> [<set2> ...]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3340
	 * <set>: <num-sprites> <first-sprite>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3341
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3342
	 * 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
  3343
	 * Each set:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3344
	 * 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
  3345
	 * 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
  3346
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3347
	buf++; // skip action byte
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3348
	uint8 num_sets = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3349
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3350
	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
  3351
		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
  3352
		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
  3353
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3354
		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
  3355
			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
  3356
		);
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
  3357
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3358
		for (uint j = 0; j < num_sprites; j++) {
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
  3359
			LoadNextSprite(first_sprite + j, _file_index); // XXX
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  3360
			_nfo_line++;
361
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  3361
		}
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
  3362
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3363
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3364
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3365
/* Action 0x0A (SKIP) */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3366
static void SkipActA(byte *buf, int len)
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3367
{
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3368
	buf++;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3369
	uint8 num_sets = grf_load_byte(&buf);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3370
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3371
	for (uint i = 0; i < num_sets; i++) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3372
		/* Skip the sprites this replaces */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3373
		_skip_sprites += grf_load_byte(&buf);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3374
		/* But ignore where they go */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3375
		grf_load_word(&buf);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3376
	}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3377
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3378
	grfmsg(3, "SkipActA: Skipping %d sprites", _skip_sprites);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3379
}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3380
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  3381
/* Action 0x0B */
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
  3382
static void GRFLoadError(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3383
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3384
	/* <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
  3385
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3386
	 * B severity      00: notice, contine loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3387
	 *                 01: warning, continue loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3388
	 *                 02: error, but continue loading grf file, and attempt
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3389
	 *                     loading grf again when loading or starting next game
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3390
	 *                 03: error, abort loading and prevent loading again in
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3391
	 *                     the future (only when restarting the patch)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3392
	 * 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
  3393
	 * B message-id    message to show, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3394
	 * 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
  3395
	 *                 not present for built-in messages.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3396
	 * 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
  3397
	 * 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
  3398
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3399
	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
  3400
		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
  3401
		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
  3402
		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
  3403
		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
  3404
		STR_NEWGRF_ERROR_LOAD_BEFORE,
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3405
		STR_NEWGRF_ERROR_LOAD_AFTER
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3406
	};
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  3407
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
  3408
	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
  3409
		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
  3410
		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
  3411
		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
  3412
		STR_NEWGRF_ERROR_MSG_FATAL
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  3413
	};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3414
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
  3415
	/* AddGRFString expects the string to be referred to by an id in the newgrf
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3416
	 * file. Errors messages are never referred to however, so invent ids that
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3417
	 * are unlikely to be reached in a newgrf file so they don't overwrite
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3418
	 * anything 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
  3419
	enum {
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3420
		MESSAGE_STRING_ID = MAX_UVALUE(StringID) - 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
  3421
		MESSAGE_DATA_ID   = MAX_UVALUE(StringID)
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3422
	};
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3423
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3424
	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
  3425
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3426
	/* 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
  3427
	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
  3428
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3429
	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
  3430
	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
  3431
	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
  3432
	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
  3433
	len -= 4;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3434
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3435
	/* 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
  3436
	 * is set. */
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3437
	if (!HASBIT(severity, 7) && _cur_stage == GLS_INIT) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3438
		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
  3439
		return;
3588
a1adf8a40756 (svn r4474) - NewGRF: Skip non-fatal errors when not in stage 2.
peter1138
parents: 3577
diff changeset
  3440
	}
6421
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3441
	CLRBIT(severity, 7);
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3442
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3443
	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
  3444
		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
  3445
		severity = 2;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3446
	} 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
  3447
		/* 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
  3448
		 * more of it gets loaded. */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3449
		_cur_grfconfig->status = GCS_DISABLED;
6421
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3450
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3451
		_skip_sprites = -1;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3452
	}
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3453
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3454
	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
  3455
		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
  3456
		return;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3457
	}
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3458
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3459
	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
  3460
		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
  3461
		return;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3462
	}
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3463
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
  3464
	bool new_scheme = _cur_grffile->grf_version >= 7;
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3465
	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
  3466
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3467
	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
  3468
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3469
	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
  3470
		/* 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
  3471
		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
  3472
		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
  3473
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3474
		error->message = AddGRFString(_cur_grffile->grfid, MESSAGE_STRING_ID, lang, new_scheme, message, STR_UNDEFINED);
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3475
	} 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
  3476
		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
  3477
	}
02c062eb2c74 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents: 6422
diff changeset
  3478
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
  3479
	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
  3480
		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
  3481
		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
  3482
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3483
		error->data = AddGRFString(_cur_grffile->grfid, MESSAGE_DATA_ID, lang, new_scheme, data, STR_UNDEFINED);
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3484
	}
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3485
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3486
	/* 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
  3487
	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
  3488
	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
  3489
		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
  3490
		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
  3491
	}
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3492
	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
  3493
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3494
	_cur_grfconfig->error = error;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3495
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3496
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  3497
/* Action 0x0C */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3498
static void GRFComment(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3499
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3500
	/* <0C> [<ignored...>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3501
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3502
	 * 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
  3503
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3504
	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
  3505
6433
84cd6e4262fd (svn r8843) -Fix
tron
parents: 6429
diff changeset
  3506
	int text_len = len - 1;
84cd6e4262fd (svn r8843) -Fix
tron
parents: 6429
diff changeset
  3507
	const char *text = (const char*)(buf + 1);
84cd6e4262fd (svn r8843) -Fix
tron
parents: 6429
diff changeset
  3508
	grfmsg(2, "GRFComment: %.*s", text_len, text);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3509
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3510
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
  3511
/* Action 0x0D (GLS_SAFETYSCAN) */
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
  3512
static void SafeParamSet(byte *buf, int len)
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
  3513
{
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
  3514
	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
  3515
	buf++;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3516
	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
  3517
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
  3518
	/* 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
  3519
	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
  3520
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
  3521
	/* 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
  3522
	 * 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
  3523
	 * 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
  3524
	 * 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
  3525
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
  3526
	SETBIT(_cur_grfconfig->flags, GCF_UNSAFE);
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
  3527
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
  3528
	/* 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
  3529
	_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
  3530
}
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
  3531
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3532
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3533
static uint32 GetPatchVariable(uint8 param)
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3534
{
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3535
	switch (param) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3536
		/* start year - 1920 */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3537
		case 0x0B: return max(_patches.starting_year, ORIGINAL_BASE_YEAR) - ORIGINAL_BASE_YEAR;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3538
		/* freight trains weight factor */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3539
		case 0x0E: return _patches.freight_trains;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3540
		/* empty wagon speed increase */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3541
		case 0x0F: return 0;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3542
		/* plane speed factor */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3543
		case 0x10: return 4;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3544
		/* 2CC colormap base sprite */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3545
		case 0x11: return SPR_2CCMAP_BASE;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3546
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3547
		default:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3548
			grfmsg(2, "ParamSet: Unknown Patch variable 0x%02X.", param);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3549
			return 0;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3550
	}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3551
}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3552
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3553
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3554
static uint32 PerformGRM(uint32 *grm, uint16 num_ids, uint16 count, uint8 op, uint8 target, const char *type)
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3555
{
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3556
	uint start = 0;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3557
	uint size  = 0;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3558
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3559
	if (op == 6) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3560
		/* Return GRFID of set that reserved ID */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3561
		return grm[_cur_grffile->param[target]];
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3562
	}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3563
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3564
	/* With an operation of 2 or 3, we want to reserve a specific block of IDs */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3565
	if (op == 2 || op == 3) start = _cur_grffile->param[target];
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3566
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3567
	for (uint i = start; i < num_ids; i++) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3568
		if (grm[i] == 0) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3569
			size++;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3570
		} else {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3571
			if (op == 2 || op == 3) break;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3572
			start = i + 1;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3573
			size = 0;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3574
		}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3575
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3576
		if (size == count) break;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3577
	}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3578
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3579
	if (size == count) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3580
		/* Got the slot... */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3581
		if (op == 0 || op == 3) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3582
			grfmsg(2, "ParamSet: GRM: Reserving %d %s at %d", count, type, start);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3583
			for (uint i = 0; i < count; i++) grm[start + i] = _cur_grffile->grfid;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3584
		}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3585
		return start;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3586
	}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3587
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3588
	/* Unable to allocate */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3589
	if (op != 4 && op != 5) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3590
		/* Deactivate GRF */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3591
		grfmsg(0, "ParamSet: GRM: Unable to allocate %d %s, deactivating", count, type);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3592
		_cur_grfconfig->status = GCS_DISABLED;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3593
		_skip_sprites = -1;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3594
		return UINT_MAX;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3595
	}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3596
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3597
	grfmsg(1, "ParamSet: GRM: Unable to allocate %d %s", count, type);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3598
	return UINT_MAX;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3599
}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3600
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3601
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3602
/* Action 0x0D */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3603
static void ParamSet(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3604
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3605
	/* <0D> <target> <operation> <source1> <source2> [<data>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3606
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3607
	 * B target        parameter number where result is stored
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3608
	 * B operation     operation to perform, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3609
	 * B source1       first source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3610
	 * B source2       second source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3611
	 * 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
  3612
	 *                 if both source1 and source2 refer to actual parameters
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3613
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3614
	 * Operations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3615
	 * 00      Set parameter equal to source1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3616
	 * 01      Addition, source1 + source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3617
	 * 02      Subtraction, source1 - source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3618
	 * 03      Unsigned multiplication, source1 * source2 (both unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3619
	 * 04      Signed multiplication, source1 * source2 (both signed)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3620
	 * 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
  3621
	 *         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
  3622
	 *         negative, source1 is unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3623
	 * 06      Signed bit shift, source1 by source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3624
	 *         (source2 like in 05, and source1 as well)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3625
	 */
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
  3626
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
  3627
	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
  3628
	buf++;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3629
	uint8 target = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3630
	uint8 oper   = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3631
	uint32 src1  = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3632
	uint32 src2  = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3633
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3634
	uint32 data = 0;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3635
	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
  3636
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
  3637
	/* 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
  3638
	 * 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
  3639
	 * 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
  3640
	 * - 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
  3641
	 * - 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
  3642
	 *   an earlier action D */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3643
	if (HASBIT(oper, 7)) {
3807
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  3644
		if (target < 0x80 && target < _cur_grffile->param_end) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  3645
			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
  3646
			return;
3807
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  3647
		}
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  3648
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3649
		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
  3650
	}
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
  3651
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
  3652
	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
  3653
		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
  3654
			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
  3655
				/* Patch variables */
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3656
				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
  3657
			} 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
  3658
				/* GRF Resource Management */
5225
52ddcedcc6f7 (svn r7345) -Codechange: enumification of NewGRF loading stage, and move enum definition to header for future use.
peter1138
parents: 5211
diff changeset
  3659
				if (_cur_stage != GLS_ACTIVATION) {
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3660
					/* Ignore GRM during initialization */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3661
					src1 = 0;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3662
				} else {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3663
					uint8  op      = src1;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3664
					uint8  feature = GB(data, 8, 8);
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3665
					uint16 count   = GB(data, 16, 16);
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3666
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3667
					switch (feature) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3668
						case 0x00: // Trains
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3669
						case 0x01: // Road Vehicles
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3670
						case 0x02: // Ships
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3671
						case 0x03: // Aircraft
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3672
							src1 = PerformGRM(&_grm_engines[_vehshifts[feature]], _vehcounts[feature], count, op, target, "vehicles");
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3673
							if (_skip_sprites == -1) return;
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3674
							break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3675
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3676
						case 0x08: // General sprites
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3677
							switch (op) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3678
								case 0:
6140
22c9279c3bbd (svn r8505) -Codechange: Ensure GRM allocated sprites will be below the original 16384 sprite limit. If not, fail and disable the NewGRF.
peter1138
parents: 6126
diff changeset
  3679
									/* Check if the allocated sprites will fit below the original sprite limit */
22c9279c3bbd (svn r8505) -Codechange: Ensure GRM allocated sprites will be below the original 16384 sprite limit. If not, fail and disable the NewGRF.
peter1138
parents: 6126
diff changeset
  3680
									if (_cur_spriteid + count >= 16384) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  3681
										grfmsg(0, "ParamSet: GRM: Unable to allocate %d sprites; try changing NewGRF order", count);
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3682
										_cur_grfconfig->status = GCS_DISABLED;
6140
22c9279c3bbd (svn r8505) -Codechange: Ensure GRM allocated sprites will be below the original 16384 sprite limit. If not, fail and disable the NewGRF.
peter1138
parents: 6126
diff changeset
  3683
22c9279c3bbd (svn r8505) -Codechange: Ensure GRM allocated sprites will be below the original 16384 sprite limit. If not, fail and disable the NewGRF.
peter1138
parents: 6126
diff changeset
  3684
										_skip_sprites = -1;
22c9279c3bbd (svn r8505) -Codechange: Ensure GRM allocated sprites will be below the original 16384 sprite limit. If not, fail and disable the NewGRF.
peter1138
parents: 6126
diff changeset
  3685
										return;
22c9279c3bbd (svn r8505) -Codechange: Ensure GRM allocated sprites will be below the original 16384 sprite limit. If not, fail and disable the NewGRF.
peter1138
parents: 6126
diff changeset
  3686
									}
22c9279c3bbd (svn r8505) -Codechange: Ensure GRM allocated sprites will be below the original 16384 sprite limit. If not, fail and disable the NewGRF.
peter1138
parents: 6126
diff changeset
  3687
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3688
									/* 'Reserve' space at the current sprite ID */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3689
									src1 = _cur_spriteid;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3690
									_cur_spriteid += count;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3691
									break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3692
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3693
								case 1:
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3694
									src1 = _cur_spriteid;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3695
									break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3696
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3697
								default:
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  3698
									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
  3699
									return;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3700
							}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3701
							break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3702
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3703
						case 0x0B: // Cargo
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3704
							src1 = PerformGRM(_grm_cargos, NUM_CARGO, count, op, target, "cargos");
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3705
							if (_skip_sprites == -1) return;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3706
							break;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  3707
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  3708
						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
  3709
					}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3710
				}
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
  3711
			}
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
  3712
		} 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
  3713
			/* 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
  3714
			const GRFFile *file = GetFileByGRFID(data);
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  3715
			if (file == NULL || src1 >= file->param_end) {
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  3716
				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
  3717
			} 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
  3718
				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
  3719
			}
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
  3720
		}
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
  3721
	} 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
  3722
		/* 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
  3723
		 * 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
  3724
		 * 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
  3725
		 * 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
  3726
		 * of 0 is used instead.  */
3811
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3727
		src1 = (src1 == 0xFF) ? data : GetParamVal(src1, NULL);
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3728
		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
  3729
	}
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
  3730
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
  3731
	/* 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
  3732
	 * 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
  3733
	 * 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
  3734
	 * 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
  3735
	 * 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
  3736
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3737
	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
  3738
	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
  3739
		case 0x00:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3740
			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
  3741
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3742
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3743
		case 0x01:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3744
			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
  3745
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3746
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3747
		case 0x02:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3748
			res = src1 - src2;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3749
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3750
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
  3751
		case 0x03:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3752
			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
  3753
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3754
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
  3755
		case 0x04:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3756
			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
  3757
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3758
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
  3759
		case 0x05:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  3760
			if ((int32)src2 < 0) {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3761
				res = src1 >> -(int32)src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  3762
			} else {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3763
				res = src1 << src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  3764
			}
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
  3765
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3766
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
  3767
		case 0x06:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  3768
			if ((int32)src2 < 0) {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3769
				res = (int32)src1 >> -(int32)src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  3770
			} else {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3771
				res = (int32)src1 << src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  3772
			}
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
  3773
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3774
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3775
		case 0x07: // Bitwise AND
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3776
			res = src1 & src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3777
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3778
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3779
		case 0x08: // Bitwise OR
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3780
			res = src1 | src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3781
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3782
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3783
		case 0x09: // Unsigned division
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3784
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3785
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3786
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3787
				res = src1 / src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3788
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3789
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3790
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3791
		case 0x0A: // Signed divison
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3792
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3793
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3794
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3795
				res = (int32)src1 / (int32)src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3796
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3797
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3798
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3799
		case 0x0B: // Unsigned modulo
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3800
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3801
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3802
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3803
				res = src1 % src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3804
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3805
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3806
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3807
		case 0x0C: // Signed modulo
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3808
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3809
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3810
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3811
				res = (int32)src1 % (int32)src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3812
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3813
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  3814
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3815
		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
  3816
	}
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3817
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3818
	switch (target) {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3819
		case 0x8E: // Y-Offset for train sprites
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3820
			_traininfo_vehicle_pitch = res;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3821
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3822
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3823
		/* @todo implement */
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3824
		case 0x8F: // Rail track type cost factors
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3825
		case 0x93: // Tile refresh offset to left
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3826
		case 0x94: // Tile refresh offset to right
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3827
		case 0x95: // Tile refresh offset upwards
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3828
		case 0x96: // Tile refresh offset downwards
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3829
		case 0x97: // Snow line height
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3830
		case 0x99: // Global ID offset
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3831
			grfmsg(7, "ParamSet: Skipping unimplemented target 0x%02X", target);
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3832
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3833
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  3834
		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
  3835
			_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
  3836
			/* Set train list engine width */
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  3837
			_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
  3838
			break;
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  3839
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3840
		default:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3841
			if (target < 0x80) {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3842
				_cur_grffile->param[target] = res;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3843
				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
  3844
			} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3845
				grfmsg(7, "ParamSet: Skipping unknown target 0x%02X", target);
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3846
			}
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3847
			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
  3848
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3849
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3850
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
  3851
/* Action 0x0E (GLS_SAFETYSCAN) */
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
  3852
static void SafeGRFInhibit(byte *buf, int len)
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
  3853
{
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
  3854
	/* <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
  3855
	 *
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
  3856
	 * 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
  3857
	 * 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
  3858
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3859
	if (!check_length(len, 2, "GRFInhibit")) return;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3860
	buf++;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3861
	uint8 num = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3862
	if (!check_length(len, 2 + 4 * num, "GRFInhibit")) return;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3863
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3864
	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
  3865
		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
  3866
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
  3867
		/* 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
  3868
		if (grfid != _cur_grfconfig->grfid) {
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
  3869
			SETBIT(_cur_grfconfig->flags, GCF_UNSAFE);
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
  3870
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
  3871
			/* 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
  3872
			_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
  3873
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
  3874
			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
  3875
		}
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
  3876
	}
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
  3877
}
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
  3878
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  3879
/* Action 0x0E */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3880
static void GRFInhibit(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3881
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3882
	/* <0E> <num> <grfids...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3883
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3884
	 * B num           Number of GRFIDs that follow
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3885
	 * 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
  3886
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3887
	if (!check_length(len, 2, "GRFInhibit")) return;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3888
	buf++;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3889
	uint8 num = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3890
	if (!check_length(len, 2 + 4 * num, "GRFInhibit")) return;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3891
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3892
	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
  3893
		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
  3894
		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
  3895
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
  3896
		/* 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
  3897
		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
  3898
			grfmsg(2, "GRFInhibit: Deactivating file '%s'", file->filename);
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3899
			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
  3900
		}
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
  3901
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3902
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3903
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  3904
/* Action 0x10 */
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3905
static void DefineGotoLabel(byte *buf, int len)
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3906
{
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3907
	/* <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
  3908
	 *
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3909
	 * 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
  3910
	 * 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
  3911
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
  3912
	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
  3913
	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
  3914
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3915
	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
  3916
	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
  3917
	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
  3918
	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
  3919
	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
  3920
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3921
	/* 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
  3922
	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
  3923
		_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
  3924
	} 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
  3925
		/* 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
  3926
		GRFLabel *l;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3927
		for (l = _cur_grffile->label; l->next != NULL; l = l->next);
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3928
		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
  3929
	}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3930
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3931
	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
  3932
}
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
  3933
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3934
/* Action 0x11 */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3935
static void GRFSound(byte *buf, int len)
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3936
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3937
	/* <11> <num>
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3938
	 *
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3939
	 * 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
  3940
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
  3941
	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
  3942
	buf++;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  3943
	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
  3944
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3945
	_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
  3946
	_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
  3947
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3948
	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
  3949
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3950
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3951
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
  3952
{
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3953
	const GRFFile *file;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3954
	FileEntry *se = AllocateFileEntry();
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3955
	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
  3956
	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
  3957
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3958
	file = GetFileByGRFID(grfid);
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3959
	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
  3960
		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
  3961
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3962
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3963
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3964
	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
  3965
		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
  3966
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3967
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3968
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3969
	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
  3970
5024
f13f2f2d43f9 (svn r7065) Use simple assignment instead of memcpy()
tron
parents: 5011
diff changeset
  3971
	*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
  3972
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3973
	/* 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
  3974
	se->volume   = 128;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3975
	se->priority = 0;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3976
}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3977
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3978
/* 'Action 0xFE' */
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3979
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
  3980
{
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3981
	if (_grf_data_blocks == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3982
		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
  3983
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3984
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3985
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3986
	buf++;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3987
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3988
	_grf_data_blocks--;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3989
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3990
	/* 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
  3991
	 * 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
  3992
	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
  3993
		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
  3994
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3995
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3996
	switch (_grf_data_type) {
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3997
		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
  3998
		default: NOT_REACHED(); break;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3999
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4000
}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4001
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4002
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
  4003
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4004
	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
  4005
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4006
	/* 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
  4007
	 * so that the indices used elsewhere are still correct. */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4008
	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
  4009
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  4010
	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
  4011
		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
  4012
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4013
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4014
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4015
	/* 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
  4016
	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
  4017
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  4018
	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
  4019
		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
  4020
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4021
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4022
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4023
	for (;;) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4024
		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
  4025
		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
  4026
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4027
		switch (tag) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4028
			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
  4029
				/* 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
  4030
				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
  4031
					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
  4032
					return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4033
				}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4034
				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
  4035
				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
  4036
				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
  4037
				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
  4038
				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
  4039
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4040
				/* 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
  4041
				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
  4042
				break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4043
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4044
			case 'atad': // 'data'
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4045
				se->file_size    = size;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4046
				se->file_offset  = FioGetPos() - (len - (buf - buf_start)) + 1;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4047
				se->file_offset |= _file_index << 24;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4048
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4049
				/* 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
  4050
				se->volume = 0x80;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4051
				se->priority = 0;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4052
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4053
				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
  4054
				return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4055
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4056
			default:
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4057
				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
  4058
				return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4059
		}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4060
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4061
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4062
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
  4063
/* Action 0x12 */
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  4064
static void LoadFontGlyph(byte *buf, int len)
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  4065
{
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
  4066
	/* <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
  4067
	 *
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
  4068
	 * 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
  4069
	 * 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
  4070
	 * 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
  4071
	 * 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
  4072
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
  4073
	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
  4074
	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
  4075
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4076
	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
  4077
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
  4078
	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
  4079
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4080
	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
  4081
		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
  4082
		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
  4083
		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
  4084
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4085
		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
  4086
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4087
		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
  4088
			SetUnicodeGlyph(size, base_char + c, _cur_spriteid);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  4089
			LoadNextSprite(_cur_spriteid++, _file_index);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  4090
			_nfo_line++;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  4091
		}
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
  4092
	}
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
  4093
}
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
  4094
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4095
/* Action 0x13 */
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4096
static void TranslateGRFStrings(byte *buf, int len)
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4097
{
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4098
	/* <13> <grfid> <num-ent> <offset> <text...>
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4099
	 *
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4100
	 * 4*B grfid     The GRFID of the file whose texts are to be translated
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4101
	 * B   num-ent   Number of strings
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4102
	 * W   offset    First text ID
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4103
	 * S   text...   Zero-terminated strings */
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4104
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4105
	buf++; len--;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4106
	if (!check_length(len, 7, "TranslateGRFString")) return;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4107
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4108
	uint32 grfid = grf_load_dword(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4109
	const GRFConfig *c = GetGRFConfig(grfid);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4110
	if (c == NULL || (c->status != GCS_INITIALISED && c->status != GCS_ACTIVATED)) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  4111
		grfmsg(7, "TranslateGRFStrings: GRFID 0x%08x unknown, skipping action 13", BSWAP32(grfid));
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4112
		return;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4113
	}
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4114
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4115
	if (c->status == GCS_INITIALISED) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4116
		/* If the file is not active but will be activated later, give an error
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4117
		 * and disable this file. */
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4118
		GRFError *error = CallocT<GRFError>(1);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4119
		error->message  = STR_NEWGRF_ERROR_LOAD_AFTER;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4120
		error->data     = STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4121
		error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4122
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4123
		if (_cur_grfconfig->error != NULL) free(_cur_grfconfig->error);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4124
		_cur_grfconfig->error = error;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4125
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4126
		_cur_grfconfig->status = GCS_DISABLED;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4127
		_skip_sprites = -1;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4128
		return;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4129
	}
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4130
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4131
	byte num_strings = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4132
	uint16 first_id  = grf_load_word(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4133
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4134
	if (!((first_id >= 0xD000 && first_id + num_strings <= 0xD3FF) || (first_id >= 0xDC00 && first_id + num_strings <= 0xDCFF))) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  4135
		grfmsg(7, "TranslateGRFStrings: Attempting to set out-of-range string IDs in action 13 (first: 0x%4X, number: 0x%2X)", first_id, num_strings);
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4136
		return;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4137
	}
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4138
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4139
	len -= 7;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4140
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4141
	for (uint i = 0; i < num_strings && len > 0; i++) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4142
		const char *string   = grf_load_string(&buf, len);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4143
		size_t string_length = strlen(string) + 1;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4144
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4145
		len -= (int)string_length;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4146
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4147
		if (string_length == 1) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4148
			grfmsg(7, "TranslateGRFString: Ignoring empty string.");
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4149
			continue;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4150
		}
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4151
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4152
		/* Since no language id is supplied this string has to be added as a
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4153
		 * generic string, thus the language id of 0x7F. For this to work
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4154
		 * new_scheme has to be true as well. A language id of 0x7F will be
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4155
		 * overridden by a non-generic id, so this will not change anything if
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4156
		 * a string has been provided specifically for this language. */
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4157
		AddGRFString(grfid, first_id + i, 0x7F, true, string, STR_UNDEFINED);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4158
	}
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4159
}
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4160
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4161
/* 'Action 0xFF' */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4162
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
  4163
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4164
	if (_grf_data_blocks == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4165
		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
  4166
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4167
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4168
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4169
	buf++;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4170
	uint8 name_len = grf_load_byte(&buf);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4171
	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
  4172
	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
  4173
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4174
	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
  4175
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4176
	_grf_data_blocks--;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4177
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4178
	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
  4179
		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
  4180
		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
  4181
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4182
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4183
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
  4184
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
  4185
/* Used during safety scan on unsafe actions */
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  4186
static void GRFUnsafe(byte *buf, int len)
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  4187
{
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
  4188
	SETBIT(_cur_grfconfig->flags, GCF_UNSAFE);
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  4189
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
  4190
	/* 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
  4191
	_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
  4192
}
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
  4193
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
  4194
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4195
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
  4196
{
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4197
	_ttdpatch_flags[0] =  ((_patches.always_small_airport ? 1 : 0) << 0x0C)  // keepsmallairport
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4198
	                   |                                        (1 << 0x0D)  // newairports
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4199
	                   |                                        (1 << 0x0E)  // largestations
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4200
	                   |           ((_patches.longbridges ? 1 : 0) << 0x0F)  // longbridges
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4201
	                   |                                        (0 << 0x10)  // loadtime
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4202
	                   |                                        (1 << 0x12)  // presignals
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4203
	                   |                                        (1 << 0x13)  // extpresignals
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4204
	                   | ((_patches.never_expire_vehicles ? 1 : 0) << 0x16)  // enginespersist
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4205
	                   |                                        (1 << 0x1B)  // multihead
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4206
	                   |                                        (1 << 0x1D)  // lowmemory
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4207
	                   |                                        (1 << 0x1E); // generalfixes
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4208
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4209
	_ttdpatch_flags[1] =                                        (0 << 0x07)  // moreairports - based on units of noise
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4210
	                   |        ((_patches.mammoth_trains ? 1 : 0) << 0x08)  // mammothtrains
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4211
	                   |                                        (1 << 0x09)  // trainrefit
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4212
	                   |                                        (0 << 0x0B)  // subsidiaries
5801
7d14e62bc9f3 (svn r7930) -Fix: [FS#520] Wrong GRF flag set for gradual loading (mart3p)
Darkvater
parents: 5776
diff changeset
  4213
	                   |       ((_patches.gradual_loading ? 1 : 0) << 0x0C)  // gradualloading
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4214
	                   |                                        (1 << 0x12)  // unifiedmaglevmode - set bit 0 mode. Not revelant to OTTD
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4215
	                   |                                        (1 << 0x13)  // unifiedmaglevmode - set bit 1 mode
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4216
	                   |                                        (1 << 0x14)  // bridgespeedlimits
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4217
	                   |                                        (1 << 0x16)  // eternalgame
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4218
	                   |                                        (1 << 0x17)  // newtrains
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4219
	                   |                                        (1 << 0x18)  // newrvs
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4220
	                   |                                        (1 << 0x19)  // newships
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4221
	                   |                                        (1 << 0x1A)  // newplanes
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4222
	                   |           ((_patches.signal_side ? 1 : 0) << 0x1B)  // signalsontrafficside
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4223
	                   |                                        (1 << 0x1C); // electrifiedrailway
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4224
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4225
	_ttdpatch_flags[2] =                                        (1 << 0x01)  // loadallgraphics - obsolote
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4226
	                   |                                        (1 << 0x03)  // semaphores
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4227
	                   |                                        (0 << 0x0B)  // enhancedgui
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4228
	                   |                                        (0 << 0x0C)  // newagerating
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4229
	                   |       ((_patches.build_on_slopes ? 1 : 0) << 0x0D)  // buildonslopes
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  4230
	                   |         ((_patches.full_load_any ? 1 : 0) << 0x0E)  // fullloadany
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4231
	                   |                                        (0 << 0x0F)  // planespeed
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4232
	                   |                                        (0 << 0x10)  // moreindustriesperclimate - obsolete
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4233
	                   |                                        (0 << 0x11)  // moretoylandfeatures
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4234
	                   |                                        (1 << 0x12)  // newstations
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4235
	                   |                                        (0 << 0x13)  // tracktypecostdiff
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  4236
	                   |                                        (1 << 0x14)  // manualconvert
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4237
	                   |       ((_patches.build_on_slopes ? 1 : 0) << 0x15)  // buildoncoasts
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4238
	                   |                                        (1 << 0x16)  // canals
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4239
	                   |                                        (1 << 0x17)  // newstartyear
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  4240
	                   |    ((_patches.freight_trains > 1 ? 1 : 0) << 0x18)  // freighttrains
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4241
	                   |                                        (1 << 0x19)  // newhouses
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4242
	                   |                                        (1 << 0x1A)  // newbridges
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4243
	                   |                                        (0 << 0x1B)  // newtownnames
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4244
	                   |                                        (0 << 0x1C)  // moreanimations
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4245
	                   |    ((_patches.wagon_speed_limits ? 1 : 0) << 0x1D)  // wagonspeedlimits
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4246
	                   |                                        (1 << 0x1E)  // newshistory
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4247
	                   |                                        (0 << 0x1F); // custombridgeheads
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4248
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4249
	_ttdpatch_flags[3] =                                        (0 << 0x00)  // newcargodistribution
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4250
	                   |                                        (1 << 0x01)  // windowsnap
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4251
	                   |                                        (0 << 0x02)  // townbuildnoroad
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4252
	                   |                                        (0 << 0x03)  // pathbasedsignalling. To enable if ever pbs is back
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4253
	                   |                                        (0 << 0x04)  // aichoosechance
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4254
	                   |                                        (1 << 0x05)  // resolutionwidth
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4255
	                   |                                        (1 << 0x06)  // resolutionheight
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4256
	                   |                                        (0 << 0x07)  // newindustries
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4257
	                   |         ((_patches.improved_load ? 1 : 0) << 0x08)  // fifoloading
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4258
	                   |                                        (0 << 0x09)  // townroadbranchprob
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4259
	                   |                                        (0 << 0x0A)  // tempsnowline
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  4260
	                   |                                        (1 << 0x0B)  // newcargo
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4261
	                   |                                        (1 << 0x0C)  // enhancemultiplayer
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4262
	                   |                                        (1 << 0x0D)  // onewayroads
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4263
	                   |   ((_patches.nonuniform_stations ? 1 : 0) << 0x0E)  // irregularstations
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4264
	                   |                                        (1 << 0x0F)  // statistics
4657
188335e8d316 (svn r6533) - Fix (r6532): Somebody forgot to add newsounds to the ttdpatch flags...
peter1138
parents: 4656
diff changeset
  4265
	                   |                                        (1 << 0x10)  // newsounds
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4266
	                   |                                        (1 << 0x11)  // autoreplace
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4267
	                   |                                        (1 << 0x12)  // autoslope
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4268
	                   |                                        (0 << 0x13)  // followvehicle
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4269
	                   |                                        (1 << 0x14)  // trams
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4270
	                   |                                        (0 << 0x15)  // enhancetunnels
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4271
	                   |                                        (1 << 0x16)  // shortrvs
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4272
	                   |                                        (1 << 0x17)  // articulatedrvs
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  4273
	                   |                                        (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
  4274
}
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
  4275
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4276
static void ResetCustomStations()
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  4277
{
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4278
	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
  4279
		if (file->stations == NULL) continue;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4280
		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
  4281
			if (file->stations[i] == NULL) continue;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4282
			StationSpec *statspec = file->stations[i];
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  4283
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  4284
			/* 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
  4285
			if (!statspec->copied_renderdata) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4286
				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
  4287
					free((void*)statspec->renderdata[t].seq);
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  4288
				}
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  4289
				free(statspec->renderdata);
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  4290
			}
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  4291
5061
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  4292
			/* Release platforms and layouts */
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  4293
			if (!statspec->copied_layouts) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4294
				for (uint l = 0; l < statspec->lengths; l++) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4295
					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
  4296
						free(statspec->layouts[l][p]);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  4297
					}
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  4298
					free(statspec->layouts[l]);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  4299
				}
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  4300
				free(statspec->layouts);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  4301
				free(statspec->platforms);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  4302
			}
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
  4303
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
  4304
			/* 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
  4305
			free(statspec);
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  4306
		}
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
  4307
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
  4308
		/* 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
  4309
		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
  4310
		file->stations = NULL;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  4311
	}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  4312
}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  4313
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4314
static void ResetCustomHouses()
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4315
{
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4316
	GRFFile *file;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4317
	uint i;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4318
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4319
	for (file = _first_grffile; file != NULL; file = file->next) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4320
		if (file->housespec == NULL) continue;
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4321
		for (i = 0; i < HOUSE_MAX; i++) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4322
			free(file->housespec[i]);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4323
		}
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4324
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4325
		free(file->housespec);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4326
		file->housespec = NULL;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4327
	}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4328
}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4329
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4330
static void ResetCustomIndustries()
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4331
{
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4332
	GRFFile *file;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4333
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4334
	for (file = _first_grffile; file != NULL; file = file->next) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4335
		uint i;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4336
		/* We are verifiying both tiles and industries specs loaded from the grf file
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4337
		 * First, let's deal with industryspec */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4338
		if (file->industryspec != NULL) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4339
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4340
			for (i = 0; i < NUM_INDUSTRYTYPES; i++) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4341
				IndustrySpec *ind = file->industryspec[i];
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4342
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4343
				if (ind != NULL) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4344
					/* We need to remove the sounds array */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4345
					if (HASBIT(ind->cleanup_flag, CLEAN_RANDOMSOUNDS)) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4346
						free((void*)ind->random_sounds);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4347
					}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4348
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4349
					/* We need to remove the tiles layouts */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4350
					if (HASBIT(ind->cleanup_flag, CLEAN_TILELSAYOUT) && ind->table != NULL) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4351
						for (int j = 0; j < ind->num_table; j++) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4352
							/* remove the individual layouts */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4353
							if (ind->table[j] != NULL) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4354
								free((IndustryTileTable*)ind->table[j]);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4355
							}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4356
						}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4357
						/* remove the layouts pointers */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4358
						free((IndustryTileTable**)ind->table);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4359
						ind->table = NULL;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4360
					}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4361
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4362
					free(ind);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4363
					ind = NULL;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4364
				}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4365
			}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4366
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4367
			free(file->industryspec);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4368
			file->industryspec = NULL;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4369
		}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4370
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4371
		if (file->indtspec != NULL) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4372
			for (i = 0; i < NUM_INDUSTRYTILES; i++) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4373
				if (file->indtspec[i] != NULL) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4374
					free(file->indtspec[i]);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4375
					file->indtspec[i] = NULL;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4376
				}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4377
			}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4378
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4379
			free(file->indtspec);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4380
			file->indtspec = NULL;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4381
		}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4382
	}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4383
}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4384
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4385
static void ResetNewGRF()
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  4386
{
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4387
	GRFFile *next;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4388
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4389
	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
  4390
		next = f->next;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  4391
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  4392
		free(f->filename);
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4393
		free(f->cargo_list);
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  4394
		free(f);
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  4395
	}
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  4396
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  4397
	_first_grffile = NULL;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  4398
	_cur_grffile   = NULL;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  4399
}
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  4400
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  4401
/**
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
  4402
 * 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
  4403
 * 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
  4404
 */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4405
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
  4406
{
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  4407
	CleanUpStrings();
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  4408
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4409
	/* Copy/reset original engine info data */
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
  4410
	memcpy(&_engine_info, &orig_engine_info, sizeof(orig_engine_info));
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  4411
	memcpy(&_rail_vehicle_info, &orig_rail_vehicle_info, sizeof(orig_rail_vehicle_info));
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  4412
	memcpy(&_ship_vehicle_info, &orig_ship_vehicle_info, sizeof(orig_ship_vehicle_info));
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  4413
	memcpy(&_aircraft_vehicle_info, &orig_aircraft_vehicle_info, sizeof(orig_aircraft_vehicle_info));
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  4414
	memcpy(&_road_vehicle_info, &orig_road_vehicle_info, sizeof(orig_road_vehicle_info));
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  4415
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4416
	/* Copy/reset original bridge info data
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4417
	 * First, free sprite table data */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4418
	for (uint i = 0; i < MAX_BRIDGES; i++) {
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  4419
		if (_bridge[i].sprite_table != NULL) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4420
			for (uint j = 0; j < 7; j++) free(_bridge[i].sprite_table[j]);
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  4421
			free(_bridge[i].sprite_table);
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  4422
		}
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
  4423
	}
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
  4424
	memcpy(&_bridge, &orig_bridge, sizeof(_bridge));
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  4425
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4426
	/* Reset refit/cargo class data */
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  4427
	memset(&cargo_allowed, 0, sizeof(cargo_allowed));
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  4428
	memset(&cargo_disallowed, 0, sizeof(cargo_disallowed));
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  4429
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4430
	/* Reset GRM reservations */
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4431
	memset(&_grm_engines, 0, sizeof(_grm_engines));
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4432
	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
  4433
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4434
	/* Unload sprite group data */
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  4435
	UnloadWagonOverrides();
3695
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  4436
	UnloadRotorOverrideSprites();
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  4437
	UnloadCustomEngineSprites();
2769
acea0abd2195 (svn r3316) - NewGRF: Unload engine names before loading grf files. This fixes names in climates where the engines don't get loaded. Renamed function to reflect its purpose.
peter1138
parents: 2766
diff changeset
  4438
	UnloadCustomEngineNames();
2971
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
  4439
	ResetEngineListOrder();
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  4440
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4441
	/* Reset price base data */
9903
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9896
diff changeset
  4442
	// ResetPriceBaseMultipliers();
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  4443
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  4444
	/* Reset the curencies array */
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  4445
	ResetCurrencies();
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  4446
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4447
	/* Reset the house array */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4448
	ResetCustomHouses();
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4449
	ResetHouses();
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4450
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4451
	/* Reset the industries structures*/
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4452
	ResetCustomIndustries();
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4453
	ResetIndustries();
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4454
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4455
	/* Reset station classes */
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  4456
	ResetStationClasses();
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  4457
	ResetCustomStations();
2812
f250489941f9 (svn r3360) Fix initialization of engines for precalculation of default refit mask.
peter1138
parents: 2769
diff changeset
  4458
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4459
	/* Reset canal sprite groups */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4460
	memset(_canal_sg, 0, sizeof(_canal_sg));
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4461
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4462
	/* Reset the snowline table. */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4463
	ClearSnowLine();
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4464
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  4465
	/* Reset NewGRF files */
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  4466
	ResetNewGRF();
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  4467
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4468
	/* Add engine type to engine data. This is needed for the refit precalculation. */
2812
f250489941f9 (svn r3360) Fix initialization of engines for precalculation of default refit mask.
peter1138
parents: 2769
diff changeset
  4469
	AddTypeToEngines();
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  4470
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
  4471
	/* Set up the default cargo types */
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
  4472
	SetupCargoForClimate(_opt.landscape);
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
  4473
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
  4474
	/* 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
  4475
	_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
  4476
	_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
  4477
	_traininfo_vehicle_width = 29;
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4478
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4479
	_loaded_newgrf_features = 0;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4480
5209
fa3ad39e2fa7 (svn r7324) -Codechange: reset newgrf signal location data
peter1138
parents: 5161
diff changeset
  4481
	_signal_base = 0;
5210
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  4482
	_coast_base = 0;
3845
c3cd4b825c2f (svn r4869) - NewGRF: support setting train list vehicle width to 32 instead of 29 pixels, for sets which use 32 pixel long engines/wagons.
peter1138
parents: 3825
diff changeset
  4483
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4484
	InitializeSoundPool();
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  4485
	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
  4486
}
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
  4487
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
  4488
/** Reset all NewGRFData that was used only while processing data */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4489
static void ClearTemporaryNewGRFData()
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  4490
{
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  4491
	/* Clear the GOTO labels used for GRF processing */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4492
	for (GRFLabel *l = _cur_grffile->label; l != NULL;) {
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  4493
		GRFLabel *l2 = l->next;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  4494
		free(l);
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  4495
		l = l2;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  4496
	}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  4497
	_cur_grffile->label = NULL;
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  4498
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  4499
	/* Clear the list of spritegroups */
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  4500
	free(_cur_grffile->spritegroups);
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  4501
	_cur_grffile->spritegroups = NULL;
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  4502
	_cur_grffile->spritegroups_count = 0;
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  4503
}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  4504
6473
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4505
static void BuildCargoTranslationMap()
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4506
{
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4507
	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
  4508
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4509
	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
  4510
		const CargoSpec *cs = GetCargo(c);
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4511
		if (!cs->IsValid()) continue;
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4512
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4513
		if (_cur_grffile->cargo_max == 0) {
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4514
			/* 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
  4515
			_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
  4516
		} else {
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4517
			/* 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
  4518
			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
  4519
				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
  4520
					_cur_grffile->cargo_map[c] = i;
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4521
					break;
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4522
				}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4523
			}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4524
		}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4525
	}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4526
}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4527
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
  4528
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
  4529
{
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4530
	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
  4531
	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
  4532
		/* 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
  4533
		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
  4534
		_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
  4535
		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
  4536
	}
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
  4537
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
  4538
	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
  4539
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  4540
	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
  4541
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9907
diff changeset
  4542
	newfile->filename = strdup(config->full_path);
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
  4543
	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
  4544
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
  4545
	/* 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
  4546
	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
  4547
	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
  4548
	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
  4549
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
  4550
	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
  4551
		_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
  4552
		_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
  4553
	} 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
  4554
		_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
  4555
		_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
  4556
	}
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
  4557
}
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
  4558
5037
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  4559
6471
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4560
/** 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
  4561
 * 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
  4562
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
  4563
	'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
  4564
	'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
  4565
	'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
  4566
	'PLST', 'FZDR',
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4567
	0 };
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4568
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4569
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
  4570
	0 };
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4571
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4572
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
  4573
	'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
  4574
	'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
  4575
	'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
  4576
	'PLST', 'FZDR',
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4577
	0 };
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4578
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4579
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
  4580
	'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
  4581
	'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
  4582
	0 };
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4583
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4584
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
  4585
	_default_refitmasks_rail,
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4586
	_default_refitmasks_road,
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4587
	_default_refitmasks_ships,
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4588
	_default_refitmasks_aircraft,
5037
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  4589
};
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  4590
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  4591
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  4592
/**
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  4593
 * 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
  4594
 */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4595
static void CalculateRefitMasks()
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  4596
{
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4597
	for (EngineID engine = 0; engine < TOTAL_NUM_ENGINES; engine++) {
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  4598
		uint32 mask = 0;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  4599
		uint32 not_mask = 0;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4600
		uint32 xor_mask = 0;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4601
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4602
		if (_engine_info[engine].refit_mask != 0) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4603
			const GRFFile *file = GetEngineGRF(engine);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4604
			if (file != NULL && file->cargo_max != 0) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4605
				/* Apply cargo translation table to the refit mask */
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4606
				uint num_cargo = min(32, file->cargo_max);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4607
				for (uint i = 0; i < num_cargo; i++) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4608
					if (!HASBIT(_engine_info[engine].refit_mask, i)) continue;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4609
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4610
					CargoID c = GetCargoIDByLabel(file->cargo_list[i]);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4611
					if (c == CT_INVALID) continue;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4612
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4613
					SETBIT(xor_mask, c);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4614
				}
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4615
			} else {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4616
				/* No cargo table, so use the cargo bitnum values */
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4617
				for (CargoID c = 0; c < NUM_CARGO; c++) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4618
					const CargoSpec *cs = GetCargo(c);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4619
					if (!cs->IsValid()) continue;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4620
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4621
					if (HASBIT(_engine_info[engine].refit_mask, cs->bitnum)) SETBIT(xor_mask, c);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4622
				}
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4623
			}
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4624
		}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  4625
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  4626
		if (cargo_allowed[engine] != 0) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4627
			/* Build up the list of cargo types from the set cargo classes. */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4628
			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
  4629
				const CargoSpec *cs = GetCargo(i);
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
  4630
				if (cargo_allowed[engine]    & cs->classes) SETBIT(mask,     i);
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
  4631
				if (cargo_disallowed[engine] & 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
  4632
			}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  4633
		} else {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4634
			/* Don't apply default refit mask to wagons or engines with no capacity */
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  4635
			if (xor_mask == 0 && (
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4636
						GetEngine(engine)->type != VEH_TRAIN || (
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  4637
							RailVehInfo(engine)->capacity != 0 &&
6119
b47985557d1e (svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents: 6106
diff changeset
  4638
							RailVehInfo(engine)->railveh_type != RAILVEH_WAGON
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  4639
						)
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  4640
					)) {
6471
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4641
				const CargoLabel *cl = _default_refitmasks[GetEngine(engine)->type];
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4642
				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
  4643
					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
  4644
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  4645
					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
  4646
					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
  4647
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
  4648
					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
  4649
				}
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  4650
			}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  4651
		}
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
  4652
		_engine_info[engine].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
  4653
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
  4654
		/* 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
  4655
		 * cargo type. Apparently cargo_type isn't a common property... */
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
  4656
		switch (GetEngine(engine)->type) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4657
			default: NOT_REACHED();
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4658
			case VEH_AIRCRAFT: break;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4659
			case VEH_TRAIN: {
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
  4660
				RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
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
  4661
				if (rvi->cargo_type == CT_INVALID) rvi->cargo_type = FindFirstRefittableCargo(engine);
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4662
				if (rvi->cargo_type == CT_INVALID) _engine_info[engine].climates = 0;
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
  4663
				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
  4664
			}
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4665
			case VEH_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
  4666
				RoadVehicleInfo *rvi = &_road_vehicle_info[engine - ROAD_ENGINES_INDEX];
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
  4667
				if (rvi->cargo_type == CT_INVALID) rvi->cargo_type = FindFirstRefittableCargo(engine);
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4668
				if (rvi->cargo_type == CT_INVALID) _engine_info[engine].climates = 0;
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
  4669
				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
  4670
			}
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4671
			case VEH_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
  4672
				ShipVehicleInfo *svi = &_ship_vehicle_info[engine - SHIP_ENGINES_INDEX];
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
  4673
				if (svi->cargo_type == CT_INVALID) svi->cargo_type = FindFirstRefittableCargo(engine);
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4674
				if (svi->cargo_type == CT_INVALID) _engine_info[engine].climates = 0;
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
  4675
				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
  4676
			}
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
  4677
		}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  4678
	}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  4679
}
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
  4680
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4681
/** Add all new houses to the house array. House properties can be set at any
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4682
 * time in the GRF file, so we can only add a house spec to the house array
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4683
 * after the file has finished loading. We also need to check the dates, due to
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4684
 * the TTDPatch behaviour described below that we need to emulate. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4685
static void FinaliseHouseArray()
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4686
{
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4687
	/* If there are no houses with start dates before 1930, then all houses
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4688
	 * with start dates of 1930 have them reset to 0. This is in order to be
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4689
	 * compatible with TTDPatch, where if no houses have start dates before
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4690
	 * 1930 and the date is before 1930, the game pretends that this is 1930.
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4691
	 * If there have been any houses defined with start dates before 1930 then
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4692
	 * the dates are left alone. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4693
	bool reset_dates = true;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4694
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4695
	for (GRFFile *file = _first_grffile; file != NULL; file = file->next) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4696
		if (file->housespec == NULL) continue;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4697
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4698
		for (int i = 0; i < HOUSE_MAX; i++) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4699
			HouseSpec *hs = file->housespec[i];
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4700
			if (hs != NULL) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4701
				_house_mngr.SetEntitySpec(hs);
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4702
				if (hs->min_date < 1930) reset_dates = false;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4703
			}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4704
		}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4705
	}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4706
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4707
	if (reset_dates) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4708
		for (int i = NEW_HOUSE_OFFSET; i < HOUSE_MAX; i++) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4709
			HouseSpec *hs = GetHouseSpecs(i);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4710
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4711
			if (hs->enabled && hs->min_date == 1930) hs->min_date = 0;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4712
		}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4713
	}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4714
}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4715
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4716
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4717
/** Each cargo string needs to be mapped from TTDPatch to OpenTTD string IDs.
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4718
 * This is done after loading so that strings from Action 4 will be mapped
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4719
 * properly. */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4720
static void MapNewCargoStrings()
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4721
{
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4722
	for (CargoID c = 0; c < NUM_CARGO; c++) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4723
		CargoSpec *cs = &_cargo[c];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4724
		/* Don't map if the cargo is unavailable or not from NewGRF */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4725
		if (!cs->IsValid() || cs->grfid == 0) continue;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4726
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4727
		cs->name         = MapGRFStringID(cs->grfid, cs->name);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4728
		cs->name_plural  = MapGRFStringID(cs->grfid, cs->name_plural);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4729
		cs->units_volume = MapGRFStringID(cs->grfid, cs->units_volume);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4730
		cs->quantifier   = MapGRFStringID(cs->grfid, cs->quantifier);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4731
		cs->abbrev       = MapGRFStringID(cs->grfid, cs->abbrev);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4732
	}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4733
}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4734
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4735
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4736
/* 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
  4737
 * 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
  4738
 * partial implementation yet). */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4739
/* 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
  4740
 * 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
  4741
 * 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
  4742
static void DecodeSpecialSprite(uint num, GrfLoadingStage stage)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4743
{
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  4744
	/* 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
  4745
	 * 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
  4746
	 * 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
  4747
	 * "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
  4748
	 * 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
  4749
	 * 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
  4750
	 * 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
  4751
	 * 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
  4752
	 * --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
  4753
	/* 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
  4754
	 * 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
  4755
	 * 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
  4756
	static const SpecialSpriteHandler handlers[][GLS_END] = {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4757
		/* 0x00 */ { NULL,     SafeChangeInfo, NULL,       InitChangeInfo, ReserveChangeInfo, FeatureChangeInfo, },
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4758
		/* 0x01 */ { SkipAct1, SkipAct1,  SkipAct1,        SkipAct1,       SkipAct1,          NewSpriteSet, },
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4759
		/* 0x02 */ { NULL,     NULL,      NULL,            NULL,           NULL,              NewSpriteGroup, },
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4760
		/* 0x03 */ { NULL,     GRFUnsafe, NULL,            NULL,           NULL,              FeatureMapSpriteGroup, },
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4761
		/* 0x04 */ { NULL,     NULL,      NULL,            NULL,           NULL,              FeatureNewName, },
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4762
		/* 0x05 */ { SkipAct5, SkipAct5,  SkipAct5,        SkipAct5,       SkipAct5,          GraphicsNew, },
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
  4763
		/* 0x06 */ { NULL,     NULL,      NULL,            CfgApply,       CfgApply,          CfgApply, },
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4764
		/* 0x07 */ { NULL,     NULL,      NULL,            NULL,           SkipIf,            SkipIf, },
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4765
		/* 0x08 */ { ScanInfo, NULL,      NULL,            GRFInfo,        GRFInfo,           GRFInfo, },
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4766
		/* 0x09 */ { NULL,     NULL,      NULL,            SkipIf,         SkipIf,            SkipIf, },
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4767
		/* 0x0A */ { SkipActA, SkipActA,  SkipActA,        SkipActA,       SkipActA,          SpriteReplace, },
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4768
		/* 0x0B */ { NULL,     NULL,      NULL,            GRFLoadError,   GRFLoadError,      GRFLoadError, },
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4769
		/* 0x0C */ { NULL,     NULL,      NULL,            GRFComment,     NULL,              GRFComment, },
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4770
		/* 0x0D */ { NULL,     SafeParamSet, NULL,         ParamSet,       ParamSet,          ParamSet, },
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4771
		/* 0x0E */ { NULL,     SafeGRFInhibit, NULL,       GRFInhibit,     GRFInhibit,        GRFInhibit, },
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4772
		/* 0x0F */ { NULL,     NULL,      NULL,            NULL,           NULL,              NULL, },
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4773
		/* 0x10 */ { NULL,     NULL,      DefineGotoLabel, NULL,           NULL,              NULL, },
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4774
		/* 0x11 */ { NULL,     GRFUnsafe, NULL,            NULL,           NULL,              GRFSound, },
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4775
		/* 0x12 */ { NULL,     NULL,      NULL,            NULL,           NULL,              LoadFontGlyph, },
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4776
		/* 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
  4777
	};
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  4778
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4779
	byte* buf;
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  4780
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4781
	if (_preload_sprite == NULL) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4782
		/* 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
  4783
		 * 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
  4784
		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
  4785
		if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory");
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4786
		FioReadBlock(buf, num);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4787
	} else {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4788
		/* 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
  4789
		buf = _preload_sprite;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4790
		_preload_sprite = NULL;
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4791
		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
  4792
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4793
		/* 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
  4794
		FioSeekTo(num, SEEK_CUR);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4795
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4796
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4797
	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
  4798
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4799
	if (action == 0xFF) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  4800
		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
  4801
		GRFDataBlock(buf, num);
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4802
	} else if (action == 0xFE) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  4803
		grfmsg(7, "DecodeSpecialSprite: andling 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
  4804
		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
  4805
	} else if (action >= lengthof(handlers)) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  4806
		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
  4807
	} else if (handlers[action][stage] == NULL) {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  4808
		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
  4809
	} else {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  4810
		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
  4811
		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
  4812
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4813
	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
  4814
}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4815
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4816
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  4817
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
  4818
{
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9907
diff changeset
  4819
	const char *filename = config->full_path;
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
  4820
	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
  4821
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4822
	/* 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
  4823
	 * 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
  4824
	 * 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
  4825
	 * 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
  4826
	 * 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
  4827
	 *
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4828
	 * 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
  4829
	 * 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
  4830
	 * 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
  4831
	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
  4832
		_cur_grffile = GetFileByFilename(filename);
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4833
		if (_cur_grffile == NULL) error("File '%s' lost in cache.\n", filename);
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4834
		if (stage == GLS_RESERVE && config->status != GCS_INITIALISED) return;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4835
		if (stage == GLS_ACTIVATION && config->status != GCS_INITIALISED) 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
  4836
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4837
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4838
	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
  4839
	_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
  4840
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  4841
	_cur_grfconfig = config;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  4842
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  4843
	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
  4844
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4845
	/* 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
  4846
	 * 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
  4847
	 * 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
  4848
	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
  4849
		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
  4850
	} else {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  4851
		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
  4852
		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
  4853
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4854
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4855
	_skip_sprites = 0; // XXX
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  4856
	_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
  4857
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4858
	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
  4859
		byte type = FioReadByte();
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  4860
		_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
  4861
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4862
		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
  4863
			if (_skip_sprites == 0) {
2958
3f8946daf55f (svn r3520) Remove unused parameters from some functions
tron
parents: 2935
diff changeset
  4864
				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
  4865
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
  4866
				/* 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
  4867
				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
  4868
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
  4869
				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
  4870
			} 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
  4871
				FioSkipBytes(num);
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  4872
			}
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  4873
		} else {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  4874
			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
  4875
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4876
			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
  4877
			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
  4878
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4879
			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
  4880
				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
  4881
			} 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
  4882
				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
  4883
					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
  4884
					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
  4885
						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
  4886
						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
  4887
					} 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
  4888
						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
  4889
						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
  4890
						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
  4891
					}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4892
				}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4893
			}
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  4894
		}
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
  4895
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4896
		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
  4897
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4898
}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4899
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4900
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
  4901
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4902
static void AfterLoadGRFs()
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4903
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4904
	/* Update the bitmasks for the vehicle lists */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4905
	Player *p;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4906
	FOR_ALL_PLAYERS(p) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4907
		p->avail_railtypes = GetPlayerRailtypes(p->index);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4908
		p->avail_roadtypes = GetPlayerRoadtypes(p->index);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4909
	}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4910
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4911
	/* Pre-calculate all refit masks after loading GRF files. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4912
	CalculateRefitMasks();
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4913
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4914
	/* Set the block size in the depot windows based on vehicle sprite sizes */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4915
	InitDepotWindowBlockSizes();
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4916
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4917
	/* Add all new houses to the house array. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4918
	FinaliseHouseArray();
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4919
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4920
	/* Create dynamic list of industry legends for smallmap_gui.cpp */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4921
	BuildIndustriesLegend();
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4922
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4923
	/* Map cargo strings. This is a separate step because cargos are
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4924
	 * loaded before strings... */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4925
	MapNewCargoStrings();
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4926
}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4927
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
  4928
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
  4929
{
2930
a3bfaa5a9222 (svn r3486) - NewGRF fix: Always reinitialize the ttdpatch flags as patch settings may have changed.
peter1138
parents: 2895
diff changeset
  4930
	InitializeGRFSpecial();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4931
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
  4932
	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
  4933
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
  4934
	/* 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
  4935
	 * 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
  4936
	 * and load information from it. */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4937
	for (GrfLoadingStage stage = GLS_LABELSCAN; stage <= GLS_ACTIVATION; stage++) {
2400
0b51bc385750 (svn r2926) -Fix: Use the same file slots in both initialisation stages when loading a patch grf
tron
parents: 2346
diff changeset
  4938
		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
  4939
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4940
		_cur_stage = stage;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4941
		_cur_spriteid = load_index;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4942
		for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  4943
			if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND) continue;
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  4944
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  4945
			/* @todo usererror() */
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4946
			if (!FioCheckFileExists(c->full_path)) error("NewGRF file is missing '%s'", c->filename);
3628
bd4a6601e5a2 (svn r4527) - Feature [NewGRF]: Add support for specifying parameters to GRF files. Usage: "mygrf = 1". You can pass up to 128 parameters, each one seperated by a comma or a space-character. Big thanks to peter1138 for the inspiration and examples.
Darkvater
parents: 3620
diff changeset
  4947
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
  4948
			if (stage == GLS_LABELSCAN) InitNewGRFFile(c, _cur_spriteid);
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  4949
			LoadNewGRFFile(c, slot++, stage);
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4950
			if (stage == GLS_RESERVE) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4951
				if (c->status == GCS_ACTIVATED) c->status = GCS_INITIALISED;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  4952
			} else if (stage == GLS_ACTIVATION) {
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
  4953
				ClearTemporaryNewGRFData();
6473
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  4954
				BuildCargoTranslationMap();
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  4955
				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
  4956
			}
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
  4957
		}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4958
	}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  4959
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4960
	/* Call any functions that should be run after GRFs have been loaded. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  4961
	AfterLoadGRFs();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4962
}
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4963
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4964
bool HasGrfMiscBit(GrfMiscBit bit)
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4965
{
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4966
	return HASBIT(_misc_grf_features, bit);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  4967
}