src/newgrf.cpp
author rubidium
Wed, 09 Jan 2008 18:11:12 +0000
branchnoai
changeset 9723 eee46cb39750
parent 9722 ebf0ece7d8f6
child 9724 b39bc69bb2f2
permissions -rw-r--r--
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
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
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
     3
/** @file newgrf.cpp */
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include <stdarg.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1883
diff changeset
     9
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1183
diff changeset
    10
#include "debug.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "fileio.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "engine.h"
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
    13
#include "spritecache.h"
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    14
#include "station.h"
405
6830ae7a0d5d (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents: 404
diff changeset
    15
#include "sprite.h"
452
520e4ed6945d (svn r662) [newgrf] Moved grfspecial.c to newgrf.c/newgrf.h
dominik
parents: 449
diff changeset
    16
#include "newgrf.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2013
diff changeset
    17
#include "variables.h"
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
    18
#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
    19
#include "bridge.h"
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
    20
#include "town.h"
2962
dbd168a4703a (svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents: 2958
diff changeset
    21
#include "newgrf_engine.h"
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
    22
#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
    23
#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
    24
#include "fontcache.h"
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
    25
#include "currency.h"
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
    26
#include "landscape.h"
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
    27
#include "newgrf_config.h"
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
    28
#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
    29
#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
    30
#include "newgrf_spritegroup.h"
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
    31
#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
    32
#include "cargotype.h"
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
    33
#include "industry.h"
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
    34
#include "newgrf_canal.h"
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
    35
#include "table/build_industry.h"
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
    36
#include "newgrf_commons.h"
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
    37
#include "newgrf_townname.h"
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
    38
#include "newgrf_industries.h"
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
    39
#include "table/landscape_sprite.h"
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
    40
#include "gfxinit.h"
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
    41
#include "fios.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    42
#include "rail.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    43
#include "strings_func.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    44
#include "gfx_func.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    45
#include "date_func.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    46
#include "vehicle_func.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    47
#include "sound_func.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    48
#include "string_func.h"
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
    49
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
/* TTDPatch extended GRF format codec
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
 * (c) Petr Baudis 2004 (GPL'd)
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
    52
 * 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
    53
 *
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
 * Contains portions of documentation by TTDPatch team.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
 * 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
    56
 * 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
    57
 * 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
    58
455
e7ac799e1437 (svn r665) code fixes for newgrf.c/newgrf.h
dominik
parents: 452
diff changeset
    59
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
    60
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
    61
static uint _file_index; // XXX
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
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
    63
static GRFFile *_cur_grffile;
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    64
GRFFile *_first_grffile;
3707
2999a89e8abd (svn r4650) - NewGRF: use the correct type for _cur_spriteid
peter1138
parents: 3704
diff changeset
    65
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
    66
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
    67
static uint32 _nfo_line;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
    69
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
    70
3814
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
    71
/* 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
    72
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
    73
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
    74
/* 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
    75
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
    76
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
    77
/* 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
    78
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
    79
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
    80
/* Indicates which are the newgrf features currently loaded ingame */
9628
b5c2449616b5 (svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents: 9627
diff changeset
    81
GRFLoadedFeatures _loaded_newgrf_features;
363
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
    82
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    83
enum GrfDataType {
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    84
	GDT_SOUND,
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    85
};
4656
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
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
    88
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
    89
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    90
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    91
enum grfspec_feature {
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    92
	GSF_TRAIN,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    93
	GSF_ROAD,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    94
	GSF_SHIP,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    95
	GSF_AIRCRAFT,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    96
	GSF_STATION,
2438
eaef2b29fa3d (svn r2964) Fix: newgrf: Include missing grf feature canal.
peter1138
parents: 2421
diff changeset
    97
	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
    98
	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
    99
	GSF_TOWNHOUSE,
3620
b459e678a003 (svn r4517) - NewGRF: fix and complete the feature list
peter1138
parents: 3614
diff changeset
   100
	GSF_GLOBALVAR,
b459e678a003 (svn r4517) - NewGRF: fix and complete the feature list
peter1138
parents: 3614
diff changeset
   101
	GSF_INDUSTRYTILES,
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
   102
	GSF_INDUSTRIES,
3620
b459e678a003 (svn r4517) - NewGRF: fix and complete the feature list
peter1138
parents: 3614
diff changeset
   103
	GSF_CARGOS,
b459e678a003 (svn r4517) - NewGRF: fix and complete the feature list
peter1138
parents: 3614
diff changeset
   104
	GSF_SOUNDFX,
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   105
};
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   106
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   107
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
typedef void (*SpecialSpriteHandler)(byte *buf, int len);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
   110
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
   111
	/* GSF_TRAIN */    NUM_TRAIN_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   112
	/* GSF_ROAD */     NUM_ROAD_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   113
	/* GSF_SHIP */     NUM_SHIP_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   114
	/* GSF_AIRCRAFT */ NUM_AIRCRAFT_ENGINES
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   115
};
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   116
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
   117
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
   118
	/* GSF_TRAIN */    0,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   119
	/* GSF_ROAD */     ROAD_ENGINES_INDEX,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   120
	/* GSF_SHIP */     SHIP_ENGINES_INDEX,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   121
	/* GSF_AIRCRAFT */ AIRCRAFT_ENGINES_INDEX,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
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
   124
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
   125
	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
   126
};
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
   127
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   128
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
   129
static uint16 cargo_disallowed[TOTAL_NUM_ENGINES];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
   131
/* 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
   132
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
   133
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   134
/* Contains the GRF ID of the owner of a cargo if it has been reserved */
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   135
static uint32 _grm_cargos[NUM_CARGO];
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   136
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   137
/** DEBUG() function dedicated to newGRF debugging messages
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   138
 * Function is essentialy the same as DEBUG(grf, severity, ...) with the
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   139
 * addition of file:line information when parsing grf files.
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   140
 * NOTE: for the above reason(s) grfmsg() should ONLY be used for
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   141
 * loading/parsing grf files, not for runtime debug messages as there
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   142
 * is no file information available during that time.
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   143
 * @param severity debugging severity level, see debug.h
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
   144
 * @param str message in printf() format */
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   145
void CDECL grfmsg(int severity, const char *str, ...)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
{
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 51
diff changeset
   147
	char buf[1024];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
	va_start(va, str);
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   151
	vsnprintf(buf, sizeof(buf), str, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
	va_end(va);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   153
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   154
	DEBUG(grf, severity, "[%s:%d] %s", _cur_grfconfig->filename, _nfo_line, buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
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
   157
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
   158
{
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
   159
	if (real >= wanted) return true;
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
   160
	grfmsg(0, "%s: Invalid pseudo sprite length %d (expected %d)!", str, real, wanted);
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
   161
	return false;
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
   162
}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   163
500
ef288590e096 (svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents: 490
diff changeset
   164
static inline byte grf_load_byte(byte **buf)
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
   165
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
	return *(*buf)++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
static uint16 grf_load_word(byte **buf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
{
3711
4a0d1c635b56 (svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.
Darkvater
parents: 3709
diff changeset
   171
	uint16 val = grf_load_byte(buf);
4a0d1c635b56 (svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.
Darkvater
parents: 3709
diff changeset
   172
	return val | (grf_load_byte(buf) << 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   175
static uint16 grf_load_extended(byte** buf)
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   176
{
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   177
	uint16 val;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   178
	val = grf_load_byte(buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   179
	if (val == 0xFF) val = grf_load_word(buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   180
	return val;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   181
}
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   182
2324
117bd73a0731 (svn r2850) [newgrf] Patch from peter1139
miham
parents: 2204
diff changeset
   183
static uint32 grf_load_dword(byte **buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
{
3711
4a0d1c635b56 (svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.
Darkvater
parents: 3709
diff changeset
   185
	uint32 val = grf_load_word(buf);
4a0d1c635b56 (svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.
Darkvater
parents: 3709
diff changeset
   186
	return val | (grf_load_word(buf) << 16);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   189
static uint32 grf_load_var(byte size, byte **buf)
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   190
{
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   191
	switch (size) {
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   192
		case 1: return grf_load_byte(buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   193
		case 2: return grf_load_word(buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   194
		case 4: return grf_load_dword(buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   195
		default:
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   196
			NOT_REACHED();
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   197
			return 0;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   198
	}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   199
}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   200
6416
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   201
static const char *grf_load_string(byte **buf, size_t max_len)
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   202
{
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   203
	const char *string   = *(const char **)buf;
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   204
	size_t string_length = ttd_strnlen(string, max_len);
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   205
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   206
	if (string_length == max_len) {
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   207
		/* String was not NUL terminated, so make sure it is now. */
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   208
		(*buf)[string_length - 1] = '\0';
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   209
		grfmsg(7, "String was not terminated with a zero byte.");
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   210
	} else {
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   211
		/* Increase the string length to include the NUL byte. */
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   212
		string_length++;
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   213
	}
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   214
	*buf += string_length;
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   215
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   216
	return string;
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   217
}
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   218
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   219
static GRFFile *GetFileByGRFID(uint32 grfid)
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   220
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   221
	GRFFile *file;
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   222
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   223
	for (file = _first_grffile; file != NULL; file = file->next) {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   224
		if (file->grfid == grfid) break;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   225
	}
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   226
	return file;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   227
}
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   228
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   229
static GRFFile *GetFileByFilename(const char *filename)
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   230
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   231
	GRFFile *file;
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   232
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   233
	for (file = _first_grffile; file != NULL; file = file->next) {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   234
		if (strcmp(file->filename, filename) == 0) break;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   235
	}
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   236
	return file;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   237
}
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   238
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   239
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
   240
/** Used when setting an object's property to map to the GRF's strings
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
   241
 * while taking in consideration the "drift" between TTDPatch string system and OpenTTD's one
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
   242
 * @param grfid Id of the grf file
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
   243
 * @param str StringID that we want to have the equivalent in OoenTTD
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
   244
 * @return the properly adjusted StringID
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
   245
 */
9703
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   246
StringID MapGRFStringID(uint32 grfid, StringID str)
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
   247
{
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   248
	/* StringID table for TextIDs 0x4E->0x6D */
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   249
	static StringID units_volume[] = {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   250
		STR_NOTHING,    STR_PASSENGERS, STR_TONS,       STR_BAGS,
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   251
		STR_LITERS,     STR_ITEMS,      STR_CRATES,     STR_TONS,
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   252
		STR_TONS,       STR_TONS,       STR_TONS,       STR_BAGS,
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   253
		STR_TONS,       STR_TONS,       STR_TONS,       STR_BAGS,
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   254
		STR_TONS,       STR_TONS,       STR_BAGS,       STR_LITERS,
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   255
		STR_TONS,       STR_LITERS,     STR_TONS,       STR_NOTHING,
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   256
		STR_BAGS,       STR_LITERS,     STR_TONS,       STR_NOTHING,
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   257
		STR_TONS,       STR_NOTHING,    STR_LITERS,     STR_NOTHING
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   258
	};
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
   259
	/* 0xD0 and 0xDC stand for all the TextIDs in the range
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
   260
	 * of 0xD000 (misc graphics texts) and 0xDC00 (misc persistent texts).
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
   261
	 * These strings are unique to each grf file, and thus require to be used with the
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
   262
	 * grfid in which they are declared */
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
   263
	if (GB(str, 8, 8) == 0xD0 || GB(str, 8, 8) == 0xDC) {
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
   264
		return GetGRFStringID(grfid, str);
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
   265
	}
9703
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   266
#define TEXID_TO_STRINGID(begin, end, stringid) if (str >= begin && str <= end) return str + (stringid - begin)
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
   267
	/* We have some changes in our cargo strings, resulting in some missing. */
9703
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   268
	TEXID_TO_STRINGID(0x000E, 0x002D, STR_000E);
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   269
	TEXID_TO_STRINGID(0x002E, 0x004D, STR_002E);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   270
	if (str >= 0x004E && str <= 0x006D) str = units_volume[str - 0x004E];
9703
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   271
	TEXID_TO_STRINGID(0x006E, 0x008D, STR_QUANTITY_NOTHING);
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   272
	TEXID_TO_STRINGID(0x008E, 0x00AD, STR_ABBREV_NOTHING);
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
   273
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   274
	/* Map building names according to our lang file changes. There are several
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   275
	 * ranges of house ids, all of which need to be remapped to allow newgrfs
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   276
	 * to use original house names. */
9703
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   277
	TEXID_TO_STRINGID(0x200F, 0x201F, STR_200F_TALL_OFFICE_BLOCK);
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   278
	TEXID_TO_STRINGID(0x2036, 0x2041, STR_2036_COTTAGES);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   279
	TEXID_TO_STRINGID(0x2059, 0x205C, STR_2059_IGLOO);
9703
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   280
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   281
	/* Same thing for industries, since the introduction of 4 new strings above STR_482A_PRODUCTION_LAST_MONTH */
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   282
	TEXID_TO_STRINGID(0x482A, 0x483B, STR_482A_PRODUCTION_LAST_MONTH);
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   283
#undef TEXTID_TO_STRINGID
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   284
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   285
	if (str == STR_NULL) return STR_EMPTY;
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
   286
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
   287
	return str;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
   288
}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
   289
9545
179f651eb116 (svn r9468) [NoAI] -Sync with trunk r9431:9467
truelight
parents: 9517
diff changeset
   290
static uint8 MapDOSColour(uint8 colour)
179f651eb116 (svn r9468) [NoAI] -Sync with trunk r9431:9467
truelight
parents: 9517
diff changeset
   291
{
179f651eb116 (svn r9468) [NoAI] -Sync with trunk r9431:9467
truelight
parents: 9517
diff changeset
   292
	if (_use_dos_palette) return colour;
179f651eb116 (svn r9468) [NoAI] -Sync with trunk r9431:9467
truelight
parents: 9517
diff changeset
   293
179f651eb116 (svn r9468) [NoAI] -Sync with trunk r9431:9467
truelight
parents: 9517
diff changeset
   294
	if (colour < 10) {
179f651eb116 (svn r9468) [NoAI] -Sync with trunk r9431:9467
truelight
parents: 9517
diff changeset
   295
		static uint8 dos_to_win_colour_map[] = { 0, 215, 216, 136, 88, 106, 32, 33, 40, 245 };
179f651eb116 (svn r9468) [NoAI] -Sync with trunk r9431:9467
truelight
parents: 9517
diff changeset
   296
		return dos_to_win_colour_map[colour];
179f651eb116 (svn r9468) [NoAI] -Sync with trunk r9431:9467
truelight
parents: 9517
diff changeset
   297
	}
179f651eb116 (svn r9468) [NoAI] -Sync with trunk r9431:9467
truelight
parents: 9517
diff changeset
   298
179f651eb116 (svn r9468) [NoAI] -Sync with trunk r9431:9467
truelight
parents: 9517
diff changeset
   299
	if (colour >= 245 && colour < 254) return colour - 28;
179f651eb116 (svn r9468) [NoAI] -Sync with trunk r9431:9467
truelight
parents: 9517
diff changeset
   300
179f651eb116 (svn r9468) [NoAI] -Sync with trunk r9431:9467
truelight
parents: 9517
diff changeset
   301
	return colour;
179f651eb116 (svn r9468) [NoAI] -Sync with trunk r9431:9467
truelight
parents: 9517
diff changeset
   302
}
179f651eb116 (svn r9468) [NoAI] -Sync with trunk r9431:9467
truelight
parents: 9517
diff changeset
   303
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
   304
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   305
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
   306
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
static void dewagonize(int condition, int engine)
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
	EngineInfo *ei = &_engine_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   312
	if (condition != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
		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
   314
		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
   315
			rvi->railveh_type = RAILVEH_SINGLEHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
		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
   318
		rvi->railveh_type = RAILVEH_WAGON;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   322
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
   323
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
	byte *buf = *bufp;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   325
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   327
	for (int i = 0; i < numinfo; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   328
		EngineInfo *ei       = &_engine_info[engine + i];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   329
		RailVehicleInfo *rvi = &_rail_vehicle_info[engine + i];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   330
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   331
		switch (prop) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   332
			case 0x05: { // Track type
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
				uint8 tracktype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
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
   335
				switch (tracktype) {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   336
					case 0: rvi->railtype = rvi->engclass >= 2 ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL; break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   337
					case 1: rvi->railtype = RAILTYPE_MONO; break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   338
					case 2: rvi->railtype = RAILTYPE_MAGLEV; break;
3026
6401a6942660 (svn r3606) - NewGRF: Convert from TTDP railtype values to our own railtypes. (These are currently the same, but won't be forever...)
peter1138
parents: 3023
diff changeset
   339
					default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   340
						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
   341
						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
   342
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   343
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   344
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   345
			case 0x08: // AI passenger service
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   346
				/** @todo Tells the AI that this engine is designed for
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   347
				 * passenger services and shouldn't be used for freight. */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   348
				grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   349
				ret = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   350
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   351
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   352
			case 0x09: { // Speed (1 unit is 1 kmh)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
				uint16 speed = grf_load_word(&buf);
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   354
				if (speed == 0xFFFF) speed = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   356
				rvi->max_speed = speed;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   357
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   358
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   359
			case 0x0B: { // Power
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
				uint16 power = grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   362
				if (rvi->railveh_type == RAILVEH_MULTIHEAD) power /= 2;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   363
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   364
				rvi->power = power;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
				dewagonize(power, engine + i);
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   366
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   367
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   368
			case 0x0D: { // Running cost factor
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
				uint8 runcostfact = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   371
				if (rvi->railveh_type == RAILVEH_MULTIHEAD) runcostfact /= 2;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   372
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   373
				rvi->running_cost_base = runcostfact;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   374
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   375
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   376
			case 0x0E: { // Running cost base
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
				uint32 base = grf_load_dword(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
				switch (base) {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   380
					case 0x4C30: rvi->running_cost_class = 0; break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   381
					case 0x4C36: rvi->running_cost_class = 1; break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   382
					case 0x4C3C: rvi->running_cost_class = 2; break;
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
   383
					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
   384
					default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   385
						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
   386
						break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   388
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   389
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   390
			case 0x12: { // Sprite ID
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
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
   393
				/* 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
   394
				 * 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
   395
				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
   396
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   397
				rvi->image_index = spriteid;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   398
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   399
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   400
			case 0x13: { // Dual-headed
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
				uint8 dual = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   403
				if (dual != 0) {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   404
					if (rvi->railveh_type != RAILVEH_MULTIHEAD) {
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   405
						// adjust power and running cost if needed
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   406
						rvi->power /= 2;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   407
						rvi->running_cost_base /= 2;
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   408
					}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   409
					rvi->railveh_type = RAILVEH_MULTIHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
				} else {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   411
					if (rvi->railveh_type == RAILVEH_MULTIHEAD) {
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   412
						// adjust power and running cost if needed
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   413
						rvi->power *= 2;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   414
						rvi->running_cost_base *= 2;
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   415
					}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   416
					rvi->railveh_type = rvi->power == 0 ?
6126
40a18030c3aa (svn r8465) -Regression (r8455): Switching from dual to single head should switch to wagon if power is zero. .Or something.
peter1138
parents: 6119
diff changeset
   417
						RAILVEH_WAGON : RAILVEH_SINGLEHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   419
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   420
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   421
			case 0x14: // Cargo capacity
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   422
				rvi->capacity = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   423
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   424
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   425
			case 0x15: { // Cargo type
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
				uint8 ctype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   428
				if (ctype < NUM_CARGO && HasBit(_cargo_mask, ctype)) {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   429
					rvi->cargo_type = ctype;
2846
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   430
				} else {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   431
					rvi->cargo_type = CT_INVALID;
6468
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
   432
					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
   433
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   434
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   435
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   436
			case 0x16: // Weight
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   437
				SB(rvi->weight, 0, 8, grf_load_byte(&buf));
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   438
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   439
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   440
			case 0x17: // Cost factor
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   441
				rvi->base_cost = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   442
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   443
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   444
			case 0x18: // AI rank
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   445
				rvi->ai_rank = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   446
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   447
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   448
			case 0x19: { // Engine traction type
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   449
				/* What do the individual numbers mean?
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   450
				 * 0x00 .. 0x07: Steam
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   451
				 * 0x08 .. 0x27: Diesel
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   452
				 * 0x28 .. 0x31: Electric
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   453
				 * 0x32 .. 0x37: Monorail
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   454
				 * 0x38 .. 0x41: Maglev
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   455
				 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
				uint8 traction = grf_load_byte(&buf);
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   457
				EngineClass engclass;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   459
				if (traction <= 0x07) {
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   460
					engclass = EC_STEAM;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   461
				} else if (traction <= 0x27) {
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   462
					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
   463
				} else if (traction <= 0x31) {
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   464
					engclass = EC_ELECTRIC;
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   465
				} else if (traction <= 0x37) {
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   466
					engclass = EC_MONORAIL;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   467
				} else if (traction <= 0x41) {
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   468
					engclass = EC_MAGLEV;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   469
				} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
					break;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   471
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   472
				if (rvi->railtype == RAILTYPE_RAIL     && engclass >= EC_ELECTRIC) rvi->railtype = RAILTYPE_ELECTRIC;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   473
				if (rvi->railtype == RAILTYPE_ELECTRIC && engclass  < EC_ELECTRIC) rvi->railtype = RAILTYPE_RAIL;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   474
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   475
				rvi->engclass = engclass;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   476
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   477
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   478
			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
   479
				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
   480
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
				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
   482
					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
   483
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   484
					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
   485
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   486
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   487
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   488
			case 0x1B: // Powered wagons power bonus
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   489
				rvi->pow_wag_power = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   490
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   491
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   492
			case 0x1C: // Refit cost
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   493
				ei->refit_cost = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   494
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   495
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   496
			case 0x1D: // Refit cargo
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   497
				ei->refit_mask = grf_load_dword(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   498
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   499
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   500
			case 0x1E: // Callback
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   501
				ei->callbackmask = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   502
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   503
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   504
			case 0x1F: // Tractive effort coefficient
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   505
				rvi->tractive_effort = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   506
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   507
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   508
			case 0x20: // Air drag
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   509
				/** @todo Air drag for trains. */
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   510
				grf_load_byte(&buf);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   511
				ret = true;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   512
				break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   513
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   514
			case 0x21: // Shorter vehicle
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   515
				rvi->shorten_factor = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   516
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   517
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   518
			case 0x22: // Visual effect
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   519
				/** @see note in engine.h about rvi->visual_effect */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   520
				rvi->visual_effect = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   521
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   522
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   523
			case 0x23: // Powered wagons weight bonus
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   524
				rvi->pow_wag_weight = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   525
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   526
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   527
			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
   528
				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
   529
2545
d1965652e523 (svn r3074) -NewGrf: Fix stupid typo in weight setting.
peter1138
parents: 2542
diff changeset
   530
				if (weight > 4) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   531
					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
   532
				} else {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   533
					SB(rvi->weight, 8, 8, weight);
2542
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   534
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   535
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   536
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   537
			case 0x25: // User-defined bit mask to set when checking veh. var. 42
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   538
				rvi->user_def_data = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   539
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   540
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   541
			case 0x26: // Retire vehicle early
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   542
				ei->retire_early = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   543
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   544
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   545
			case 0x27: // Miscellaneous flags
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   546
				ei->misc_flags = grf_load_byte(&buf);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   547
				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   548
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   549
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   550
			case 0x28: // Cargo classes allowed
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   551
				cargo_allowed[engine + i] = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   552
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   553
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   554
			case 0x29: // Cargo classes disallowed
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   555
				cargo_disallowed[engine + i] = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   556
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   557
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   558
			case 0x2A: // Long format introduction date (days since year 0)
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   559
				ei->base_intro = grf_load_dword(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   560
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   561
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   562
			default:
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   563
				ret = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   564
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   565
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
	}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   567
0
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
{
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   574
	byte *buf = *bufp;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   575
	bool ret = false;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   576
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   577
	for (int i = 0; i < numinfo; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   578
		EngineInfo *ei       = &_engine_info[ROAD_ENGINES_INDEX + engine + i];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   579
		RoadVehicleInfo *rvi = &_road_vehicle_info[engine + i];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   580
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   581
		switch (prop) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   582
			case 0x08: // Speed (1 unit is 0.5 kmh)
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   583
				rvi->max_speed = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   584
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   585
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   586
			case 0x09: // Running cost factor
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   587
				rvi->running_cost = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   588
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   589
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   590
			case 0x0A: // Running cost base
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   591
				/** @todo : I have no idea. --pasky
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   592
				 * I THINK it is used for overriding the base cost of all road vehicle (_price.roadveh_base) --belugas */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   593
				grf_load_dword(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   594
				ret = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   595
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   596
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   597
			case 0x0E: { // Sprite ID
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
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
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
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   605
				rvi->image_index = spriteid;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   606
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   607
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   608
			case 0x0F: // Cargo capacity
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   609
				rvi->capacity = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   610
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   611
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   612
			case 0x10: { // Cargo type
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   613
				uint8 cargo = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   614
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   615
				if (cargo < NUM_CARGO && HasBit(_cargo_mask, cargo)) {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   616
					rvi->cargo_type = cargo;
2846
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   617
				} else {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   618
					rvi->cargo_type = CT_INVALID;
6468
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
   619
					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
   620
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   621
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   622
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   623
			case 0x11: // Cost factor
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   624
				rvi->base_cost = grf_load_byte(&buf); // ?? is it base_cost?
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   625
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   626
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   627
			case 0x12: // SFX
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   628
				rvi->sfx = (SoundFx)grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   629
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   630
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   631
			case 0x13: // Power in 10hp
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   632
			case 0x14: // Weight in 1/4 tons
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   633
			case 0x15: // Speed in mph*0.8
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   634
				/** @todo Support for road vehicles realistic power
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   635
				 * computations (called rvpower in TTDPatch) is just
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   636
				 * missing in OTTD yet. --pasky */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   637
				grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   638
				ret = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   639
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   640
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   641
			case 0x16: // Cargos available for refitting
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   642
				ei->refit_mask = grf_load_dword(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   643
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   644
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   645
			case 0x17: // Callback mask
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   646
				ei->callbackmask = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   647
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   648
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   649
			case 0x18: // Tractive effort
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   650
			case 0x19: // Air drag
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   651
				/** @todo Tractive effort and air drag for road vehicles. */
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   652
				grf_load_byte(&buf);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   653
				ret = true;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   654
				break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   655
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   656
			case 0x1A: // Refit cost
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   657
				ei->refit_cost = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   658
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   659
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   660
			case 0x1B: // Retire vehicle early
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   661
				ei->retire_early = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   662
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   663
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   664
			case 0x1C: // Miscellaneous flags
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   665
				ei->misc_flags = grf_load_byte(&buf);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   666
				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   667
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   668
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   669
			case 0x1D: // Cargo classes allowed
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   670
				cargo_allowed[ROAD_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   671
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   672
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   673
			case 0x1E: // Cargo classes disallowed
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   674
				cargo_disallowed[ROAD_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   675
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   676
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   677
			case 0x1F: // Long format introduction date (days since year 0)
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   678
				ei->base_intro = grf_load_dword(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   679
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   680
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   681
			default:
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   682
				ret = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   683
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   684
		}
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   685
	}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   686
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   687
	*bufp = buf;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   688
	return ret;
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
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   691
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
   692
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
	byte *buf = *bufp;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   694
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   696
	for (int i = 0; i < numinfo; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   697
		EngineInfo *ei       = &_engine_info[SHIP_ENGINES_INDEX + engine + i];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   698
		ShipVehicleInfo *svi = &_ship_vehicle_info[engine + i];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   699
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   700
		switch (prop) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   701
			case 0x08: { // Sprite ID
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
   704
				/* 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
   705
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   706
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   707
				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
   708
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   709
				svi->image_index = spriteid;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   710
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   711
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   712
			case 0x09: // Refittable
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   713
				svi->refittable = (grf_load_byte(&buf) != 0);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   714
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   715
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   716
			case 0x0A: // Cost factor
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   717
				svi->base_cost = grf_load_byte(&buf); // ?? is it base_cost?
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   718
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   719
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   720
			case 0x0B: // Speed (1 unit is 0.5 kmh)
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   721
				svi->max_speed = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   722
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   723
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   724
			case 0x0C: { // Cargo type
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
				uint8 cargo = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   727
				if (cargo < NUM_CARGO && HasBit(_cargo_mask, cargo)) {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   728
					svi->cargo_type = cargo;
2846
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   729
				} else {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   730
					svi->cargo_type = CT_INVALID;
6468
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
   731
					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
   732
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   733
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   734
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   735
			case 0x0D: // Cargo capacity
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   736
				svi->capacity = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   737
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   738
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   739
			case 0x0F: // Running cost factor
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   740
				svi->running_cost = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   741
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   742
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   743
			case 0x10: // SFX
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   744
				svi->sfx = (SoundFx)grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   745
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   746
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   747
			case 0x11: // Cargos available for refitting
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   748
				ei->refit_mask = grf_load_dword(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   749
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   750
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   751
			case 0x12: // Callback mask
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   752
				ei->callbackmask = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   753
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   754
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   755
			case 0x13: // Refit cost
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   756
				ei->refit_cost = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   757
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   758
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   759
			case 0x14: // Ocean speed fraction
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   760
			case 0x15: // Canal speed fraction
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   761
				/** @todo Speed fractions for ships on oceans and canals */
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   762
				grf_load_byte(&buf);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   763
				ret = true;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   764
				break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   765
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   766
			case 0x16: // Retire vehicle early
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   767
				ei->retire_early = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   768
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   769
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   770
			case 0x17: // Miscellaneous flags
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   771
				ei->misc_flags = grf_load_byte(&buf);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   772
				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   773
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   774
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   775
			case 0x18: // Cargo classes allowed
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   776
				cargo_allowed[SHIP_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   777
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   778
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   779
			case 0x19: // Cargo classes disallowed
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   780
				cargo_disallowed[SHIP_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   781
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   782
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   783
			case 0x1A: // Long format introduction date (days since year 0)
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   784
				ei->base_intro = grf_load_dword(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   785
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   786
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   787
			default:
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   788
				ret = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   789
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   790
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
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
   797
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
   798
{
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
   799
	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
   800
	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
   801
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   802
	for (int i = 0; i < numinfo; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   803
		EngineInfo *ei           = &_engine_info[AIRCRAFT_ENGINES_INDEX + engine + i];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   804
		AircraftVehicleInfo *avi = &_aircraft_vehicle_info[engine + i];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   805
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   806
		switch (prop) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   807
			case 0x08: { // Sprite ID
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   808
				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
   809
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
   810
				/* 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
   811
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   812
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   813
				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
   814
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   815
				avi->image_index = spriteid;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   816
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   817
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   818
			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
   819
				if (grf_load_byte(&buf) == 0) {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   820
					avi->subtype = AIR_HELI;
4926
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   821
				} else {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   822
					SB(avi->subtype, 0, 1, 1); // AIR_CTOL
4926
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   823
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   824
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   825
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   826
			case 0x0A: // Large
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   827
				SB(avi->subtype, 1, 1, (grf_load_byte(&buf) != 0 ? 1 : 0)); // AIR_FAST
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   828
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   829
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   830
			case 0x0B: // Cost factor
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   831
				avi->base_cost = grf_load_byte(&buf); // ?? is it base_cost?
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   832
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   833
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   834
			case 0x0C: // Speed (1 unit is 8 mph, we translate to 1 unit is 1 km/h)
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   835
				avi->max_speed = (grf_load_byte(&buf) * 129) / 10;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   836
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   837
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   838
			case 0x0D: // Acceleration
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   839
				avi->acceleration = (grf_load_byte(&buf) * 129) / 10;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   840
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   841
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   842
			case 0x0E: // Running cost factor
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   843
				avi->running_cost = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   844
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   845
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   846
			case 0x0F: // Passenger capacity
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   847
				avi->passenger_capacity = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   848
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   849
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   850
			case 0x11: // Mail capacity
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   851
				avi->mail_capacity = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   852
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   853
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   854
			case 0x12: // SFX
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   855
				avi->sfx = (SoundFx)grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   856
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   857
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   858
			case 0x13: // Cargos available for refitting
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   859
				ei->refit_mask = grf_load_dword(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   860
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   861
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   862
			case 0x14: // Callback mask
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   863
				ei->callbackmask = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   864
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   865
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   866
			case 0x15: // Refit cost
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   867
				ei->refit_cost = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   868
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   869
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   870
			case 0x16: // Retire vehicle early
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   871
				ei->retire_early = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   872
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   873
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   874
			case 0x17: // Miscellaneous flags
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   875
				ei->misc_flags = grf_load_byte(&buf);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   876
				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   877
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   878
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   879
			case 0x18: // Cargo classes allowed
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   880
				cargo_allowed[AIRCRAFT_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   881
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   882
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   883
			case 0x19: // Cargo classes disallowed
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   884
				cargo_disallowed[AIRCRAFT_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   885
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   886
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   887
			case 0x1A: // Long format introduction date (days since year 0)
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   888
				ei->base_intro = grf_load_dword(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   889
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   890
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   891
			default:
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   892
				ret = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   893
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   894
		}
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
   895
	}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   896
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   897
	*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
   898
	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
   899
}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   900
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   901
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
   902
{
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   903
	byte *buf = *bufp;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   904
	bool ret = false;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   905
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
   906
	if (stid + numinfo > MAX_STATIONS) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   907
		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
   908
		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
   909
	}
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   910
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
   911
	/* 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
   912
	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
   913
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   914
	for (int i = 0; i < numinfo; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   915
		StationSpec *statspec = _cur_grffile->stations[stid + i];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   916
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   917
		/* Check that the station we are modifying is defined. */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   918
		if (statspec == NULL && prop != 0x08) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   919
			grfmsg(2, "StationChangeInfo: Attempt to modify undefined station %u, ignoring", stid + i);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   920
			continue;
3501
cf7d2c33e7fc (svn r4352) - NewGRF Codechange: dynamically allocate the memory used to store custom station data. This saves us approximately 40KB per GRF file, if there are no stations defined.
peter1138
parents: 3488
diff changeset
   921
		}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   922
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   923
		switch (prop) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   924
			case 0x08: { // Class ID
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   925
				StationSpec **spec = &_cur_grffile->stations[stid + i];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   926
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
   927
				/* Property 0x08 is special; it is where the station is allocated */
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   928
				if (*spec == NULL) *spec = CallocT<StationSpec>(1);
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   929
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
   930
				/* Swap classid because we read it in BE meaning WAYP or DFLT */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
   931
				uint32 classid = grf_load_dword(&buf);
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   932
				(*spec)->sclass = AllocateStationClass(BSWAP32(classid));
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   933
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   934
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
   935
			case 0x09: // Define sprite layout
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   936
				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
   937
				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
   938
				statspec->copied_renderdata = false;
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
   939
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
   940
				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
   941
					DrawTileSprites *dts = &statspec->renderdata[t];
3570
f9749bae861e (svn r4452) - NewGRF: switch to unsigned ints for array indices.
peter1138
parents: 3566
diff changeset
   942
					uint seq_count = 0;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   943
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
   944
					dts->seq = NULL;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   945
					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
   946
					dts->ground_pal = grf_load_word(&buf);
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   947
					if (dts->ground_sprite == 0) continue;
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   948
					if (HasBit(dts->ground_pal, 15)) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   949
						ClrBit(dts->ground_pal, 15);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   950
						SetBit(dts->ground_sprite, SPRITE_MODIFIER_USE_OFFSET);
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   951
					}
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   952
					if (HasBit(dts->ground_pal, 14)) {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   953
						ClrBit(dts->ground_pal, 14);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   954
						SetBit(dts->ground_sprite, SPRITE_MODIFIER_OPAQUE);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   955
					}
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   956
					if (HasBit(dts->ground_sprite, 15)) {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   957
						ClrBit(dts->ground_sprite, 15);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   958
						SetBit(dts->ground_sprite, PALETTE_MODIFIER_COLOR);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   959
					}
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   960
					if (HasBit(dts->ground_sprite, 14)) {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   961
						ClrBit(dts->ground_sprite, 14);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   962
						SetBit(dts->ground_sprite, PALETTE_MODIFIER_TRANSPARENT);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   963
					}
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   964
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   965
					while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   966
						DrawTileSeqStruct *dtss;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   967
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
   968
						/* 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
   969
						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
   970
						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
   971
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   972
						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
   973
						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
   974
						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
   975
						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
   976
						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
   977
						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
   978
						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
   979
						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
   980
						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
   981
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   982
						/* Remap flags as ours collide */
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   983
						if (HasBit(dtss->pal, 15)) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   984
							ClrBit(dtss->pal, 15);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   985
							SetBit(dtss->image, SPRITE_MODIFIER_USE_OFFSET);
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   986
						}
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   987
						if (HasBit(dtss->pal, 14)) {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   988
							ClrBit(dtss->pal, 14);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   989
							SetBit(dtss->image, SPRITE_MODIFIER_OPAQUE);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   990
						}
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
   991
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   992
						if (HasBit(dtss->image, 15)) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   993
							ClrBit(dtss->image, 15);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   994
							SetBit(dtss->image, PALETTE_MODIFIER_COLOR);
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   995
						}
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   996
						if (HasBit(dtss->image, 14)) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   997
							ClrBit(dtss->image, 14);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
   998
							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
   999
						}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1000
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1001
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1002
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1003
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1004
			case 0x0A: { // Copy sprite layout
398
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
  1005
				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
  1006
				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
  1007
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1008
				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
  1009
				statspec->renderdata = srcstatspec->renderdata;
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  1010
				statspec->copied_renderdata = true;
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1011
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1012
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1013
			case 0x0B: // Callback mask
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1014
				statspec->callbackmask = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1015
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1016
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1017
			case 0x0C: // Disallowed number of platforms
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1018
				statspec->disallowed_platforms = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1019
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1020
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1021
			case 0x0D: // Disallowed platform lengths
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1022
				statspec->disallowed_lengths = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1023
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1024
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1025
			case 0x0E: // Define custom layout
5060
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1026
				statspec->copied_layouts = false;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1027
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1028
				while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1029
					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
  1030
					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
  1031
					StationLayout layout;
3570
f9749bae861e (svn r4452) - NewGRF: switch to unsigned ints for array indices.
peter1138
parents: 3566
diff changeset
  1032
					uint l, p;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1033
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1034
					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
  1035
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1036
					//debug("l %d > %d ?", length, stat->lengths);
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1037
					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
  1038
						statspec->platforms = ReallocT(statspec->platforms, length);
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1039
						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
  1040
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
  1041
						statspec->layouts = ReallocT(statspec->layouts, length);
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1042
						memset(statspec->layouts + statspec->lengths, 0,
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1043
						       (length - statspec->lengths) * sizeof(*statspec->layouts));
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1044
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1045
						statspec->lengths = length;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1046
					}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1047
					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
  1048
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1049
					//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
  1050
					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
  1051
						statspec->layouts[l] = ReallocT(statspec->layouts[l], number);
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  1052
						/* 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
  1053
						memset(statspec->layouts[l] + statspec->platforms[l], 0,
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1054
						       (number - statspec->platforms[l]) * sizeof(**statspec->layouts));
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1055
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1056
						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
  1057
					}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1058
542
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
  1059
					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
  1060
					layout = MallocT<byte>(length * number);
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1061
					for (l = 0; l < length; l++) {
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1062
						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
  1063
							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
  1064
						}
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1065
					}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1066
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1067
					l--;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1068
					p--;
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1069
					free(statspec->layouts[l][p]);
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1070
					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
  1071
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1072
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1073
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1074
			case 0x0F: { // Copy custom layout
5060
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1075
				byte srcid = grf_load_byte(&buf);
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1076
				const StationSpec *srcstatspec = _cur_grffile->stations[srcid];
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1077
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1078
				statspec->lengths   = srcstatspec->lengths;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1079
				statspec->platforms = srcstatspec->platforms;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1080
				statspec->layouts   = srcstatspec->layouts;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1081
				statspec->copied_layouts = true;
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1082
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1083
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1084
			case 0x10: // Little/lots cargo threshold
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1085
				statspec->cargo_threshold = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1086
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1087
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1088
			case 0x11: // Pylon placement
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1089
				statspec->pylons = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1090
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1091
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1092
			case 0x12: // Cargo types for random triggers
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1093
				statspec->cargo_triggers = grf_load_dword(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1094
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1095
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1096
			case 0x13: // General flags
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1097
				statspec->flags = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1098
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1099
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1100
			case 0x14: // Overhead wire placement
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1101
				statspec->wires = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1102
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1103
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1104
			case 0x15: // Blocked tiles
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1105
				statspec->blocked = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1106
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1107
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1108
			case 0x16: // @todo Animation info
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1109
				grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1110
				ret = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1111
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1112
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1113
			case 0x17: // @todo Animation speed
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1114
				grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1115
				ret = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1116
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1117
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1118
			case 0x18: // @todo Animation triggers
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1119
				grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1120
				ret = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1121
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1122
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1123
			default:
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1124
				ret = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1125
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1126
		}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1127
	}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1128
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1129
	*bufp = buf;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1130
	return ret;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1131
}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1132
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
  1133
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
  1134
{
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
  1135
	byte *buf = *bufp;
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1136
	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
  1137
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1138
	if (brid + numinfo > MAX_BRIDGES) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1139
		grfmsg(1, "BridgeChangeInfo: Bridge %u is invalid, max %u, ignoring", brid + numinfo, MAX_BRIDGES);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1140
		return false;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1141
	}
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1142
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1143
	for (int i = 0; i < numinfo; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1144
		Bridge *bridge = &_bridge[brid + i];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1145
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1146
		switch (prop) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1147
			case 0x08: // Year of availability
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1148
				bridge->avail_year = ORIGINAL_BASE_YEAR + grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1149
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1150
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1151
			case 0x09: // Minimum length
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1152
				bridge->min_length = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1153
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1154
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1155
			case 0x0A: // Maximum length
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1156
				bridge->max_length = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1157
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1158
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1159
			case 0x0B: // Cost factor
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1160
				bridge->price = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1161
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1162
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1163
			case 0x0C: // Maximum speed
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1164
				bridge->speed = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1165
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1166
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1167
			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
  1168
				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
  1169
				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
  1170
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
				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
  1172
					/* 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
  1173
					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
  1174
				}
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
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
  1176
				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
  1177
					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
  1178
						grfmsg(1, "BridgeChangeInfo: Table %d >= 7, skipping", tableid);
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  1179
						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
  1180
						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
  1181
					}
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
  1182
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
					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
  1184
						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
  1185
					}
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
  1186
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  1187
					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
  1188
						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
  1189
						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
  1190
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1191
						if (HasBit(pal, 15)) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1192
							SetBit(image, PALETTE_MODIFIER_TRANSPARENT);
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1193
						}
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1194
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1195
						/* Clear old color modifer bit */
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1196
						ClrBit(image, 15);
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1197
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1198
						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
  1199
						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
  1200
					}
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
  1201
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1202
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1203
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1204
			case 0x0E: // Flags; bit 0 - disable far pillars
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1205
				bridge->flags = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1206
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1207
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1208
			case 0x0F: // Long format year of availability (year since year 0)
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1209
				bridge->avail_year = Clamp(grf_load_dword(&buf), MIN_YEAR, MAX_YEAR);
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1210
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1211
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1212
			default:
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1213
				ret = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1214
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1215
		}
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
  1216
	}
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
  1217
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
	*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
  1219
	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
  1220
}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1221
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1222
static bool TownHouseChangeInfo(uint hid, int numinfo, int prop, byte **bufp, int len)
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1223
{
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1224
	byte *buf = *bufp;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1225
	bool ret = false;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1226
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1227
	if (hid + numinfo > HOUSE_MAX) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1228
		grfmsg(1, "TownHouseChangeInfo: Too many houses loaded (%u), max (%u). Ignoring.", hid + numinfo, HOUSE_MAX);
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1229
		return false;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1230
	}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1231
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1232
	/* Allocate house specs if they haven't been allocated already. */
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1233
	if (_cur_grffile->housespec == NULL) {
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1234
		_cur_grffile->housespec = CallocT<HouseSpec*>(HOUSE_MAX);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1235
	}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1236
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1237
	for (int i = 0; i < numinfo; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1238
		HouseSpec *housespec = _cur_grffile->housespec[hid + i];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1239
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1240
		if (prop != 0x08 && housespec == NULL) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1241
			grfmsg(2, "TownHouseChangeInfo: Attempt to modify undefined house %u. Ignoring.", hid + i);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1242
			continue;
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1243
		}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1244
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1245
		switch (prop) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1246
			case 0x08: { // Substitute building type, and definition of a new house
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1247
				HouseSpec **house = &_cur_grffile->housespec[hid + i];
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1248
				byte subs_id = grf_load_byte(&buf);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1249
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1250
				if (subs_id == 0xFF) {
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1251
					/* Instead of defining a new house, a substitute house id
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1252
					 * of 0xFF disables the old house with the current id. */
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1253
					_house_specs[hid + i].enabled = false;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1254
					continue;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1255
				} else if (subs_id >= NEW_HOUSE_OFFSET) {
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1256
					/* The substitute id must be one of the original houses. */
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1257
					grfmsg(2, "TownHouseChangeInfo: Attempt to use new house %u as substitute house for %u. Ignoring.", subs_id, hid + i);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1258
					return false;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1259
				}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1260
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1261
				/* Allocate space for this house. */
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1262
				if (*house == NULL) *house = CallocT<HouseSpec>(1);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1263
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1264
				housespec = *house;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1265
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1266
				memcpy(housespec, &_house_specs[subs_id], sizeof(_house_specs[subs_id]));
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1267
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1268
				housespec->enabled = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1269
				housespec->local_id = hid + i;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1270
				housespec->substitute_id = subs_id;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1271
				housespec->grffile = _cur_grffile;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1272
				housespec->random_colour[0] = 0x04;  // those 4 random colours are the base colour
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1273
				housespec->random_colour[1] = 0x08;  // for all new houses
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1274
				housespec->random_colour[2] = 0x0C;  // they stand for red, blue, orange and green
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1275
				housespec->random_colour[3] = 0x06;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1276
9701
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9686
diff changeset
  1277
				/* Make sure that the third cargo type is valid in this
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9686
diff changeset
  1278
				 * climate. This can cause problems when copying the properties
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9686
diff changeset
  1279
				 * of a house that accepts food, where the new house is valid
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9686
diff changeset
  1280
				 * in the temperate climate. */
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9686
diff changeset
  1281
				if (!GetCargo(housespec->accepts_cargo[2])->IsValid()) {
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9686
diff changeset
  1282
					housespec->cargo_acceptance[2] = 0;
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9686
diff changeset
  1283
				}
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9686
diff changeset
  1284
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1285
				/**
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1286
				 * New houses do not (currently) expect to have a default start
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1287
				 * date before 1930, as this breaks the build date stuff.
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1288
				 * @see FinaliseHouseArray() for more details.
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1289
				 */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1290
				if (housespec->min_date < 1930) housespec->min_date = 1930;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1291
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1292
				_loaded_newgrf_features.has_newhouses = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1293
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1294
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1295
			case 0x09: // Building flags
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1296
				housespec->building_flags = (BuildingFlags)grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1297
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1298
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1299
			case 0x0A: { // Availability years
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1300
				uint16 years = grf_load_word(&buf);
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1301
				housespec->min_date = GB(years, 0, 8) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB(years, 0, 8);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1302
				housespec->max_date = GB(years, 8, 8) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB(years, 8, 8);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1303
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1304
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1305
			case 0x0B: // Population
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1306
				housespec->population = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1307
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1308
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1309
			case 0x0C: // Mail generation multiplier
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1310
				housespec->mail_generation = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1311
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1312
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1313
			case 0x0D: // Passenger acceptance
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1314
			case 0x0E: // Mail acceptance
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1315
				housespec->cargo_acceptance[prop - 0x0D] = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1316
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1317
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1318
			case 0x0F: { // Goods/candy, food/fizzy drinks acceptance
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1319
				int8 goods = grf_load_byte(&buf);
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  1320
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  1321
				/* If value of goods is negative, it means in fact food or, if in toyland, fizzy_drink acceptance.
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  1322
				 * Else, we have "standard" 3rd cargo type, goods or candy, for toyland once more */
9701
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9686
diff changeset
  1323
				CargoID cid = (goods >= 0) ? ((_opt.landscape == LT_TOYLAND) ? CT_CANDY : CT_GOODS) :
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1324
						((_opt.landscape == LT_TOYLAND) ? CT_FIZZY_DRINKS : CT_FOOD);
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  1325
9701
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9686
diff changeset
  1326
				/* Make sure the cargo type is valid in this climate. */
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9686
diff changeset
  1327
				if (!GetCargo(cid)->IsValid()) goods = 0;
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9686
diff changeset
  1328
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9686
diff changeset
  1329
				housespec->accepts_cargo[2] = cid;
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1330
				housespec->cargo_acceptance[2] = abs(goods); // but we do need positive value here
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1331
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1332
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1333
			case 0x10: // Local authority rating decrease on removal
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1334
				housespec->remove_rating_decrease = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1335
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1336
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1337
			case 0x11: // Removal cost multiplier
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1338
				housespec->removal_cost = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1339
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1340
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1341
			case 0x12: // Building name ID
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1342
				housespec->building_name = MapGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1343
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1344
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1345
			case 0x13: // Building availability mask
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1346
				housespec->building_availability = (HouseZones)grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1347
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1348
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1349
			case 0x14: // House callback flags
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1350
				housespec->callback_mask = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1351
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1352
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1353
			case 0x15: { // House override byte
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1354
				byte override = grf_load_byte(&buf);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1355
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1356
				/* The house being overridden must be an original house. */
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1357
				if (override >= NEW_HOUSE_OFFSET) {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1358
					grfmsg(2, "TownHouseChangeInfo: Attempt to override new house %u with house id %u. Ignoring.", override, hid + i);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1359
					continue;
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1360
				}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1361
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1362
				_house_mngr.Add(hid + i, _cur_grffile->grfid, override);
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1363
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1364
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1365
			case 0x16: // Periodic refresh multiplier
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1366
				housespec->processing_time = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1367
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1368
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1369
			case 0x17: // Four random colours to use
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1370
				for (uint j = 0; j < 4; j++) housespec->random_colour[j] = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1371
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1372
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1373
			case 0x18: // Relative probability of appearing
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1374
				housespec->probability = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1375
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1376
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1377
			case 0x19: // Extra flags
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1378
				housespec->extra_flags = (HouseExtraFlags)grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1379
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1380
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1381
			case 0x1A: // Animation frames
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1382
				housespec->animation_frames = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1383
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1384
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1385
			case 0x1B: // Animation speed
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1386
				housespec->animation_speed = Clamp(grf_load_byte(&buf), 2, 16);
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1387
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1388
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1389
			case 0x1C: // Class of the building type
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1390
				housespec->class_id = AllocateHouseClassID(grf_load_byte(&buf), _cur_grffile->grfid);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1391
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1392
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1393
			case 0x1D: // Callback flags 2
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1394
				housespec->callback_mask |= (grf_load_byte(&buf) << 8);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1395
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1396
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1397
			case 0x1E: { // Accepted cargo types
9599
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
  1398
				uint32 cargotypes = grf_load_dword(&buf);
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
  1399
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
  1400
				/* Check if the cargo types should not be changed */
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
  1401
				if (cargotypes == 0xFFFFFFFF) break;
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
  1402
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
  1403
				for (uint j = 0; j < 3; j++) {
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
  1404
					/* Get the cargo number from the 'list' */
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
  1405
					uint8 cargo_part = GB(cargotypes, 8 * j, 8);
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
  1406
					CargoID cargo = GetCargoTranslation(cargo_part, _cur_grffile);
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
  1407
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
  1408
					if (cargo == CT_INVALID) {
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
  1409
						/* Disable acceptance of invalid cargo type */
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1410
						housespec->cargo_acceptance[j] = 0;
9599
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
  1411
					} else {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1412
						housespec->accepts_cargo[j] = cargo;
9599
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
  1413
					}
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
  1414
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1415
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1416
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1417
			case 0x1F: // Minimum life span
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1418
				housespec->minimum_life = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1419
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1420
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1421
			case 0x20: { // @todo Cargo acceptance watch list
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1422
				byte count = grf_load_byte(&buf);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1423
				for (byte j = 0; j < count; j++) grf_load_byte(&buf);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1424
				ret = true;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1425
			} break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1426
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1427
			default:
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1428
				ret = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1429
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1430
		}
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1431
	}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1432
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1433
	*bufp = buf;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1434
	return ret;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1435
}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  1436
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1437
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
  1438
{
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1439
	byte *buf = *bufp;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1440
	bool ret = false;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1441
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1442
	for (int i = 0; i < numinfo; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1443
		switch (prop) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1444
			case 0x08: { // Cost base factor
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1445
				byte factor = grf_load_byte(&buf);
2508
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1446
				uint price = gvid + i;
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1447
2508
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1448
				if (price < NUM_PRICES) {
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1449
					SetPriceBaseMultiplier(price, factor);
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1450
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1451
					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
  1452
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1453
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1454
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1455
			case 0x09: { // Cargo translation table
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1456
				if (gvid != 0) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1457
					if (i == 0) grfmsg(1, "InitChangeInfo: Cargo translation table must start at zero");
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1458
					/* Skip data */
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1459
					buf += 4;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1460
					break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1461
				}
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1462
				if (i == 0) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1463
					free(_cur_grffile->cargo_list);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1464
					_cur_grffile->cargo_max = numinfo;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1465
					_cur_grffile->cargo_list = MallocT<CargoLabel>(numinfo);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1466
				}
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1467
				CargoLabel cl = grf_load_dword(&buf);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1468
				_cur_grffile->cargo_list[i] = BSWAP32(cl);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1469
			} break;
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1470
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1471
			case 0x0A: { // Currency display names
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1472
				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
  1473
				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
  1474
4504
3d20af4bd525 (svn r6289) -Fix(r6108) : case 0x48 (generic text) should not have been set over newstations.
belugas
parents: 4434
diff changeset
  1475
				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
  1476
					_currency_specs[curidx].name = newone;
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1477
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1478
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1479
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1480
			case 0x0B: { // Currency multipliers
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1481
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1482
				uint32 rate = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1483
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1484
				if (curidx < NUM_CURRENCY) {
4602
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1485
					/* 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
  1486
					 * 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
  1487
					 * to be compatible */
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1488
					_currency_specs[curidx].rate = rate / 1000;
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1489
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1490
					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
  1491
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1492
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1493
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1494
			case 0x0C: { // Currency options
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1495
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1496
				uint16 options = grf_load_word(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1497
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1498
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1499
					_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
  1500
					/* 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
  1501
					 * 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
  1502
					_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
  1503
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1504
					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
  1505
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1506
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1507
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1508
			case 0x0D: { // Currency prefix symbol
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1509
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1510
				uint32 tempfix = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1511
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1512
				if (curidx < NUM_CURRENCY) {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1513
					memcpy(_currency_specs[curidx].prefix, &tempfix, 4);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1514
					_currency_specs[curidx].prefix[4] = 0;
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 symbol %d out of range, ignoring", curidx);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1517
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1518
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1519
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1520
			case 0x0E: { // Currency suffix symbol
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1521
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1522
				uint32 tempfix = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1523
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1524
				if (curidx < NUM_CURRENCY) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  1525
					memcpy(&_currency_specs[curidx].suffix, &tempfix, 4);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1526
					_currency_specs[curidx].suffix[4] = 0;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1527
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1528
					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
  1529
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1530
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1531
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1532
			case 0x0F: { //  Euro introduction dates
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1533
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1534
				Year year_euro = grf_load_word(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1535
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1536
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1537
					_currency_specs[curidx].to_euro = year_euro;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1538
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1539
					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
  1540
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1541
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1542
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1543
			case 0x10: // Snow line height table
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1544
				if (numinfo > 1 || IsSnowLineSet()) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1545
					grfmsg(1, "GlobalVarChangeInfo: The snowline can only be set once (%d)", numinfo);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1546
				} else if (len < SNOW_LINE_MONTHS * SNOW_LINE_DAYS) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1547
					grfmsg(1, "GlobalVarChangeInfo: Not enough entries set in the snowline table (%d)", len);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1548
				} else {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1549
					byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1550
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1551
					for (uint i = 0; i < SNOW_LINE_MONTHS; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1552
						for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1553
							table[i][j] = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1554
						}
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  1555
					}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1556
					SetSnowLine(table);
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  1557
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1558
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1559
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1560
			default:
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1561
				ret = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1562
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1563
		}
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1564
	}
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1565
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1566
	*bufp = buf;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1567
	return ret;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1568
}
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1569
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1570
static bool CargoChangeInfo(uint cid, int numinfo, int prop, byte **bufp, int len)
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1571
{
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1572
	byte *buf = *bufp;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1573
	bool ret = false;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1574
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1575
	if (cid + numinfo > NUM_CARGO) {
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1576
		grfmsg(2, "CargoChangeInfo: Cargo type %d out of range (max %d)", cid + numinfo, NUM_CARGO - 1);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1577
		return false;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1578
	}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1579
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1580
	for (int i = 0; i < numinfo; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1581
		CargoSpec *cs = &_cargo[cid + i];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1582
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1583
		switch (prop) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1584
			case 0x08: /* Bit number of cargo */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1585
				cs->bitnum = grf_load_byte(&buf);
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1586
				if (cs->IsValid()) {
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  1587
					cs->grfid = _cur_grffile->grfid;
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1588
					SetBit(_cargo_mask, cid + i);
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1589
				} else {
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1590
					ClrBit(_cargo_mask, cid + i);
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1591
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1592
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1593
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1594
			case 0x09: /* String ID for cargo type name */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1595
				cs->name = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1596
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1597
9686
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9641
diff changeset
  1598
			case 0x0A: /* String for 1 unit of cargo */
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9641
diff changeset
  1599
				cs->name_single = grf_load_word(&buf);
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1600
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1601
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1602
			case 0x0B:
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1603
				/* String for units of cargo. This is different in OpenTTD to TTDPatch
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1604
				 * (e.g. 10 tonnes of coal) */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1605
				cs->units_volume = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1606
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1607
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1608
			case 0x0C: /* String for quantity of cargo (e.g. 10 tonnes of coal) */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1609
				cs->quantifier = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1610
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1611
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1612
			case 0x0D: /* String for two letter cargo abbreviation */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1613
				cs->abbrev = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1614
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1615
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1616
			case 0x0E: /* Sprite ID for cargo icon */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1617
				cs->sprite = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1618
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1619
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1620
			case 0x0F: /* Weight of one unit of cargo */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1621
				cs->weight = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1622
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1623
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1624
			case 0x10: /* Used for payment calculation */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1625
				cs->transit_days[0] = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1626
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1627
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1628
			case 0x11: /* Used for payment calculation */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1629
				cs->transit_days[1] = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1630
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1632
			case 0x12: /* Base cargo price */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1633
				cs->initial_payment = grf_load_dword(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1634
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1635
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1636
			case 0x13: /* Colour for station rating bars */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1637
				cs->rating_colour = MapDOSColour(grf_load_byte(&buf));
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1638
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1639
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1640
			case 0x14: /* Colour for cargo graph */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1641
				cs->legend_colour = MapDOSColour(grf_load_byte(&buf));
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1642
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1643
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1644
			case 0x15: /* Freight status */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1645
				cs->is_freight = (grf_load_byte(&buf) != 0);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1646
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1647
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1648
			case 0x16: /* Cargo classes */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1649
				cs->classes = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1650
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1651
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1652
			case 0x17: /* Cargo label */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1653
				cs->label = grf_load_dword(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1654
				cs->label = BSWAP32(cs->label);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1655
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1656
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1657
			case 0x18: { /* Town growth substitute type */
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1658
				uint8 substitute_type = grf_load_byte(&buf);
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1659
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1660
				switch (substitute_type) {
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1661
					case 0x00: cs->town_effect = TE_PASSENGERS; break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1662
					case 0x02: cs->town_effect = TE_MAIL; break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1663
					case 0x05: cs->town_effect = TE_GOODS; break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1664
					case 0x09: cs->town_effect = TE_WATER; break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1665
					case 0x0B: cs->town_effect = TE_FOOD; break;
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1666
					default:
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1667
						grfmsg(1, "CargoChangeInfo: Unknown town growth substitute value %d, setting to none.", substitute_type);
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1668
					case 0xFF: cs->town_effect = TE_NONE; break;
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1669
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1670
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1671
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1672
			case 0x19: /* Town growth coefficient */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1673
				cs->multipliertowngrowth = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1674
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1675
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1676
			case 0x1A: /* Bitmask of callbacks to use */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1677
				cs->callback_mask = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1678
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1679
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1680
			default:
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1681
				ret = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1682
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1683
		}
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1684
	}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1685
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1686
	*bufp = buf;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1687
	return ret;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1688
}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1689
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  1690
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1691
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
  1692
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1693
	byte *buf = *bufp;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1694
	bool ret = false;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1695
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1696
	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
  1697
		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
  1698
		return false;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1699
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1700
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1701
	for (int i = 0; i < numinfo; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1702
		uint sound = sid + i + _cur_grffile->sound_offset - GetNumOriginalSounds();
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1703
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1704
		if (sound >= GetNumSounds()) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1705
			grfmsg(1, "SoundEffectChangeInfo: Sound %d not defined (max %d)", sound, GetNumSounds());
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1706
			continue;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1707
		}
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1708
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1709
		switch (prop) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1710
			case 0x08: // Relative volume
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1711
				GetSound(sound)->volume = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1712
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1713
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1714
			case 0x09: // Priority
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1715
				GetSound(sound)->priority = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1716
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1717
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1718
			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
  1719
				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
  1720
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1721
				if (orig_sound >= GetNumSounds()) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1722
					grfmsg(1, "SoundEffectChangeInfo: Original sound %d not defined (max %d)", orig_sound, GetNumSounds());
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1723
				} else {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1724
					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
  1725
					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
  1726
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1727
					/* 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
  1728
					*oldfe = *newfe;
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1729
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1730
			} break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1731
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1732
			default:
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1733
				ret = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1734
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  1735
		}
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1736
	}
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
	*bufp = buf;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1739
	return ret;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1740
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1741
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1742
static bool IndustrytilesChangeInfo(uint indtid, int numinfo, int prop, byte **bufp, int len)
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1743
{
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1744
	byte *buf = *bufp;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1745
	bool ret = false;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1746
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1747
	if (indtid + numinfo > NUM_INDUSTRYTILES) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1748
		grfmsg(1, "IndustryTilesChangeInfo: Too many industry tiles loaded (%u), max (%u). Ignoring.", indtid + numinfo, NUM_INDUSTRYTILES);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1749
		return false;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1750
	}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1751
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1752
	/* Allocate industry tile specs if they haven't been allocated already. */
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1753
	if (_cur_grffile->indtspec == NULL) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1754
		_cur_grffile->indtspec = CallocT<IndustryTileSpec*>(NUM_INDUSTRYTILES);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1755
	}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1756
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1757
	for (int i = 0; i < numinfo; i++) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1758
		IndustryTileSpec *tsp = _cur_grffile->indtspec[indtid + i];
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1759
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1760
		if (prop != 0x08 && tsp == NULL) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1761
			grfmsg(2, "IndustryTilesChangeInfo: Attempt to modify undefined industry tile %u. Ignoring.", indtid + i);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1762
			continue;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1763
		}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1764
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1765
		switch (prop) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1766
			case 0x08: { // Substitute industry tile type
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1767
				IndustryTileSpec **tilespec = &_cur_grffile->indtspec[indtid + i];
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1768
				byte subs_id = grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1769
9701
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9686
diff changeset
  1770
				if (subs_id >= NEW_INDUSTRYTILEOFFSET) {
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1771
					/* The substitute id must be one of the original industry tile. */
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1772
					grfmsg(2, "IndustryTilesChangeInfo: Attempt to use new industry tile %u as substitute industry tile for %u. Ignoring.", subs_id, indtid + i);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1773
					return false;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1774
				}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1775
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1776
				/* Allocate space for this industry. */
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1777
				if (*tilespec == NULL) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1778
					int tempid;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1779
					*tilespec = CallocT<IndustryTileSpec>(1);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1780
					tsp = *tilespec;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1781
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1782
					memcpy(tsp, &_industry_tile_specs[subs_id], sizeof(_industry_tile_specs[subs_id]));
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1783
					tsp->enabled = true;
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  1784
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  1785
					/* A copied tile should not have the animation infos copied too.
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  1786
					 * The anim_state should be left untouched, though
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  1787
					 * It is up to the author to animate them himself */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  1788
					tsp->anim_production = INDUSTRYTILE_NOANIM;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  1789
					tsp->anim_next = INDUSTRYTILE_NOANIM;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  1790
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1791
					tsp->grf_prop.local_id = indtid + i;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1792
					tsp->grf_prop.subst_id = subs_id;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1793
					tsp->grf_prop.grffile = _cur_grffile;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1794
					tempid = _industile_mngr.AddEntityID(indtid + i, _cur_grffile->grfid, subs_id); // pre-reserve the tile slot
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1795
				}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1796
			} break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1797
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1798
			case 0x09: { // Industry tile override
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1799
				byte ovrid = grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1800
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1801
				/* The industry being overridden must be an original industry. */
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1802
				if (ovrid >= NEW_INDUSTRYTILEOFFSET) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1803
					grfmsg(2, "IndustryTilesChangeInfo: Attempt to override new industry tile %u with industry tile id %u. Ignoring.", ovrid, indtid + i);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1804
					return false;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1805
				}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1806
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1807
				_industile_mngr.Add(indtid + i, _cur_grffile->grfid, ovrid);
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1808
			} break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1809
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1810
			case 0x0A: // Tile acceptance
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1811
			case 0x0B:
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1812
			case 0x0C: {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1813
				uint16 acctp = grf_load_word(&buf);
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  1814
				tsp->accepts_cargo[prop - 0x0A] = GetCargoTranslation(GB(acctp, 0, 8), _cur_grffile);
9704
197cb8c6ae17 (svn r11221) [NoAI] -Sync: with trunk r11145:11220
glx
parents: 9703
diff changeset
  1815
				tsp->acceptance[prop - 0x0A] = GB(acctp, 8, 8);
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1816
			} break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1817
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1818
			case 0x0D: // Land shape flags
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1819
				tsp->slopes_refused = (Slope)grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1820
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1821
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1822
			case 0x0E: // Callback flags
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1823
				tsp->callback_flags = grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1824
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1825
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1826
			case 0x0F: // Animation information
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1827
				tsp->animation_info = grf_load_word(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1828
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1829
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1830
			case 0x10: // Animation speed
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1831
				tsp->animation_speed = grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1832
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1833
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1834
			case 0x11: // Triggers for callback 25
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1835
				tsp->animation_triggers = grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1836
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1837
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1838
			case 0x12: // Special flags
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1839
				tsp->animation_special_flags = grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1840
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1841
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1842
			default:
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1843
				ret = true;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1844
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1845
		}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1846
	}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1847
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1848
	*bufp = buf;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1849
	return ret;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1850
}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1851
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1852
static bool IndustriesChangeInfo(uint indid, int numinfo, int prop, byte **bufp, int len)
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1853
{
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1854
	byte *buf = *bufp;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1855
	bool ret = false;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1856
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1857
	if (indid + numinfo > NUM_INDUSTRYTYPES) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1858
		grfmsg(1, "IndustriesChangeInfo: Too many industries loaded (%u), max (%u). Ignoring.", indid + numinfo, NUM_INDUSTRYTYPES);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1859
		return false;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1860
	}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1861
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1862
	grfmsg(1, "IndustriesChangeInfo: newid %u", indid);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1863
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1864
	/* Allocate industry specs if they haven't been allocated already. */
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1865
	if (_cur_grffile->industryspec == NULL) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1866
		_cur_grffile->industryspec = CallocT<IndustrySpec*>(NUM_INDUSTRYTYPES);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1867
	}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1868
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1869
	for (int i = 0; i < numinfo; i++) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1870
		IndustrySpec *indsp = _cur_grffile->industryspec[indid + i];
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1871
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1872
		if (prop != 0x08 && indsp == NULL) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1873
			grfmsg(2, "IndustriesChangeInfo: Attempt to modify undefined industry %u. Ignoring.", indid + i);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1874
			continue;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1875
		}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1876
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1877
		switch (prop) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1878
			case 0x08: { // Substitute industry type
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1879
				IndustrySpec **indspec = &_cur_grffile->industryspec[indid + i];
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1880
				byte subs_id = grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1881
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1882
				if (subs_id == 0xFF) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1883
					/* Instead of defining a new industry, a substitute industry id
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1884
					 * of 0xFF disables the old industry with the current id. */
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1885
					_industry_specs[indid + i].enabled = false;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1886
					continue;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1887
				} else if (subs_id >= NEW_INDUSTRYOFFSET) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1888
					/* The substitute id must be one of the original industry. */
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1889
					grfmsg(2, "_industry_specs: Attempt to use new industry %u as substitute industry for %u. Ignoring.", subs_id, indid + i);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1890
					return false;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1891
				}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1892
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1893
				/* Allocate space for this industry.
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1894
				 * Only need to do it once. If ever it is called again, it should not
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1895
				 * do anything */
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1896
				if (*indspec == NULL) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1897
					*indspec = CallocT<IndustrySpec>(1);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1898
					indsp = *indspec;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1899
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1900
					memcpy(indsp, &_origin_industry_specs[subs_id], sizeof(_industry_specs[subs_id]));
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1901
					indsp->enabled = true;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1902
					indsp->grf_prop.local_id = indid + i;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1903
					indsp->grf_prop.subst_id = subs_id;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1904
					indsp->grf_prop.grffile = _cur_grffile;
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  1905
					/* If the grf industry needs to check its surounding upon creation, it should
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  1906
					 * rely on callbacks, not on the original placement functions */
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  1907
					indsp->check_proc = CHECK_NOTHING;
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1908
				}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1909
			} break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1910
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1911
			case 0x09: { // Industry type override
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1912
				byte ovrid = grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1913
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1914
				/* The industry being overridden must be an original industry. */
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1915
				if (ovrid >= NEW_INDUSTRYOFFSET) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1916
					grfmsg(2, "IndustriesChangeInfo: Attempt to override new industry %u with industry id %u. Ignoring.", ovrid, indid + i);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1917
					return false;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1918
				}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1919
				indsp->grf_prop.override = ovrid;
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1920
				_industry_mngr.Add(indid + i, _cur_grffile->grfid, ovrid);
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1921
			} break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1922
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1923
			case 0x0A: { // Set industry layout(s)
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1924
				indsp->num_table = grf_load_byte(&buf); // Number of layaouts
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1925
				uint32 defsize = grf_load_dword(&buf);  // Total size of the definition
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1926
				IndustryTileTable **tile_table = CallocT<IndustryTileTable*>(indsp->num_table); // Table with tiles to compose an industry
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1927
				IndustryTileTable *itt = CallocT<IndustryTileTable>(defsize); // Temporary array to read the tile layouts from the GRF
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1928
				int size;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1929
				IndustryTileTable *copy_from;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1930
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1931
				for (byte j = 0; j < indsp->num_table; j++) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1932
					for (int k = 0;; k++) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1933
						itt[k].ti.x = grf_load_byte(&buf); // Offsets from northermost tile
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1934
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1935
						if (itt[k].ti.x == 0xFE && k == 0) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1936
							/* This means we have to borrow the layout from an old industry */
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1937
							IndustryType type = grf_load_byte(&buf);  //industry holding required layout
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1938
							byte laynbr = grf_load_byte(&buf);        //layout number to borrow
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1939
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1940
							copy_from = (IndustryTileTable*)_origin_industry_specs[type].table[laynbr];
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1941
							for (size = 1;; size++) {
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  1942
								if (copy_from[size - 1].ti.x == -0x80 && copy_from[size - 1].ti.y == 0) break;
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1943
							}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1944
							break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1945
						}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1946
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1947
						itt[k].ti.y = grf_load_byte(&buf); // Or table definition finalisation
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1948
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1949
						if (itt[k].ti.x == 0 && itt[k].ti.y == 0x80) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1950
							/*  Not the same terminator.  The one we are using is rather
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1951
							 x= -80, y = x .  So, adjust it. */
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1952
							itt[k].ti.x = -0x80;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1953
							itt[k].ti.y =  0;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1954
							itt[k].gfx  =  0;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1955
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1956
							size = k + 1;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1957
							copy_from = itt;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1958
							break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1959
						}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1960
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1961
						itt[k].gfx = grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1962
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1963
						if (itt[k].gfx == 0xFE) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1964
							/* Use a new tile from this GRF */
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1965
							int local_tile_id = grf_load_word(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1966
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1967
							/* Read the ID from the _industile_mngr. */
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1968
							int tempid = _industile_mngr.GetID(local_tile_id, _cur_grffile->grfid);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1969
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1970
							if (tempid == INVALID_INDUSTRYTILE) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1971
								grfmsg(2, "IndustriesChangeInfo: Attempt to use industry tile %u with industry id %u, not yet defined. Ignoring.", local_tile_id, indid);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1972
							} else {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1973
								/* Declared as been valid, can be used */
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1974
								itt[k].gfx = tempid;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1975
								size = k + 1;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1976
								copy_from = itt;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1977
							}
9704
197cb8c6ae17 (svn r11221) [NoAI] -Sync: with trunk r11145:11220
glx
parents: 9703
diff changeset
  1978
						} else if (itt[k].gfx == 0xFF) {
197cb8c6ae17 (svn r11221) [NoAI] -Sync: with trunk r11145:11220
glx
parents: 9703
diff changeset
  1979
							itt[k].ti.x = (int8)GB(itt[k].ti.x, 0, 8);
197cb8c6ae17 (svn r11221) [NoAI] -Sync: with trunk r11145:11220
glx
parents: 9703
diff changeset
  1980
							itt[k].ti.y = (int8)GB(itt[k].ti.y, 0, 8);
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1981
						}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1982
					}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1983
					tile_table[j] = CallocT<IndustryTileTable>(size);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1984
					memcpy(tile_table[j], copy_from, sizeof(*copy_from) * size);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1985
				}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1986
				/* Install final layout construction in the industry spec */
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1987
				indsp->table = tile_table;
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  1988
				SetBit(indsp->cleanup_flag, 1);
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1989
				free(itt);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1990
			} break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1991
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1992
			case 0x0B: // Industry production flags
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1993
				indsp->life_type = (IndustryLifeType)grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1994
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1995
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1996
			case 0x0C: // Industry closure message
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1997
				indsp->closure_text = MapGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1998
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  1999
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2000
			case 0x0D: // Production increase message
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2001
				indsp->production_up_text = MapGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2002
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2003
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2004
			case 0x0E: // Production decrease message
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2005
				indsp->production_down_text = MapGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2006
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2007
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2008
			case 0x0F: // Fund cost multiplier
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2009
				indsp->cost_multiplier = grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2010
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2011
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2012
			case 0x10: // Production cargo types
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2013
				for (byte j = 0; j < 2; j++) {
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  2014
					indsp->produced_cargo[j] = GetCargoTranslation(grf_load_byte(&buf), _cur_grffile);
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2015
				}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2016
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2017
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2018
			case 0x11: // Acceptance cargo types
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2019
				for (byte j = 0; j < 3; j++) {
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  2020
					indsp->accepts_cargo[j] = GetCargoTranslation(grf_load_byte(&buf), _cur_grffile);
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2021
				}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2022
				grf_load_byte(&buf); // Unnused, eat it up
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2023
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2024
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2025
			case 0x12: // Production multipliers
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2026
			case 0x13:
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2027
				indsp->production_rate[prop - 0x12] = grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2028
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2029
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2030
			case 0x14: // Minimal amount of cargo distributed
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2031
				indsp->minimal_cargo = grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2032
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2033
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2034
			case 0x15: { // Random sound effects
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2035
				indsp->number_of_sounds = grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2036
				uint8 *sounds = MallocT<uint8>(indsp->number_of_sounds);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2037
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2038
				for (uint8 j = 0; j < indsp->number_of_sounds; j++) sounds[j] = grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2039
				indsp->random_sounds = sounds;
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2040
				SetBit(indsp->cleanup_flag, 0);
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2041
			} break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2042
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2043
			case 0x16: // Conflicting industry types
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2044
				for (byte j = 0; j < 3; j++) indsp->conflicting[j] = grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2045
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2046
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2047
			case 0x17: // Probability in random game
9704
197cb8c6ae17 (svn r11221) [NoAI] -Sync: with trunk r11145:11220
glx
parents: 9703
diff changeset
  2048
				indsp->appear_creation[_opt.landscape] = grf_load_byte(&buf);
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2049
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2050
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2051
			case 0x18: // Probability during gameplay
9704
197cb8c6ae17 (svn r11221) [NoAI] -Sync: with trunk r11145:11220
glx
parents: 9703
diff changeset
  2052
				indsp->appear_ingame[_opt.landscape] = grf_load_byte(&buf);
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2053
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2054
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2055
			case 0x19: // Map color
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2056
				indsp->map_colour = MapDOSColour(grf_load_byte(&buf));
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2057
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2058
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2059
			case 0x1A: // Special industry flags to define special behavior
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  2060
				indsp->behaviour = (IndustryBehaviour)grf_load_dword(&buf);
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2061
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2062
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2063
			case 0x1B: // New industry text ID
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2064
				indsp->new_industry_text = MapGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2065
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2066
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2067
			case 0x1C: // Input cargo multipliers for the three input cargo types
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2068
			case 0x1D:
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2069
			case 0x1E: {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2070
					uint32 multiples = grf_load_dword(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2071
					indsp->input_cargo_multiplier[prop - 0x1C][0] = GB(multiples, 0,15);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2072
					indsp->input_cargo_multiplier[prop - 0x1C][1] = GB(multiples, 15,15);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2073
				} break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2074
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2075
			case 0x1F: // Industry name
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2076
				indsp->name = MapGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2077
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2078
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2079
			case 0x20: // Prospecting success chance
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2080
				indsp->prospecting_chance = grf_load_dword(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2081
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2082
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2083
			case 0x21:   // Callback flags
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2084
			case 0x22: { // Callback additional flags
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2085
				byte aflag = grf_load_byte(&buf);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2086
				SB(indsp->callback_flags, (prop - 0x21) * 8, 8, aflag);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2087
			} break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2088
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  2089
			case 0x23: // removal cost multiplier
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  2090
				indsp->removal_cost_multiplier = grf_load_dword(&buf);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  2091
				break;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  2092
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2093
			default:
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2094
				ret = true;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2095
				break;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2096
		}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2097
	}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2098
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2099
	*bufp = buf;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2100
	return ret;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2101
}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2102
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2103
/* Action 0x00 */
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  2104
static void FeatureChangeInfo(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2105
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2106
	byte *bufend = buf + len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2107
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2108
	/* <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
  2109
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2110
	 * 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
  2111
	 *                 4 for defining new train station sets
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2112
	 * 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
  2113
	 * B num-info      how many vehicles/stations to change
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2114
	 * E id            ID of first vehicle/station to change, if num-info is
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2115
	 *                 greater than one, this one and the following
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2116
	 *                 vehicles/stations will be changed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2117
	 * 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
  2118
	 * 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
  2119
	/* TODO: Bridges, town houses. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2120
2438
eaef2b29fa3d (svn r2964) Fix: newgrf: Include missing grf feature canal.
peter1138
parents: 2421
diff changeset
  2121
	static const VCI_Handler handler[] = {
3825
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2122
		/* GSF_TRAIN */        RailVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2123
		/* GSF_ROAD */         RoadVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2124
		/* GSF_SHIP */         ShipVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2125
		/* GSF_AIRCRAFT */     AircraftVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2126
		/* GSF_STATION */      StationChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2127
		/* GSF_CANAL */        NULL,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2128
		/* GSF_BRIDGE */       BridgeChangeInfo,
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2129
		/* GSF_TOWNHOUSE */    TownHouseChangeInfo,
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2130
		/* GSF_GLOBALVAR */    NULL, /* Global variables are handled during reservation */
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2131
		/* GSF_INDUSTRYTILES */IndustrytilesChangeInfo,
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2132
		/* GSF_INDUSTRIES */   IndustriesChangeInfo,
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2133
		/* 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
  2134
		/* GSF_SOUNDFX */      SoundEffectChangeInfo,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2135
	};
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  2136
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
  2137
	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
  2138
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2139
	uint8 feature  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2140
	uint8 numprops = grf_load_byte(&buf);
6614
b41f2210a494 (svn r9108) -Fix(9093) : MSVC was a bit unhappy with some of the type changes. So basically, widening the types makes the difference
belugas
parents: 6610
diff changeset
  2141
	uint numinfo  = grf_load_byte(&buf);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2142
	uint engine   = grf_load_extended(&buf);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  2143
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2144
	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
  2145
	               feature, numprops, engine, numinfo);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
  2146
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
  2147
	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
  2148
		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
  2149
		return;
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  2150
	}
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  2151
2439
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  2152
	if (feature <= GSF_AIRCRAFT) {
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  2153
		if (engine + numinfo > _vehcounts[feature]) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2154
			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
  2155
			return;
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  2156
		}
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  2157
	}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2158
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2159
	while (numprops-- && buf < bufend) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2160
		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
  2161
		bool ignoring = false;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2162
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2163
		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
  2164
			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
  2165
			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
  2166
			case GSF_SHIP:
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2167
			case GSF_AIRCRAFT: {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2168
				bool handled = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2169
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2170
				for (uint i = 0; i < numinfo; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2171
					EngineInfo *ei = &_engine_info[engine + _vehshifts[feature] + i];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2172
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2173
					/* Common properties for vehicles */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2174
					switch (prop) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2175
						case 0x00: // Introduction date
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2176
							ei->base_intro = grf_load_word(&buf) + DAYS_TILL_ORIGINAL_BASE_YEAR;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2177
							break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2178
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2179
						case 0x02: // Decay speed
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2180
							SB(ei->unk2, 0, 7, grf_load_byte(&buf) & 0x7F);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2181
							break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2182
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2183
						case 0x03: // Vehicle life
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2184
							ei->lifelength = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2185
							break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2186
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2187
						case 0x04: // Model life
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2188
							ei->base_life = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2189
							break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2190
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2191
						case 0x06: // Climates available
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2192
							ei->climates = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2193
							break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2194
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2195
						case 0x07: // Loading speed
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2196
							/* Hyronymus explained me what does
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2197
							 * this mean and insists on having a
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2198
							 * credit ;-). --pasky */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2199
							ei->load_amount = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2200
							break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2201
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2202
						default:
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2203
							handled = false;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2204
							break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2205
					}
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2206
				}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2207
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2208
				if (handled) break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2209
			} /* FALL THROUGH */
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2210
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2211
			default:
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2212
				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
  2213
					ignoring = true;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2214
				}
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2215
				break;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2216
		}
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2217
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  2218
		if (ignoring) grfmsg(1, "FeatureChangeInfo: Ignoring property 0x%02X of feature 0x%02X (not implemented)", prop, feature);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2219
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2220
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2221
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
  2222
/* 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
  2223
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
  2224
{
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
  2225
	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
  2226
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2227
	uint8 feature  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2228
	uint8 numprops = grf_load_byte(&buf);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2229
	grf_load_byte(&buf);     // num-info
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2230
	grf_load_extended(&buf); // id
5776
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2231
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
  2232
	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
  2233
		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
  2234
		/* 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
  2235
		 * 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
  2236
		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
  2237
	}
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
  2238
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2239
	SetBit(_cur_grfconfig->flags, GCF_UNSAFE);
5776
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2240
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
  2241
	/* 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
  2242
	_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
  2243
}
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
  2244
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2245
/* Action 0x00 (GLS_RESERVE) */
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2246
static void ReserveChangeInfo(byte *buf, int len)
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2247
{
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2248
	byte *bufend = buf + len;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2249
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2250
	if (!check_length(len, 6, "InitChangeInfo")) return;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2251
	buf++;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2252
	uint8 feature  = grf_load_byte(&buf);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2253
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2254
	if (feature != GSF_CARGOS && feature != GSF_GLOBALVAR) return;
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2255
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2256
	uint8 numprops = grf_load_byte(&buf);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2257
	uint8 numinfo  = grf_load_byte(&buf);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2258
	uint8 index    = grf_load_extended(&buf);
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2259
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2260
	while (numprops-- && buf < bufend) {
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2261
		uint8 prop = grf_load_byte(&buf);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2262
		bool ignoring = false;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2263
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2264
		switch (feature) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2265
			default: NOT_REACHED();
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2266
			case GSF_CARGOS:
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2267
				ignoring = CargoChangeInfo(index, numinfo, prop, &buf, bufend - buf);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2268
				break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2269
			case GSF_GLOBALVAR:
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2270
				ignoring = GlobalVarChangeInfo(index, numinfo, prop, &buf, bufend - buf);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2271
				break;
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2272
		}
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2273
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2274
		if (ignoring) grfmsg(2, "ReserveChangeInfo: Ignoring property 0x%02X (not implemented)", prop);
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2275
	}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2276
}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2277
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2278
/**
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2279
 * Creates a spritegroup representing a callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2280
 * @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
  2281
 * @return A spritegroup representing that callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2282
 */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  2283
static const SpriteGroup* NewCallBackResultSpriteGroup(uint16 value)
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2284
{
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  2285
	SpriteGroup *group = AllocateSpriteGroup();
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2286
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  2287
	group->type = SGT_CALLBACK;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2288
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  2289
	/* Old style callback results have the highest byte 0xFF so signify it is a callback result
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  2290
	 * 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
  2291
	if ((value >> 8) == 0xFF) {
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  2292
		value &= ~0xFF00;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  2293
	} else {
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2294
		value &= ~0x8000;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  2295
	}
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2296
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  2297
	group->g.callback.result = value;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2298
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2299
	return group;
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2300
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2301
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
  2302
/**
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
  2303
 * Creates a spritegroup representing a sprite number result.
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2304
 * @param sprite The sprite number.
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2305
 * @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
  2306
 * @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
  2307
 */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  2308
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
  2309
{
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  2310
	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
  2311
	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
  2312
	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
  2313
	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
  2314
	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
  2315
}
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
  2316
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2317
/* 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
  2318
static void NewSpriteSet(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2319
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2320
	/* <01> <feature> <num-sets> <num-ent>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2321
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2322
	 * B feature       feature to define sprites for
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2323
	 *                 0, 1, 2, 3: veh-type, 4: train stations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2324
	 * B num-sets      number of sprite sets
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2325
	 * 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
  2326
	 *                 For vehicles, this is the number of different
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2327
	 *                         vehicle directions in each sprite set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2328
	 *                         Set num-dirs=8, unless your sprites are symmetric.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2329
	 *                         In that case, use num-dirs=4.
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2330
	 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2331
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
  2332
	if (!check_length(len, 4, "NewSpriteSet")) return;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2333
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2334
	uint8 feature   = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2335
	uint8 num_sets  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2336
	uint16 num_ents = grf_load_extended(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2337
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
  2338
	_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
  2339
	_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
  2340
	_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
  2341
	_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
  2342
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2343
	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
  2344
		_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
  2345
	);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2346
6614
b41f2210a494 (svn r9108) -Fix(9093) : MSVC was a bit unhappy with some of the type changes. So basically, widening the types makes the difference
belugas
parents: 6610
diff changeset
  2347
	for (uint16 i = 0; i < num_sets * num_ents; i++) {
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  2348
		_nfo_line++;
9628
b5c2449616b5 (svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents: 9627
diff changeset
  2349
		LoadNextSprite(_cur_spriteid++, _file_index, _nfo_line);
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2350
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2351
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2352
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2353
/* Action 0x01 (SKIP) */
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2354
static void SkipAct1(byte *buf, int len)
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2355
{
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2356
	if (!check_length(len, 4, "SkipAct1")) return;
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2357
	buf++;
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2358
	grf_load_byte(&buf);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2359
	uint8 num_sets  = grf_load_byte(&buf);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2360
	uint16 num_ents = grf_load_extended(&buf);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2361
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2362
	_skip_sprites = num_sets * num_ents;
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2363
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2364
	grfmsg(3, "SkipAct1: Skipping %d sprites", _skip_sprites);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2365
}
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2366
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
  2367
/* 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
  2368
 * defined spritegroup. */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  2369
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
  2370
{
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2371
	if (HasBit(groupid, 15)) return NewCallBackResultSpriteGroup(groupid);
3666
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  2372
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
  2373
	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2374
		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
  2375
		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
  2376
	}
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
  2377
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
  2378
	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
  2379
}
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
  2380
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
  2381
/* 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
  2382
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
  2383
{
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2384
	if (HasBit(spriteid, 15)) return NewCallBackResultSpriteGroup(spriteid);
3666
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  2385
3667
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  2386
	if (spriteid >= _cur_grffile->spriteset_numsets) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2387
		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
  2388
		return NULL;
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  2389
	}
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  2390
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
  2391
	/* 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
  2392
	 * 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
  2393
	 * 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
  2394
	if (_cur_grffile->spriteset_start + spriteid * num_sprites + num_sprites > _cur_spriteid) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2395
		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
  2396
				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
  2397
				_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
  2398
				_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
  2399
		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
  2400
	}
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
  2401
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  2402
	if (feature != _cur_grffile->spriteset_feature) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2403
		grfmsg(1, "CreateGroupFromGroupID(0x%02X:0x%02X): Sprite set feature 0x%02X does not match action feature 0x%02X, skipping",
9628
b5c2449616b5 (svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents: 9627
diff changeset
  2404
				setid, type,
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  2405
				_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
  2406
		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
  2407
	}
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  2408
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
  2409
	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
  2410
}
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
  2411
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2412
/* 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
  2413
static void NewSpriteGroup(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2414
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2415
	/* <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
  2416
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2417
	 * B feature       see action 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2418
	 * B set-id        ID of this particular definition
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2419
	 * B type/num-entries
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2420
	 *                 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
  2421
	 *                 list definition, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2422
	 *                 otherwise it specifies a number of entries, the exact
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2423
	 *                 meaning depends on the feature
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2424
	 * 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
  2425
	SpriteGroup *group = NULL;
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2426
	byte *bufend = buf + len;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  2427
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
  2428
	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
  2429
	buf++;
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2430
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2431
	uint8 feature = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2432
	uint8 setid   = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2433
	uint8 type    = grf_load_byte(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2434
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
  2435
	if (setid >= _cur_grffile->spritegroups_count) {
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  2436
		/* 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
  2437
		_cur_grffile->spritegroups = ReallocT(_cur_grffile->spritegroups, setid + 1);
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  2438
		/* 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
  2439
		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
  2440
			_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
  2441
	}
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
  2442
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2443
	switch (type) {
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2444
		/* Deterministic Sprite Group */
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2445
		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
  2446
		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
  2447
		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
  2448
		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
  2449
		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
  2450
		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
  2451
		{
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
  2452
			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
  2453
			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
  2454
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2455
			/* 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
  2456
			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
  2457
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2458
			group = AllocateSpriteGroup();
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2459
			group->type = SGT_DETERMINISTIC;
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2460
			group->g.determ.var_scope = HasBit(type, 1) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF;
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2461
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2462
			switch (GB(type, 2, 2)) {
3672
73caf2e829f8 (svn r4588) - NewGRF: silence a false compiler warning
peter1138
parents: 3668
diff changeset
  2463
				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
  2464
				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
  2465
				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
  2466
				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
  2467
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2468
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
  2469
			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
  2470
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2471
			/* 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
  2472
			 * 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
  2473
			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
  2474
				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
  2475
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2476
				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
  2477
					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
  2478
				}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2479
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2480
				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
  2481
				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
  2482
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2483
				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
  2484
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2485
				/* 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
  2486
				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
  2487
				adjust->variable  = grf_load_byte(&buf);
5868
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2488
				if (adjust->variable == 0x7E) {
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2489
					/* Link subroutine group */
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2490
					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
  2491
				} else {
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  2492
					adjust->parameter = IsInsideMM(adjust->variable, 0x60, 0x80) ? grf_load_byte(&buf) : 0;
5868
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2493
				}
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
  2494
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2495
				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
  2496
				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
  2497
				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
  2498
				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
  2499
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2500
				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
  2501
					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
  2502
					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
  2503
				} 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
  2504
					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
  2505
					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
  2506
				}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2507
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2508
				/* Continue reading var adjusts while bit 5 is set. */
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2509
			} while (HasBit(varadjust, 5));
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2510
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2511
			group->g.determ.num_ranges = grf_load_byte(&buf);
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  2512
			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
  2513
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
  2514
			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
  2515
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2516
			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
  2517
				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
  2518
				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
  2519
				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
  2520
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2521
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
  2522
			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
  2523
			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
  2524
		}
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
  2525
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2526
		/* Randomized Sprite Group */
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2527
		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
  2528
		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
  2529
		{
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
  2530
			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
  2531
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2532
			group = AllocateSpriteGroup();
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2533
			group->type = SGT_RANDOMIZED;
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2534
			group->g.random.var_scope = HasBit(type, 1) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF;
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2535
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2536
			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
  2537
			group->g.random.triggers       = GB(triggers, 0, 7);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2538
			group->g.random.cmp_mode       = HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2539
			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
  2540
			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
  2541
			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
  2542
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
  2543
			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
  2544
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2545
			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
  2546
				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
  2547
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2548
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2549
			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
  2550
		}
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2551
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
  2552
		/* 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
  2553
		default:
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2554
		{
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  2555
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  2556
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
  2557
			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
  2558
				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
  2559
				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
  2560
				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
  2561
				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
  2562
				case GSF_STATION:
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2563
				case GSF_CANAL:
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2564
				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
  2565
				{
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2566
					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
  2567
					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
  2568
					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
  2569
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2570
					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
  2571
						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
  2572
						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
  2573
					}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2574
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
  2575
					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
  2576
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2577
					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
  2578
					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
  2579
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2580
					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
  2581
					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
  2582
					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
  2583
					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
  2584
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2585
					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
  2586
							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
  2587
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2588
					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
  2589
						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
  2590
						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
  2591
						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
  2592
					}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2593
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2594
					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
  2595
						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
  2596
						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
  2597
						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
  2598
					}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2599
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2600
					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
  2601
				}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2602
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2603
				case GSF_TOWNHOUSE:
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2604
				case GSF_INDUSTRYTILES: {
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2605
					byte sprites     = _cur_grffile->spriteset_numents;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2606
					byte num_sprites = max((uint8)1, type);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2607
					uint i;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2608
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2609
					group = AllocateSpriteGroup();
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2610
					group->type = SGT_TILELAYOUT;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2611
					group->g.layout.num_sprites = sprites;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2612
					group->g.layout.dts = CallocT<DrawTileSprites>(1);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2613
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2614
					/* Groundsprite */
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2615
					group->g.layout.dts->ground_sprite = grf_load_word(&buf);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2616
					group->g.layout.dts->ground_pal    = grf_load_word(&buf);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2617
					/* Remap transparent/colour modifier bits */
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2618
					if (HasBit(group->g.layout.dts->ground_sprite, 14)) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2619
						ClrBit(group->g.layout.dts->ground_sprite, 14);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2620
						SetBit(group->g.layout.dts->ground_sprite, PALETTE_MODIFIER_TRANSPARENT);
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2621
					}
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2622
					if (HasBit(group->g.layout.dts->ground_sprite, 15)) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2623
						ClrBit(group->g.layout.dts->ground_sprite, 15);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2624
						SetBit(group->g.layout.dts->ground_sprite, PALETTE_MODIFIER_COLOR);
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2625
					}
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2626
					if (HasBit(group->g.layout.dts->ground_pal, 14)) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2627
						ClrBit(group->g.layout.dts->ground_pal, 14);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2628
						SetBit(group->g.layout.dts->ground_sprite, SPRITE_MODIFIER_OPAQUE);
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2629
					}
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2630
					if (HasBit(group->g.layout.dts->ground_pal, 15)) {
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2631
						/* Bit 31 set means this is a custom sprite, so rewrite it to the
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2632
						 * last spriteset defined. */
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2633
						SpriteID sprite = _cur_grffile->spriteset_start + GB(group->g.layout.dts->ground_sprite, 0, 14) * sprites;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2634
						SB(group->g.layout.dts->ground_sprite, 0, SPRITE_WIDTH, sprite);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2635
						ClrBit(group->g.layout.dts->ground_pal, 15);
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2636
					}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2637
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2638
					group->g.layout.dts->seq = CallocT<DrawTileSeqStruct>(num_sprites + 1);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2639
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2640
					for (i = 0; i < num_sprites; i++) {
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2641
						DrawTileSeqStruct *seq = (DrawTileSeqStruct*)&group->g.layout.dts->seq[i];
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2642
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2643
						seq->image = grf_load_word(&buf);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2644
						seq->pal   = grf_load_word(&buf);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2645
						seq->delta_x = grf_load_byte(&buf);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2646
						seq->delta_y = grf_load_byte(&buf);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2647
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2648
						if (HasBit(seq->image, 14)) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2649
							ClrBit(seq->image, 14);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2650
							SetBit(seq->image, PALETTE_MODIFIER_TRANSPARENT);
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2651
						}
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2652
						if (HasBit(seq->image, 15)) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2653
							ClrBit(seq->image, 15);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2654
							SetBit(seq->image, PALETTE_MODIFIER_COLOR);
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2655
						}
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2656
						if (HasBit(seq->pal, 14)) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2657
							ClrBit(seq->pal, 14);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2658
							SetBit(seq->image, SPRITE_MODIFIER_OPAQUE);
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2659
						}
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2660
						if (HasBit(seq->pal, 15)) {
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2661
							/* Bit 31 set means this is a custom sprite, so rewrite it to the
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2662
							 * last spriteset defined. */
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2663
							SpriteID sprite = _cur_grffile->spriteset_start + GB(seq->image, 0, 14) * sprites;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2664
							SB(seq->image, 0, SPRITE_WIDTH, sprite);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  2665
							ClrBit(seq->pal, 15);
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2666
						}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2667
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2668
						if (type > 0) {
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2669
							seq->delta_z = grf_load_byte(&buf);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2670
							if ((byte)seq->delta_z == 0x80) continue;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2671
						}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2672
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2673
						seq->size_x = grf_load_byte(&buf);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2674
						seq->size_y = grf_load_byte(&buf);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2675
						seq->size_z = grf_load_byte(&buf);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2676
					}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2677
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2678
					/* Set the terminator value. */
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2679
					((DrawTileSeqStruct*)group->g.layout.dts->seq)[i].delta_x = (byte)0x80;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2680
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2681
					break;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2682
				}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  2683
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2684
				case GSF_INDUSTRIES: {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2685
					if (type > 1) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2686
						grfmsg(1, "NewSpriteGroup: Unsupported industry production version %d, skipping", type);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2687
						break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2688
					}
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2689
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2690
					group = AllocateSpriteGroup();
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2691
					group->type = SGT_INDUSTRY_PRODUCTION;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2692
					group->g.indprod.version = type;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2693
					if (type == 0) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2694
						for (uint i = 0; i < 3; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2695
							group->g.indprod.substract_input[i] = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2696
						}
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2697
						for (uint i = 0; i < 2; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2698
							group->g.indprod.add_output[i] = grf_load_word(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2699
						}
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2700
						group->g.indprod.again = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2701
					} else {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2702
						for (uint i = 0; i < 3; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2703
							group->g.indprod.substract_input[i] = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2704
						}
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2705
						for (uint i = 0; i < 2; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2706
							group->g.indprod.add_output[i] = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2707
						}
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2708
						group->g.indprod.again = grf_load_byte(&buf);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2709
					}
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2710
					break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2711
				}
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  2712
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
  2713
				/* 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
  2714
				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
  2715
			}
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
  2716
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2717
	}
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
  2718
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
  2719
	_cur_grffile->spritegroups[setid] = group;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2720
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2721
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2722
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
  2723
{
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2724
	/* 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
  2725
	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
  2726
	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
  2727
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2728
	if (_cur_grffile->cargo_max == 0) {
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2729
		/* No cargo table, so use bitnum values */
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2730
		if (ctype >= 32) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2731
			grfmsg(1, "TranslateCargo: Cargo bitnum %d out of range (max 31), skipping.", ctype);
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2732
			return CT_INVALID;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2733
		}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2734
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2735
		for (CargoID c = 0; c < NUM_CARGO; c++) {
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2736
			const CargoSpec *cs = GetCargo(c);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2737
			if (!cs->IsValid()) continue;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2738
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2739
			if (cs->bitnum == ctype) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2740
				grfmsg(6, "TranslateCargo: Cargo bitnum %d mapped to cargo type %d.", ctype, c);
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2741
				return c;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2742
			}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2743
		}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2744
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2745
		grfmsg(5, "TranslateCargo: Cargo bitnum %d not available in this climate, skipping.", ctype);
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2746
		return CT_INVALID;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2747
	}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2748
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2749
	/* Check if the cargo type is out of bounds of the cargo translation table */
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2750
	if (ctype >= _cur_grffile->cargo_max) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2751
		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
  2752
		return CT_INVALID;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2753
	}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2754
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2755
	/* Look up the cargo label from the translation table */
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2756
	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
  2757
	if (cl == 0) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2758
		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
  2759
		return CT_INVALID;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2760
	}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2761
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2762
	ctype = GetCargoIDByLabel(cl);
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2763
	if (ctype == CT_INVALID) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2764
		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
  2765
		return CT_INVALID;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2766
	}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2767
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2768
	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
  2769
	return ctype;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2770
}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2771
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2772
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2773
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
  2774
{
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  2775
	static EngineID *last_engines;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  2776
	static uint last_engines_count;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2777
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2778
	if (!wagover) {
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2779
		if (last_engines_count != idcount) {
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2780
			last_engines = ReallocT(last_engines, idcount);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2781
			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
  2782
		}
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2783
	} else {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2784
		if (last_engines_count == 0) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2785
			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
  2786
			return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2787
		}
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2788
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2789
		grfmsg(6, "VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons",
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2790
				last_engines_count, idcount);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2791
	}
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
  2792
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2793
	for (uint i = 0; i < idcount; i++) {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2794
		uint8 engine_id = buf[3 + i];
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2795
		uint8 engine = engine_id + _vehshifts[feature];
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2796
		byte *bp = &buf[4 + idcount];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2797
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2798
		if (engine_id > _vehcounts[feature]) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2799
			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
  2800
			return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2801
		}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2802
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2803
		grfmsg(7, "VehicleMapSpriteGroup: [%d] Engine %d...", i, engine);
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2804
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2805
		for (uint c = 0; c < cidcount; c++) {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2806
			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
  2807
			uint16 groupid = grf_load_word(&bp);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2808
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2809
			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
  2810
2516
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  2811
			if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2812
				grfmsg(1, "VehicleMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping", groupid, _cur_grffile->spritegroups_count);
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2813
				continue;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2814
			}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2815
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2816
			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
  2817
			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
  2818
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2819
			if (wagover) {
4869
cded5f3a83c9 (svn r6795) - NewGRF: Add support for cargo-specific wagon overrides.
peter1138
parents: 4818
diff changeset
  2820
				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
  2821
			} 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
  2822
				SetCustomEngineSprites(engine, ctype, _cur_grffile->spritegroups[groupid]);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2823
				last_engines[i] = engine;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2824
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2825
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2826
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2827
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2828
	{
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2829
		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
  2830
		uint16 groupid = grf_load_word(&bp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2831
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2832
		grfmsg(8, "-- Default group id 0x%04X", groupid);
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2833
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2834
		for (uint i = 0; i < idcount; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2835
			uint8 engine = buf[3 + i] + _vehshifts[feature];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2836
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  2837
			/* 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
  2838
			if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  2839
				grfmsg(1, "VehicleMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping",
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2840
				       groupid, _cur_grffile->spritegroups_count);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2841
				continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2842
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2843
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2844
			if (wagover) {
3695
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  2845
				/* If the ID for this action 3 is the same as the vehicle ID,
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2846
 * 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
  2847
				if (feature == GSF_AIRCRAFT && engine == last_engines[i]) {
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  2848
					SetRotorOverrideSprites(engine, _cur_grffile->spritegroups[groupid]);
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  2849
				} else {
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  2850
					/* 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
  2851
					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
  2852
				}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2853
			} 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
  2854
				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
  2855
				SetEngineGRF(engine, _cur_grffile);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2856
				last_engines[i] = engine;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2857
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2858
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2859
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2860
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2861
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2862
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2863
static void CanalMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2864
{
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2865
	byte *bp = &buf[4 + idcount + cidcount * 3];
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2866
	uint16 groupid = grf_load_word(&bp);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2867
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2868
	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2869
		grfmsg(1, "CanalMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.",
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2870
		       groupid, _cur_grffile->spritegroups_count);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2871
		return;
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2872
	}
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2873
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2874
	for (uint i = 0; i < idcount; i++) {
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2875
		CanalFeature cf = (CanalFeature)buf[3 + i];
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2876
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2877
		if (cf >= CF_END) {
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2878
			grfmsg(1, "CanalMapSpriteGroup: Canal subset %d out of range, skipping", cf);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2879
			continue;
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2880
		}
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2881
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2882
		_canal_sg[cf] = _cur_grffile->spritegroups[groupid];
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2883
	}
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2884
}
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2885
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  2886
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2887
static void StationMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2888
{
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2889
	for (uint i = 0; i < idcount; i++) {
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2890
		uint8 stid = buf[3 + i];
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2891
		StationSpec *statspec = _cur_grffile->stations[stid];
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  2892
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  2893
		if (statspec == NULL) {
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  2894
			grfmsg(1, "StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stid);
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  2895
			return;
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  2896
		}
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  2897
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2898
		byte *bp = &buf[4 + idcount];
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2899
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2900
		for (uint c = 0; c < cidcount; c++) {
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2901
			uint8 ctype = grf_load_byte(&bp);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2902
			uint16 groupid = grf_load_word(&bp);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2903
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2904
			if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2905
				grfmsg(1, "StationMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping",
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2906
				       groupid, _cur_grffile->spritegroups_count);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2907
				continue;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2908
			}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2909
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2910
			ctype = TranslateCargo(GSF_STATION, ctype);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2911
			if (ctype == CT_INVALID) continue;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2912
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2913
			statspec->spritegroup[ctype] = _cur_grffile->spritegroups[groupid];
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2914
		}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2915
	}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2916
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2917
	{
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2918
		byte *bp = &buf[4 + idcount + cidcount * 3];
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2919
		uint16 groupid = grf_load_word(&bp);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2920
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2921
		if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2922
			grfmsg(1, "StationMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping",
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2923
			       groupid, _cur_grffile->spritegroups_count);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2924
			return;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2925
		}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2926
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2927
		for (uint i = 0; i < idcount; i++) {
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2928
			uint8 stid = buf[3 + i];
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2929
			StationSpec *statspec = _cur_grffile->stations[stid];
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  2930
			if (statspec == NULL) {
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  2931
				grfmsg(1, "StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stid);
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  2932
				continue;
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  2933
			}
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2934
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2935
			statspec->spritegroup[CT_DEFAULT] = _cur_grffile->spritegroups[groupid];
9599
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
  2936
			statspec->grffile = _cur_grffile;
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2937
			statspec->localidx = stid;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2938
			SetCustomStationSpec(statspec);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2939
		}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2940
	}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2941
}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2942
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2943
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2944
static void TownHouseMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2945
{
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2946
	byte *bp = &buf[4 + idcount + cidcount * 3];
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2947
	uint16 groupid = grf_load_word(&bp);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2948
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2949
	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2950
		grfmsg(1, "TownHouseMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.",
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2951
		       groupid, _cur_grffile->spritegroups_count);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2952
		return;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2953
	}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2954
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2955
	for (uint i = 0; i < idcount; i++) {
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2956
		uint8 hid = buf[3 + i];
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2957
		HouseSpec *hs = _cur_grffile->housespec[hid];
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2958
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2959
		if (hs == NULL) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  2960
			grfmsg(1, "TownHouseMapSpriteGroup: Too many houses defined, skipping");
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2961
			return;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2962
		}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2963
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2964
		hs->spritegroup = _cur_grffile->spritegroups[groupid];
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2965
	}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2966
}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  2967
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2968
static void IndustryMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2969
{
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2970
	byte *bp = &buf[4 + idcount + cidcount * 3];
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2971
	uint16 groupid = grf_load_word(&bp);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2972
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2973
	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2974
		grfmsg(1, "IndustryMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.",
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2975
		       groupid, _cur_grffile->spritegroups_count);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2976
		return;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2977
	}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2978
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2979
	for (uint i = 0; i < idcount; i++) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2980
		uint8 id = buf[3 + i];
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2981
		IndustrySpec *indsp = _cur_grffile->industryspec[id];
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2982
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2983
		if (indsp == NULL) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2984
			grfmsg(1, "IndustryMapSpriteGroup: Too many industries defined, skipping");
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2985
			return;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2986
		}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2987
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2988
		indsp->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid];
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2989
	}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2990
}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2991
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2992
static void IndustrytileMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2993
{
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2994
	byte *bp = &buf[4 + idcount + cidcount * 3];
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2995
	uint16 groupid = grf_load_word(&bp);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2996
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2997
	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2998
		grfmsg(1, "IndustrytileMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.",
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  2999
		       groupid, _cur_grffile->spritegroups_count);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3000
		return;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3001
	}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3002
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3003
	for (uint i = 0; i < idcount; i++) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3004
		uint8 id = buf[3 + i];
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3005
		IndustryTileSpec *indtsp = _cur_grffile->indtspec[id];
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3006
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3007
		if (indtsp == NULL) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3008
			grfmsg(1, "IndustrytileMapSpriteGroup: Too many industry tiles defined, skipping");
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3009
			return;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3010
		}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3011
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3012
		indtsp->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid];
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3013
	}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3014
}
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3015
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3016
static void CargoMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3017
{
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3018
	byte *bp = &buf[4 + idcount + cidcount * 3];
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3019
	uint16 groupid = grf_load_word(&bp);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3020
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3021
	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3022
		grfmsg(1, "CargoMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.",
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3023
		       groupid, _cur_grffile->spritegroups_count);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3024
		return;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3025
	}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3026
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3027
	for (uint i = 0; i < idcount; i++) {
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3028
		CargoID cid = buf[3 + i];
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3029
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3030
		if (cid >= NUM_CARGO) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3031
			grfmsg(1, "CargoMapSpriteGroup: Cargo ID %d out of range, skipping");
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3032
			continue;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3033
		}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3034
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3035
		CargoSpec *cs = &_cargo[cid];
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3036
		cs->grfid = _cur_grffile->grfid;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3037
		cs->group = _cur_grffile->spritegroups[groupid];
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3038
	}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3039
}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3040
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3041
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3042
/* Action 0x03 */
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3043
static void FeatureMapSpriteGroup(byte *buf, int len)
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3044
{
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3045
	/* <03> <feature> <n-id> <ids>... <num-cid> [<cargo-type> <cid>]... <def-cid>
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3046
	 * id-list    := [<id>] [id-list]
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3047
	 * cargo-list := <cargo-type> <cid> [cargo-list]
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3048
	 *
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3049
	 * B feature       see action 0
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3050
	 * B n-id          bits 0-6: how many IDs this definition applies to
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3051
	 *                 bit 7: if set, this is a wagon override definition (see below)
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3052
	 * B ids           the IDs for which this definition applies
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3053
	 * B num-cid       number of cargo IDs (sprite group IDs) in this definition
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3054
	 *                 can be zero, in that case the def-cid is used always
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3055
	 * B cargo-type    type of this cargo type (e.g. mail=2, wood=7, see below)
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3056
	 * W cid           cargo ID (sprite group ID) for this type of cargo
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3057
	 * W def-cid       default cargo ID (sprite group ID) */
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3058
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3059
	if (!check_length(len, 6, "FeatureMapSpriteGroup")) return;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3060
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3061
	uint8 feature = buf[1];
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3062
	uint8 idcount = buf[2] & 0x7F;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3063
	bool wagover = (buf[2] & 0x80) == 0x80;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3064
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3065
	if (!check_length(len, 3 + idcount, "FeatureMapSpriteGroup")) return;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3066
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3067
	/* If idcount is zero, this is a feature callback */
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3068
	if (idcount == 0) {
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3069
		grfmsg(2, "FeatureMapSpriteGroup: Feature callbacks not implemented yet");
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3070
		return;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3071
	}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3072
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3073
	uint8 cidcount = buf[3 + idcount];
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3074
	if (!check_length(len, 4 + idcount + cidcount * 3, "FeatureMapSpriteGroup")) return;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3075
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3076
	grfmsg(6, "FeatureMapSpriteGroup: Feature %d, %d ids, %d cids, wagon override %d",
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3077
			feature, idcount, cidcount, wagover);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3078
9704
197cb8c6ae17 (svn r11221) [NoAI] -Sync: with trunk r11145:11220
glx
parents: 9703
diff changeset
  3079
	if (_cur_grffile->spritegroups == 0) {
197cb8c6ae17 (svn r11221) [NoAI] -Sync: with trunk r11145:11220
glx
parents: 9703
diff changeset
  3080
		grfmsg(1, "FeatureMapSpriteGroup: No sprite groups to work on! Skipping");
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3081
		return;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3082
	}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3083
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3084
	switch (feature) {
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3085
		case GSF_TRAIN:
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3086
		case GSF_ROAD:
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3087
		case GSF_SHIP:
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3088
		case GSF_AIRCRAFT:
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3089
			VehicleMapSpriteGroup(buf, feature, idcount, cidcount, wagover);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3090
			return;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3091
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3092
		case GSF_CANAL:
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3093
			CanalMapSpriteGroup(buf, idcount, cidcount);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3094
			return;
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3095
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3096
		case GSF_STATION:
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3097
			StationMapSpriteGroup(buf, idcount, cidcount);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3098
			return;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3099
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3100
		case GSF_TOWNHOUSE:
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3101
			TownHouseMapSpriteGroup(buf, idcount, cidcount);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3102
			return;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3103
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3104
		case GSF_INDUSTRIES:
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3105
			IndustryMapSpriteGroup(buf, idcount, cidcount);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3106
			return;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3107
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3108
		case GSF_INDUSTRYTILES:
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3109
			IndustrytileMapSpriteGroup(buf, idcount, cidcount);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3110
			return;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  3111
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3112
		case GSF_CARGOS:
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3113
			CargoMapSpriteGroup(buf, idcount, cidcount);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3114
			return;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3115
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3116
		default:
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3117
			grfmsg(1, "FeatureMapSpriteGroup: Unsupported feature %d, skipping", feature);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3118
			return;
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3119
	}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3120
}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  3121
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3122
/* Action 0x04 */
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  3123
static void FeatureNewName(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3124
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3125
	/* <04> <veh-type> <language-id> <num-veh> <offset> <data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3126
	 *
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3127
	 * B veh-type      see action 0 (as 00..07, + 0A
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3128
	 *                 But IF veh-type = 48, then generic text
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3129
	 * 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
  3130
	                   with up to 64 language.
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3131
	                   Otherwise, it is a mapping where set bits have meaning
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3132
	                   0 = american, 1 = english, 2 = german, 3 = french, 4 = spanish
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3133
	                   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
  3134
	 * 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
  3135
	 * 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
  3136
	 *                 Byte : ID of vehicle to change
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3137
	 *                 Word : ID of string to change/add
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3138
	 * 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
  3139
	 *                 which the next name begins. */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3140
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
  3141
	bool new_scheme = _cur_grffile->grf_version >= 7;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3142
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
  3143
	if (!check_length(len, 6, "FeatureNewName")) return;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  3144
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3145
	uint8 feature  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3146
	uint8 lang     = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3147
	uint8 num      = grf_load_byte(&buf);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3148
	bool generic   = HasBit(lang, 7);
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3149
	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
  3150
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3151
	ClrBit(lang, 7);
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  3152
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
  3153
	if (feature <= GSF_AIRCRAFT && id < _vehcounts[feature]) {
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3154
		id += _vehshifts[feature];
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  3155
	}
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3156
	uint16 endid = id + num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3157
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3158
	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
  3159
	               id, endid, feature, lang);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  3160
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
  3161
	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
  3162
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3163
	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
  3164
		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
  3165
		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
  3166
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
  3167
		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
  3168
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3169
		grfmsg(8, "FeatureNewName: 0x%04X <- %s", id, name);
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3170
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3171
		switch (feature) {
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3172
			case GSF_TRAIN:
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3173
			case GSF_ROAD:
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3174
			case GSF_SHIP:
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3175
			case GSF_AIRCRAFT:
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3176
				if (id < TOTAL_NUM_ENGINES) {
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3177
					StringID string = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_8000_KIRBY_PAUL_TANK_STEAM + id);
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3178
					SetCustomEngineName(id, string);
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3179
				} else {
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3180
					AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, id);
3614
2c75299f54bd (svn r4510) - NewGRF bounds checking:
peter1138
parents: 3604
diff changeset
  3181
				}
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3182
				break;
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3183
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  3184
			case GSF_INDUSTRIES: {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  3185
				AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  3186
				break;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  3187
			}
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  3188
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3189
			case GSF_TOWNHOUSE:
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3190
			default:
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3191
				switch (GB(id, 8, 8)) {
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3192
					case 0xC4: // Station class name
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3193
						if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3194
							grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3195
						} else {
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3196
							StationClassID sclass = _cur_grffile->stations[GB(id, 0, 8)]->sclass;
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3197
							SetStationClassName(sclass, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED));
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  3198
						}
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3199
						break;
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3200
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3201
					case 0xC5: // Station name
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3202
						if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3203
							grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3204
						} else {
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3205
							_cur_grffile->stations[GB(id, 0, 8)]->name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3206
						}
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3207
						break;
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3208
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3209
					case 0xC9: // House name
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3210
						if (_cur_grffile->housespec == NULL || _cur_grffile->housespec[GB(id, 0, 8)] == NULL) {
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3211
							grfmsg(1, "FeatureNewName: Attempt to name undefined house 0x%X, ignoring.", GB(id, 0, 8));
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3212
						} else {
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3213
							_cur_grffile->housespec[GB(id, 0, 8)]->building_name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3214
						}
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3215
						break;
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3216
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3217
					case 0xD0:
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3218
					case 0xDC:
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3219
						AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3220
						break;
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3221
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3222
					default:
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3223
						grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id);
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3224
						break;
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3225
				}
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3226
				break;
3642
a247e07fafdf (svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents: 3641
diff changeset
  3227
a247e07fafdf (svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents: 3641
diff changeset
  3228
#if 0
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3229
				case GSF_CANAL :
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3230
				case GSF_BRIDGE :
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3231
					AddGRFString(_cur_spriteid, id, lang, name);
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3232
					switch (GB(id, 8, 8)) {
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3233
						case 0xC9: // House name
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3234
						default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3235
							grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3236
					}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3237
					break;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3238
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3239
				default :
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3240
					grfmsg(7, "FeatureNewName: Unsupported feature (0x%02X)", feature);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3241
					break;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3242
#endif
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  3243
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3244
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3245
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3246
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3247
/**
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3248
 * Sanitize incoming sprite offsets for Action 5 graphics replacements.
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3249
 * @param num         the number of sprites to load.
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3250
 * @param offset      offset from the base.
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3251
 * @param max_sprites the maximum number of sprites that can be loaded in this action 5.
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3252
 * @param name        used for error warnings.
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3253
 * @return the number of sprites that is going to be skipped
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3254
 */
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3255
static uint16 SanitizeSpriteOffset(uint16& num, uint16 offset, int max_sprites, const char *name)
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3256
{
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3257
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3258
	if (offset >= max_sprites) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3259
		grfmsg(1, "GraphicsNew: %s sprite offset must be less than %i, skipping", name, max_sprites);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3260
		uint orig_num = num;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3261
		num = 0;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3262
		return orig_num;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3263
	}
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3264
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3265
	if (offset + num > max_sprites) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3266
		grfmsg(4, "GraphicsNew: %s sprite overflow, truncating...", name);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3267
		uint orig_num = num;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3268
		num = max(max_sprites - offset, 0);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3269
		return orig_num - num;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3270
	}
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3271
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3272
	return 0;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3273
}
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3274
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3275
/** Allows to reposition the loaded sprite to its correct placment.
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3276
 * @param load_index SpriteID of the sprite to be relocated */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3277
static inline void TranslateShoreSprites(SpriteID load_index)
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3278
{
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3279
	/** Contains the displacement required for the corresponding initial sprite*/
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3280
	static const SpriteID shore_dup[8] = {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3281
		SPR_SHORE_BASE +  4,  ///< 4062
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3282
		SPR_SHORE_BASE +  1,  ///< 4063
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3283
		SPR_SHORE_BASE +  2,  ///< 4064
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3284
		SPR_SHORE_BASE +  8,  ///< 4065
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3285
		SPR_SHORE_BASE +  6,  ///< 4066
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3286
		SPR_SHORE_BASE + 12,  ///< 4067
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3287
		SPR_SHORE_BASE +  3,  ///< 4068
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3288
		SPR_SHORE_BASE +  9,  ///< 4069
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3289
	};
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3290
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3291
	DupSprite(load_index, shore_dup[load_index - SPR_ORIGINALSHORE_START]);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3292
}
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3293
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3294
/* Action 0x05 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3295
static void GraphicsNew(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3296
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3297
	/* <05> <graphics-type> <num-sprites> <other data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3298
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3299
	 * 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
  3300
	 * 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
  3301
	 * V other data    Graphics type specific data.  Currently unused. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3302
	/* TODO */
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3303
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
  3304
	SpriteID replace = 0;
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3305
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
  3306
	if (!check_length(len, 2, "GraphicsNew")) return;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  3307
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3308
	uint8 type = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3309
	uint16 num = grf_load_extended(&buf);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3310
	uint16 skip_num = 0;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3311
	uint16 offset = HasBit(type, 7) ? grf_load_extended(&buf) : 0;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3312
	ClrBit(type, 7); // Clear the high bit as that only indicates whether there is an offset.
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3313
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
  3314
	switch (type) {
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3315
		case 0x04: // Signal graphics
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3316
			if (num != PRESIGNAL_SPRITE_COUNT && num != PRESIGNAL_AND_SEMAPHORE_SPRITE_COUNT && num != PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3317
				grfmsg(1, "GraphicsNew: Signal graphics sprite count must be 48, 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
  3318
				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
  3319
			}
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3320
			replace = SPR_SIGNALS_BASE;
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
  3321
			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
  3322
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3323
		case 0x05: // Catenary graphics
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3324
			if (num != ELRAIL_SPRITE_COUNT) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3325
				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
  3326
				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
  3327
			}
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3328
			replace = SPR_ELRAIL_BASE;
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
  3329
			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
  3330
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3331
		case 0x06: // Foundations
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3332
			if (num != NORMAL_FOUNDATION_SPRITE_COUNT && num != NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3333
				grfmsg(1, "GraphicsNew: Foundation graphics sprite count must be 74 or 90, skipping");
3709
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  3334
				return;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  3335
			}
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3336
			replace = SPR_SLOPES_BASE; break;
3709
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  3337
			break;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  3338
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3339
		/* case 0x07: // TTDP GUI sprites. Not used by OTTD. */
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3340
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3341
		case 0x08: // Canal graphics
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3342
			if (num != CANALS_SPRITE_COUNT) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3343
				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
  3344
				return;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  3345
			}
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3346
			replace = SPR_CANALS_BASE;
3709
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  3347
			break;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  3348
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  3349
		case 0x09: // One way graphics
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3350
			if (num != ONEWAY_SPRITE_COUNT) {
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  3351
				grfmsg(1, "GraphicsNew: One way road graphics sprite count must be 6, skipping");
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  3352
				return;
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  3353
			}
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  3354
			replace = SPR_ONEWAY_BASE;
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  3355
			break;
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  3356
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3357
		case 0x0A: // 2CC colour maps
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3358
			if (num != TWOCCMAP_SPRITE_COUNT) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3359
				grfmsg(1, "GraphicsNew: 2CC colour maps sprite count must be 256, skipping");
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3360
				return;
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3361
			}
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3362
			replace = SPR_2CCMAP_BASE;
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3363
			break;
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3364
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  3365
		case 0x0B: // tramways
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3366
			if (num != TRAMWAY_SPRITE_COUNT) {
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  3367
				grfmsg(1, "GraphicsNew: Tramway graphics sprite count must be 113, skipping");
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  3368
				return;
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  3369
			}
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  3370
			replace = SPR_TRAMWAY_BASE;
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  3371
			break;
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  3372
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3373
		/* case 0x0C: // Snowy temperate trees. Not yet used by OTTD. */
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3374
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3375
		case 0x0D: // Coast graphics
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3376
			switch (num) {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3377
				case 10:
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3378
					if (!_cur_grffile->is_ottdfile) {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3379
						grfmsg(2, "GraphicsNew: feature is reserved only for OpenTTD, skipping");
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3380
						return;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3381
					}
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3382
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3383
					/* openttd(d/w).grf missing shore sprites and initialisation of SPR_SHORE_BASE */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3384
					LoadNextSprite(      SPR_SHORE_BASE +  0, _file_index, _nfo_line++); // SLOPE_STEEP_S
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3385
					TranslateShoreSprites(SPR_ORIGINALSHORE_START + 1); // SLOPE_W
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3386
					TranslateShoreSprites(SPR_ORIGINALSHORE_START + 2); // SLOPE_S
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3387
					TranslateShoreSprites(SPR_ORIGINALSHORE_START + 6); // SLOPE_SW
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3388
					TranslateShoreSprites(SPR_ORIGINALSHORE_START); // SLOPE_E
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3389
					LoadNextSprite(      SPR_SHORE_BASE +  5, _file_index, _nfo_line++); // SLOPE_STEEP_W
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3390
					TranslateShoreSprites(SPR_ORIGINALSHORE_START + 4); // SLOPE_SE
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3391
					LoadNextSprite(      SPR_SHORE_BASE +  7, _file_index, _nfo_line++); // SLOPE_WSE
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3392
					TranslateShoreSprites(SPR_ORIGINALSHORE_START + 3); // SLOPE_N
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3393
					TranslateShoreSprites(SPR_ORIGINALSHORE_START + 7); // SLOPE_NW
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3394
					LoadNextSprite(      SPR_SHORE_BASE + 10, _file_index, _nfo_line++); // SLOPE_STEEP_N
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3395
					LoadNextSprite(      SPR_SHORE_BASE + 11, _file_index, _nfo_line++); // SLOPE_NWS
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3396
					TranslateShoreSprites(SPR_ORIGINALSHORE_START + 5); // SLOPE_NE
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3397
					LoadNextSprite(      SPR_SHORE_BASE + 13, _file_index, _nfo_line++); // SLOPE_ENW
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3398
					LoadNextSprite(      SPR_SHORE_BASE + 14, _file_index, _nfo_line++); // SLOPE_SEN
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3399
					LoadNextSprite(      SPR_SHORE_BASE + 15, _file_index, _nfo_line++); // SLOPE_STEEP_E
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3400
					LoadNextSprite(      SPR_SHORE_BASE + 16, _file_index, _nfo_line++); // SLOPE_EW
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3401
					LoadNextSprite(      SPR_SHORE_BASE + 17, _file_index, _nfo_line++); // SLOPE_NS
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3402
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3403
					grfmsg(2, "GraphicsNew: Loading all standard shore sprites");
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3404
					break;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3405
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3406
				case 16:
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3407
				case 18:
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3408
					/* 'normal' newWater newGRF */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3409
					replace = SPR_SHORE_BASE;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3410
					break;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3411
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3412
				default:
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3413
					/* no valid shore sprite count */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3414
					grfmsg(1, "GraphicsNew: Shore graphics sprite count must be 10, 16 or 18, skipping");
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3415
					return;
5210
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  3416
			}
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  3417
			break;
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  3418
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3419
		/* case 0x0E: // New Signals. Not yet used by OTTD. */
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3420
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3421
		/* case 0x0F: // Tracks for marking sloped rail. Not yet used by OTTD. */
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3422
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3423
		case 0x10: // New airport sprites
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3424
			if (num != AIRPORTX_SPRITE_COUNT) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3425
				grfmsg(1, "GraphicsNew: Airport graphics sprite count must be 15, skipping");
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3426
				return;
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3427
			}
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3428
			replace = SPR_AIRPORTX_BASE;
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3429
			break;
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3430
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3431
		case 0x11: // Road stop sprites
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3432
			if (num != ROADSTOP_SPRITE_COUNT) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3433
				grfmsg(1, "GraphicsNew: Road stop graphics sprite count must be 8, skipping");
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3434
				return;
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3435
			}
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3436
			replace = SPR_ROADSTOP_BASE;
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3437
			break;
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3438
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3439
		/* case 0x12: // Aqueduct sprites. Not yet used by OTTD. */
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3440
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3441
		case 0x13: // Autorail sprites
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3442
			if (num != AUTORAIL_SPRITE_COUNT) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3443
				grfmsg(1, "GraphicsNew: Autorail graphics sprite count must be 55, skipping");
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3444
				return;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3445
			}
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3446
			replace = SPR_AUTORAIL_BASE;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3447
			break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3448
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3449
		case 0x14: // Flag sprites
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3450
			skip_num = SanitizeSpriteOffset(num, offset, FLAGS_SPRITE_COUNT, "Flag graphics");
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3451
			replace = SPR_FLAGS_BASE + offset;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3452
			break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3453
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3454
		case 0x15: // OpenTTD GUI sprites
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3455
			skip_num = SanitizeSpriteOffset(num, offset, OPENTTD_SPRITE_COUNT, "OpenTTD graphics");
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3456
			replace = SPR_OPENTTD_BASE + offset;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3457
			break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3458
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
  3459
		default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3460
			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
  3461
					type, num);
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  3462
			_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
  3463
			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
  3464
	}
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
  3465
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
  3466
	if (replace == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3467
		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
  3468
	} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3469
		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
  3470
	}
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
  3471
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
  3472
	for (; num > 0; num--) {
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3473
		_nfo_line++;
9628
b5c2449616b5 (svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents: 9627
diff changeset
  3474
		LoadNextSprite(replace == 0 ? _cur_spriteid++ : replace++, _file_index, _nfo_line);
3638
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  3475
	}
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3476
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3477
	_skip_sprites = skip_num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3478
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3479
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3480
/* Action 0x05 (SKIP) */
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3481
static void SkipAct5(byte *buf, int len)
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3482
{
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3483
	if (!check_length(len, 2, "SkipAct5")) return;
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3484
	buf++;
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3485
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3486
	/* Ignore type byte */
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3487
	grf_load_byte(&buf);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3488
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3489
	/* Skip the sprites of this action */
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3490
	_skip_sprites = grf_load_extended(&buf);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3491
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3492
	grfmsg(3, "SkipAct5: Skipping %d sprites", _skip_sprites);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3493
}
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3494
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3495
static uint32 GetParamVal(byte param, uint32 *cond_val)
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3496
{
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3497
	switch (param) {
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3498
		case 0x81: // current year
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3499
			return Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
5340
82c981816fcb (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5338
diff changeset
  3500
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3501
		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
  3502
			return _opt.landscape;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3503
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  3504
		case 0x84: { // GRF loading stage
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  3505
			uint32 res = 0;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  3506
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3507
			if (_cur_stage > GLS_INIT) SetBit(res, 0);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3508
			if (_cur_stage == GLS_RESERVE) SetBit(res, 8);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3509
			if (_cur_stage == GLS_ACTIVATION) SetBit(res, 9);
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  3510
			return res;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  3511
		}
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3512
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3513
		case 0x85: // TTDPatch flags, only for bit tests
3811
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3514
			if (cond_val == NULL) {
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3515
				/* Supported in Action 0x07 and 0x09, not 0x0D */
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3516
				return 0;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3517
			} else {
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3518
				uint32 param_val = _ttdpatch_flags[*cond_val / 0x20];
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3519
				*cond_val %= 0x20;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3520
				return param_val;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3521
			}
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3522
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3523
		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
  3524
			return _opt.road_side << 4;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3525
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3526
		case 0x88: // GRF ID check
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3527
			return 0;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3528
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3529
		case 0x8B: { // TTDPatch version
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3530
			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
  3531
			uint minor    = 6;
9704
197cb8c6ae17 (svn r11221) [NoAI] -Sync: with trunk r11145:11220
glx
parents: 9703
diff changeset
  3532
			uint revision = 1; // special case: 2.0.1 is 2.0.10
197cb8c6ae17 (svn r11221) [NoAI] -Sync: with trunk r11145:11220
glx
parents: 9703
diff changeset
  3533
			uint build    = 1382;
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
  3534
			return (major << 24) | (minor << 20) | (revision << 16) | build;
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3535
		}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3536
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3537
		case 0x8D: // TTD Version, 00=DOS, 01=Windows
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3538
			return !_use_dos_palette;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3539
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3540
		case 0x8E: // Y-offset for train sprites
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3541
			return _traininfo_vehicle_pitch;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3542
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3543
		case 0x92: // Game mode
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3544
			return _game_mode;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3545
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3546
		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
  3547
			return UINT_MAX;
5287
94a6c3c924b2 (svn r7436) -Codechange: Add action7/9/D variable 0x9A (-1)
peter1138
parents: 5234
diff changeset
  3548
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3549
		case 0x9D: // TTD Platform, 00=TTDPatch, 01=OpenTTD
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3550
			return 1;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3551
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3552
		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
  3553
			return _misc_grf_features;
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  3554
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3555
		case 0xA1: { // OpenTTD version
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3556
			extern uint32 _openttd_newgrf_version;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3557
			return _openttd_newgrf_version;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3558
		}
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3559
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3560
		default:
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3561
			/* GRF Parameter */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3562
			if (param < 0x80) return _cur_grffile->param[param];
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3563
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3564
			/* In-game variable. */
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3565
			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
  3566
			return UINT_MAX;
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3567
	}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3568
}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3569
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3570
/* Action 0x06 */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3571
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
  3572
{
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3573
	/* <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
  3574
	 *
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3575
	 * 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
  3576
	 *                 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
  3577
	 * 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
  3578
	 *                 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
  3579
	 *                 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
  3580
	 *                 were specified.
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3581
	 * 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
  3582
	 *                 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
  3583
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3584
	/* Preload the next sprite */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3585
	uint32 pos = FioGetPos();
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3586
	uint16 num = FioReadWord();
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3587
	uint8 type = FioReadByte();
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3588
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3589
	/* 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
  3590
	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
  3591
		_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
  3592
		FioReadBlock(_preload_sprite, num);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3593
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3594
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3595
	/* 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
  3596
	FioSeekTo(pos, SEEK_SET);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3597
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3598
	if (type != 0xFF) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3599
		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
  3600
		return;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3601
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3602
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3603
	/* 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
  3604
	buf++;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3605
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3606
	for (;;) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3607
		uint i;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3608
		uint param_num;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3609
		uint param_size;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3610
		uint offset;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3611
		bool add_value;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3612
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3613
		/* 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
  3614
		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
  3615
		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
  3616
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3617
		/* 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
  3618
		 * 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
  3619
		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
  3620
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3621
		/* 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
  3622
		 * instead of replacing it. */
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3623
		add_value  = HasBit(param_size, 7);
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3624
		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
  3625
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3626
		/* 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
  3627
		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
  3628
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3629
		/* 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
  3630
		 * 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
  3631
		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
  3632
			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
  3633
			break;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3634
		}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3635
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3636
		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
  3637
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3638
		bool carry = false;
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3639
		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
  3640
			uint32 value = GetParamVal(param_num + i / 4, NULL);
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3641
			/* Reset carry flag for each iteration of the variable (only really
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3642
			 * matters if param_size is greater than 4) */
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3643
			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
  3644
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3645
			if (add_value) {
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3646
				uint new_value = _preload_sprite[offset + i] + GB(value, (i % 4) * 8, 8) + (carry ? 1 : 0);
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3647
				_preload_sprite[offset + i] = GB(new_value, 0, 8);
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3648
				/* Check if the addition overflowed */
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  3649
				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
  3650
			} else {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3651
				_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
  3652
			}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3653
		}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3654
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3655
}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3656
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3657
/* Action 0x07 */
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3658
/* Action 0x09 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3659
static void SkipIf(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3660
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3661
	/* <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
  3662
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3663
	 * B param-num
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3664
	 * B param-size
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3665
	 * B condition-type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3666
	 * V value
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3667
	 * B num-sprites */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3668
	/* 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
  3669
	uint32 cond_val = 0;
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3670
	uint32 mask = 0;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  3671
	bool result;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3672
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
  3673
	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
  3674
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3675
	uint8 param     = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3676
	uint8 paramsize = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3677
	uint8 condtype  = grf_load_byte(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3678
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
  3679
	if (condtype < 2) {
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  3680
		/* 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
  3681
		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
  3682
	}
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
  3683
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  3684
	switch (paramsize) {
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3685
		case 4: cond_val = grf_load_dword(&buf); mask = 0xFFFFFFFF; break;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3686
		case 2: cond_val = grf_load_word(&buf);  mask = 0x0000FFFF; break;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3687
		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
  3688
		default: break;
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  3689
	}
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
  3690
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3691
	if (param < 0x80 && _cur_grffile->param_end <= param) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3692
		grfmsg(7, "SkipIf: Param %d undefined, skipping test", param);
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3693
		return;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3694
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3695
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3696
	uint32 param_val = GetParamVal(param, &cond_val);
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3697
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3698
	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
  3699
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3700
	/*
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3701
	 * Parameter (variable in specs) 0x88 can only have GRF ID checking
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3702
	 * conditions, except conditions 0x0B and 0x0C (cargo availability)
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3703
	 * as those ignore the parameter. So, when the condition type is
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3704
	 * either of those, the specific variable 0x88 code is skipped, so
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3705
	 * the "general" code for the cargo availability conditions kicks in.
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3706
	 */
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3707
	if (param == 0x88 && condtype != 0x0B && condtype != 0x0C) {
5703
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  3708
		/* 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
  3709
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
  3710
		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
  3711
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
  3712
		if (condtype != 10 && c == NULL) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3713
			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
  3714
			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
  3715
		}
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
  3716
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
  3717
		switch (condtype) {
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3718
			/* Tests 0x06 to 0x0A are only for param 0x88, GRFID checks */
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3719
			case 0x06: // Is GRFID active?
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  3720
				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
  3721
				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
  3722
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3723
			case 0x07: // Is GRFID non-active?
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  3724
				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
  3725
				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
  3726
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3727
			case 0x08: // GRFID is not but will be active?
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  3728
				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
  3729
				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
  3730
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3731
			case 0x09: // GRFID is or will be active?
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  3732
				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
  3733
				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
  3734
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3735
			case 0x0A: // GRFID is not nor will be active
5703
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  3736
				/* This is the only condtype that doesn't get ignored if the GRFID is not found */
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  3737
				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
  3738
				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
  3739
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3740
			default: grfmsg(1, "SkipIf: Unsupported GRF condition type %02X. Ignoring", condtype); return;
5234
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  3741
		}
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
  3742
	} 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
  3743
		/* 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
  3744
		switch (condtype) {
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3745
			case 0x00: result = !!(param_val & (1 << cond_val));
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3746
				break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3747
			case 0x01: result = !(param_val & (1 << cond_val));
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3748
				break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3749
			case 0x02: result = (param_val & mask) == cond_val;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3750
				break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3751
			case 0x03: result = (param_val & mask) != cond_val;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3752
				break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3753
			case 0x04: result = (param_val & mask) < cond_val;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3754
				break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3755
			case 0x05: result = (param_val & mask) > cond_val;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3756
				break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3757
			case 0x0B: result = GetCargoIDByLabel(BSWAP32(cond_val)) == CT_INVALID;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3758
				break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3759
			case 0x0C: result = GetCargoIDByLabel(BSWAP32(cond_val)) != CT_INVALID;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3760
				break;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3761
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3762
			default: grfmsg(1, "SkipIf: Unsupported condition type %02X. Ignoring", condtype); return;
5234
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  3763
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3764
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3765
1607
320079c7ac28 (svn r2111) So, result is bool therefore no need for this horrible == 0 thing.
pasky
parents: 1606
diff changeset
  3766
	if (!result) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3767
		grfmsg(2, "SkipIf: Not skipping sprites, test was false");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3768
		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
  3769
	}
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
  3770
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3771
	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
  3772
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3773
	/* 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
  3774
	 * 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
  3775
	 * 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
  3776
	 * label in the file is used. */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3777
	GRFLabel *choice = NULL;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3778
	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
  3779
		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
  3780
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3781
		/* 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
  3782
		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
  3783
		/* 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
  3784
		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
  3785
			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
  3786
			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
  3787
		}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3788
	}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3789
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3790
	if (choice != NULL) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3791
		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
  3792
		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
  3793
		_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
  3794
		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
  3795
	}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3796
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3797
	grfmsg(2, "SkipIf: Skipping %d sprites, test was true", numsprites);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3798
	_skip_sprites = numsprites;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3799
	if (_skip_sprites == 0) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3800
		/* Zero means there are no sprites to skip, so
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3801
		 * we use -1 to indicate that all further
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3802
		 * sprites should be skipped. */
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3803
		_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
  3804
14794ebde68e (svn r8831) -Feature: If an action 7/9 leads to skipping the rest of the file, disable the
maedhros
parents: 6421
diff changeset
  3805
		/* If an action 8 hasn't been encountered yet, disable the grf. */
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3806
		if (_cur_grfconfig->status != GCS_ACTIVATED) {
9628
b5c2449616b5 (svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents: 9627
diff changeset
  3807
			_cur_grfconfig->status = GCS_DISABLED;
b5c2449616b5 (svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents: 9627
diff changeset
  3808
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3809
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3810
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3811
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  3812
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
  3813
/* 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
  3814
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
  3815
{
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3816
	if (!check_length(len, 8, "Info")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3817
	buf++;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3818
	grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3819
	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
  3820
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3821
	_cur_grfconfig->grfid = grfid;
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  3822
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
  3823
	/* GRF IDs starting with 0xFF are reserved for internal TTDPatch use */
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3824
	if (GB(grfid, 24, 8) == 0xFF) SetBit(_cur_grfconfig->flags, GCF_SYSTEM);
5329
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3825
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  3826
	len -= 6;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3827
	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
  3828
	_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
  3829
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
  3830
	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
  3831
	if (len > 0) {
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3832
		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
  3833
		_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
  3834
	}
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
  3835
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
  3836
	/* 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
  3837
	_skip_sprites = -1;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3838
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3839
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  3840
/* Action 0x08 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3841
static void GRFInfo(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3842
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3843
	/* <08> <version> <grf-id> <name> <info>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3844
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3845
	 * B version       newgrf version, currently 06
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3846
	 * 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
  3847
	 * S name          name of this .grf set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3848
	 * S info          string describing the set, and e.g. author and copyright */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3849
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3850
	if (!check_length(len, 8, "GRFInfo")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3851
	buf++;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3852
	uint8 version    = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3853
	uint32 grfid     = grf_load_dword(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3854
	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
  3855
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
  3856
	_cur_grffile->grfid = grfid;
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  3857
	_cur_grffile->grf_version = version;
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  3858
	_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
  3859
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
  3860
	/* Do swap the GRFID for displaying purposes since people expect that */
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  3861
	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
  3862
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3863
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  3864
/* Action 0x0A */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3865
static void SpriteReplace(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3866
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3867
	/* <0A> <num-sets> <set1> [<set2> ...]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3868
	 * <set>: <num-sprites> <first-sprite>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3869
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3870
	 * 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
  3871
	 * Each set:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3872
	 * 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
  3873
	 * 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
  3874
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3875
	buf++; // skip action byte
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3876
	uint8 num_sets = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3877
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3878
	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
  3879
		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
  3880
		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
  3881
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3882
		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
  3883
			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
  3884
		);
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
  3885
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3886
		for (uint j = 0; j < num_sprites; j++) {
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3887
			int load_index = first_sprite + j;
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  3888
			_nfo_line++;
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3889
			LoadNextSprite(load_index, _file_index, _nfo_line); // XXX
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3890
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3891
			/*  Shore sprites now located at different addresses.
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3892
			 * So apply the required displacements */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  3893
			if (IsInsideMM(load_index, SPR_ORIGINALSHORE_START, SPR_ORIGINALSHORE_END + 1)) TranslateShoreSprites(load_index);
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
  3894
		}
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
  3895
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3896
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3897
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3898
/* Action 0x0A (SKIP) */
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3899
static void SkipActA(byte *buf, int len)
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3900
{
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3901
	buf++;
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3902
	uint8 num_sets = grf_load_byte(&buf);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3903
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3904
	for (uint i = 0; i < num_sets; i++) {
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3905
		/* Skip the sprites this replaces */
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3906
		_skip_sprites += grf_load_byte(&buf);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3907
		/* But ignore where they go */
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3908
		grf_load_word(&buf);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3909
	}
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3910
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3911
	grfmsg(3, "SkipActA: Skipping %d sprites", _skip_sprites);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3912
}
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  3913
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  3914
/* 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
  3915
static void GRFLoadError(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3916
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3917
	/* <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
  3918
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3919
	 * B severity      00: notice, contine loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3920
	 *                 01: warning, continue loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3921
	 *                 02: error, but continue loading grf file, and attempt
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3922
	 *                     loading grf again when loading or starting next game
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3923
	 *                 03: error, abort loading and prevent loading again in
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3924
	 *                     the future (only when restarting the patch)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3925
	 * 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
  3926
	 * B message-id    message to show, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3927
	 * 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
  3928
	 *                 not present for built-in messages.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3929
	 * 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
  3930
	 * 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
  3931
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3932
	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
  3933
		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
  3934
		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
  3935
		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
  3936
		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
  3937
		STR_NEWGRF_ERROR_LOAD_BEFORE,
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3938
		STR_NEWGRF_ERROR_LOAD_AFTER,
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3939
		STR_NEWGRF_ERROR_OTTD_VERSION_NUMBER,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3940
	};
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  3941
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
  3942
	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
  3943
		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
  3944
		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
  3945
		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
  3946
		STR_NEWGRF_ERROR_MSG_FATAL
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  3947
	};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3948
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
  3949
	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
  3950
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3951
	/* 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
  3952
	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
  3953
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  3954
	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
  3955
	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
  3956
	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
  3957
	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
  3958
	len -= 4;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3959
9627
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  3960
	/* Skip the error if it isn't valid for the current language. */
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  3961
	if (!CheckGrfLangID(lang, _cur_grffile->grf_version)) return;
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  3962
6421
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3963
	/* 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
  3964
	 * is set. */
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3965
	if (!HasBit(severity, 7) && _cur_stage == GLS_INIT) {
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  3966
		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
  3967
		return;
3588
a1adf8a40756 (svn r4474) - NewGRF: Skip non-fatal errors when not in stage 2.
peter1138
parents: 3577
diff changeset
  3968
	}
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  3969
	ClrBit(severity, 7);
6421
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3970
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3971
	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
  3972
		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
  3973
		severity = 2;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3974
	} 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
  3975
		/* 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
  3976
		 * more of it gets loaded. */
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  3977
		_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
  3978
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3979
		_skip_sprites = -1;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3980
	}
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3981
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3982
	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
  3983
		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
  3984
		return;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3985
	}
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3986
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3987
	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
  3988
		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
  3989
		return;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3990
	}
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  3991
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
  3992
	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
  3993
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3994
	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
  3995
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  3996
	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
  3997
		/* 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
  3998
		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
  3999
		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
  4000
9627
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  4001
		error->custom_message = TranslateTTDPatchCodes(message);
6465
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4002
	} 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
  4003
		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
  4004
	}
02c062eb2c74 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents: 6422
diff changeset
  4005
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
  4006
	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
  4007
		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
  4008
		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
  4009
9627
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  4010
		error->data = TranslateTTDPatchCodes(data);
6465
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4011
	}
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4012
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4013
	/* 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
  4014
	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
  4015
	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
  4016
		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
  4017
		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
  4018
	}
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4019
	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
  4020
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4021
	_cur_grfconfig->error = error;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4022
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4023
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  4024
/* Action 0x0C */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4025
static void GRFComment(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4026
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4027
	/* <0C> [<ignored...>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4028
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4029
	 * 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
  4030
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  4031
	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
  4032
6433
84cd6e4262fd (svn r8843) -Fix
tron
parents: 6429
diff changeset
  4033
	int text_len = len - 1;
84cd6e4262fd (svn r8843) -Fix
tron
parents: 6429
diff changeset
  4034
	const char *text = (const char*)(buf + 1);
84cd6e4262fd (svn r8843) -Fix
tron
parents: 6429
diff changeset
  4035
	grfmsg(2, "GRFComment: %.*s", text_len, text);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4036
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4037
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
  4038
/* 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
  4039
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
  4040
{
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
  4041
	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
  4042
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4043
	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
  4044
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
  4045
	/* 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
  4046
	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
  4047
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
  4048
	/* 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
  4049
	 * 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
  4050
	 * 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
  4051
	 * 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
  4052
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  4053
	SetBit(_cur_grfconfig->flags, GCF_UNSAFE);
5776
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4054
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
  4055
	/* 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
  4056
	_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
  4057
}
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
  4058
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4059
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4060
static uint32 GetPatchVariable(uint8 param)
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4061
{
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4062
	switch (param) {
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4063
		/* start year - 1920 */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  4064
		case 0x0B: return max(_patches.starting_year, ORIGINAL_BASE_YEAR) - ORIGINAL_BASE_YEAR;
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4065
		/* freight trains weight factor */
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4066
		case 0x0E: return _patches.freight_trains;
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4067
		/* empty wagon speed increase */
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4068
		case 0x0F: return 0;
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4069
		/* plane speed factor */
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4070
		case 0x10: return 4;
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4071
		/* 2CC colormap base sprite */
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4072
		case 0x11: return SPR_2CCMAP_BASE;
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4073
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4074
		default:
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4075
			grfmsg(2, "ParamSet: Unknown Patch variable 0x%02X.", param);
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4076
			return 0;
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4077
	}
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4078
}
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4079
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4080
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4081
static uint32 PerformGRM(uint32 *grm, uint16 num_ids, uint16 count, uint8 op, uint8 target, const char *type)
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4082
{
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4083
	uint start = 0;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4084
	uint size  = 0;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4085
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4086
	if (op == 6) {
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4087
		/* Return GRFID of set that reserved ID */
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4088
		return grm[_cur_grffile->param[target]];
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4089
	}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4090
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4091
	/* With an operation of 2 or 3, we want to reserve a specific block of IDs */
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4092
	if (op == 2 || op == 3) start = _cur_grffile->param[target];
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4093
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4094
	for (uint i = start; i < num_ids; i++) {
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4095
		if (grm[i] == 0) {
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4096
			size++;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4097
		} else {
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4098
			if (op == 2 || op == 3) break;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4099
			start = i + 1;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4100
			size = 0;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4101
		}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4102
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4103
		if (size == count) break;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4104
	}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4105
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4106
	if (size == count) {
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4107
		/* Got the slot... */
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4108
		if (op == 0 || op == 3) {
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4109
			grfmsg(2, "ParamSet: GRM: Reserving %d %s at %d", count, type, start);
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4110
			for (uint i = 0; i < count; i++) grm[start + i] = _cur_grffile->grfid;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4111
		}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4112
		return start;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4113
	}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4114
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4115
	/* Unable to allocate */
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4116
	if (op != 4 && op != 5) {
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4117
		/* Deactivate GRF */
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4118
		grfmsg(0, "ParamSet: GRM: Unable to allocate %d %s, deactivating", count, type);
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4119
		_cur_grfconfig->status = GCS_DISABLED;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4120
		_skip_sprites = -1;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4121
		return UINT_MAX;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4122
	}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4123
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4124
	grfmsg(1, "ParamSet: GRM: Unable to allocate %d %s", count, type);
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4125
	return UINT_MAX;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4126
}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4127
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4128
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  4129
/* Action 0x0D */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4130
static void ParamSet(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4131
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4132
	/* <0D> <target> <operation> <source1> <source2> [<data>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4133
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4134
	 * B target        parameter number where result is stored
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4135
	 * B operation     operation to perform, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4136
	 * B source1       first source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4137
	 * B source2       second source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4138
	 * 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
  4139
	 *                 if both source1 and source2 refer to actual parameters
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4140
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4141
	 * Operations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4142
	 * 00      Set parameter equal to source1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4143
	 * 01      Addition, source1 + source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4144
	 * 02      Subtraction, source1 - source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4145
	 * 03      Unsigned multiplication, source1 * source2 (both unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4146
	 * 04      Signed multiplication, source1 * source2 (both signed)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4147
	 * 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
  4148
	 *         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
  4149
	 *         negative, source1 is unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4150
	 * 06      Signed bit shift, source1 by source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4151
	 *         (source2 like in 05, and source1 as well)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4152
	 */
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
  4153
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
  4154
	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
  4155
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4156
	uint8 target = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4157
	uint8 oper   = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4158
	uint32 src1  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4159
	uint32 src2  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4160
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4161
	uint32 data = 0;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4162
	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
  4163
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
  4164
	/* 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
  4165
	 * 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
  4166
	 * 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
  4167
	 * - 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
  4168
	 * - 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
  4169
	 *   an earlier action D */
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  4170
	if (HasBit(oper, 7)) {
3807
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  4171
		if (target < 0x80 && target < _cur_grffile->param_end) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4172
			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
  4173
			return;
3807
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  4174
		}
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  4175
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4176
		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
  4177
	}
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
  4178
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
  4179
	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
  4180
		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
  4181
			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
  4182
				/* Patch variables */
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4183
				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
  4184
			} 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
  4185
				/* 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
  4186
				if (_cur_stage != GLS_ACTIVATION) {
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4187
					/* Ignore GRM during initialization */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4188
					src1 = 0;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4189
				} else {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4190
					uint8  op      = src1;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4191
					uint8  feature = GB(data, 8, 8);
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4192
					uint16 count   = GB(data, 16, 16);
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4193
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4194
					switch (feature) {
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  4195
						case 0x00: // Trains
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  4196
						case 0x01: // Road Vehicles
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  4197
						case 0x02: // Ships
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  4198
						case 0x03: // Aircraft
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4199
							src1 = PerformGRM(&_grm_engines[_vehshifts[feature]], _vehcounts[feature], count, op, target, "vehicles");
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4200
							if (_skip_sprites == -1) return;
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4201
							break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4202
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  4203
						case 0x08: // General sprites
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4204
							switch (op) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4205
								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
  4206
									/* 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
  4207
									if (_cur_spriteid + count >= 16384) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4208
										grfmsg(0, "ParamSet: GRM: Unable to allocate %d sprites; try changing NewGRF order", count);
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  4209
										_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
  4210
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
  4211
										_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
  4212
										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
  4213
									}
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
  4214
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4215
									/* '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
  4216
									src1 = _cur_spriteid;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4217
									_cur_spriteid += count;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4218
									break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4219
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4220
								case 1:
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4221
									src1 = _cur_spriteid;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4222
									break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4223
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4224
								default:
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4225
									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
  4226
									return;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4227
							}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4228
							break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4229
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4230
						case 0x0B: // Cargo
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4231
							/* There are two ranges: one for cargo IDs and one for cargo bitmasks */
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4232
							src1 = PerformGRM(_grm_cargos, NUM_CARGO * 2, count, op, target, "cargos");
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4233
							if (_skip_sprites == -1) return;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4234
							break;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4235
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4236
						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
  4237
					}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4238
				}
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
  4239
			}
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
  4240
		} 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
  4241
			/* 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
  4242
			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
  4243
			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
  4244
				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
  4245
			} 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
  4246
				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
  4247
			}
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
  4248
		}
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
  4249
	} 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
  4250
		/* 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
  4251
		 * 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
  4252
		 * 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
  4253
		 * 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
  4254
		 * of 0 is used instead.  */
3811
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  4255
		src1 = (src1 == 0xFF) ? data : GetParamVal(src1, NULL);
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  4256
		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
  4257
	}
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
  4258
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
  4259
	/* 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
  4260
	 * 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
  4261
	 * 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
  4262
	 * 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
  4263
	 * 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
  4264
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4265
	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
  4266
	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
  4267
		case 0x00:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4268
			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
  4269
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4270
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4271
		case 0x01:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4272
			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
  4273
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4274
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4275
		case 0x02:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4276
			res = src1 - src2;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4277
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4278
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
  4279
		case 0x03:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4280
			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
  4281
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4282
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
  4283
		case 0x04:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4284
			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
  4285
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4286
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
  4287
		case 0x05:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4288
			if ((int32)src2 < 0) {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4289
				res = src1 >> -(int32)src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4290
			} else {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4291
				res = src1 << src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4292
			}
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
  4293
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4294
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
  4295
		case 0x06:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4296
			if ((int32)src2 < 0) {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4297
				res = (int32)src1 >> -(int32)src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4298
			} else {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4299
				res = (int32)src1 << src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4300
			}
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
  4301
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4302
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  4303
		case 0x07: // Bitwise AND
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4304
			res = src1 & src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4305
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4306
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  4307
		case 0x08: // Bitwise OR
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4308
			res = src1 | src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4309
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4310
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  4311
		case 0x09: // Unsigned division
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4312
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4313
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4314
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4315
				res = src1 / src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4316
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4317
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4318
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  4319
		case 0x0A: // Signed divison
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4320
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4321
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4322
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4323
				res = (int32)src1 / (int32)src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4324
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4325
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4326
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  4327
		case 0x0B: // Unsigned modulo
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4328
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4329
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4330
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4331
				res = src1 % src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4332
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4333
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4334
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  4335
		case 0x0C: // Signed modulo
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4336
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4337
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4338
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4339
				res = (int32)src1 % (int32)src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4340
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4341
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4342
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4343
		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
  4344
	}
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4346
	switch (target) {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4347
		case 0x8E: // Y-Offset for train sprites
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4348
			_traininfo_vehicle_pitch = res;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4349
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4350
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4351
		case 0x8F: // Rail track type cost factors
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4352
			_railtype_cost_multiplier[0] = GB(res, 0, 8);
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4353
			if (_patches.disable_elrails) {
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4354
				_railtype_cost_multiplier[1] = GB(res, 0, 8);
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4355
				_railtype_cost_multiplier[2] = GB(res, 8, 8);
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4356
			} else {
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4357
				_railtype_cost_multiplier[1] = GB(res, 8, 8);
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4358
				_railtype_cost_multiplier[2] = GB(res, 16, 8);
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4359
			}
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4360
			_railtype_cost_multiplier[3] = GB(res, 16, 8);
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4361
			break;
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4362
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  4363
		/* @todo implement */
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4364
		case 0x93: // Tile refresh offset to left
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4365
		case 0x94: // Tile refresh offset to right
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4366
		case 0x95: // Tile refresh offset upwards
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4367
		case 0x96: // Tile refresh offset downwards
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4368
		case 0x97: // Snow line height
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4369
		case 0x99: // Global ID offset
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4370
			grfmsg(7, "ParamSet: Skipping unimplemented target 0x%02X", target);
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4371
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4372
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  4373
		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
  4374
			_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
  4375
			/* Set train list engine width */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  4376
			_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
  4377
			break;
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  4378
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4379
		default:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4380
			if (target < 0x80) {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4381
				_cur_grffile->param[target] = res;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4382
				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
  4383
			} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4384
				grfmsg(7, "ParamSet: Skipping unknown target 0x%02X", target);
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4385
			}
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4386
			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
  4387
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4388
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4389
5753
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  4390
/* Action 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
  4391
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
  4392
{
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
  4393
	/* <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
  4394
	 *
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
  4395
	 * 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
  4396
	 * 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
  4397
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4398
	if (!check_length(len, 2, "GRFInhibit")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4399
	buf++;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4400
	uint8 num = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4401
	if (!check_length(len, 2 + 4 * num, "GRFInhibit")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4402
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4403
	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
  4404
		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
  4405
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
  4406
		/* 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
  4407
		if (grfid != _cur_grfconfig->grfid) {
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  4408
			SetBit(_cur_grfconfig->flags, GCF_UNSAFE);
5753
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  4409
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
  4410
			/* 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
  4411
			_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
  4412
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
  4413
			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
  4414
		}
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
  4415
	}
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
  4416
}
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
  4417
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  4418
/* Action 0x0E */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4419
static void GRFInhibit(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4420
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4421
	/* <0E> <num> <grfids...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4422
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4423
	 * B num           Number of GRFIDs that follow
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4424
	 * 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
  4425
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4426
	if (!check_length(len, 2, "GRFInhibit")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4427
	buf++;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4428
	uint8 num = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4429
	if (!check_length(len, 2 + 4 * num, "GRFInhibit")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4430
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4431
	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
  4432
		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
  4433
		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
  4434
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
  4435
		/* 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
  4436
		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
  4437
			grfmsg(2, "GRFInhibit: Deactivating file '%s'", file->filename);
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  4438
			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
  4439
		}
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
  4440
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4441
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4442
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4443
/* Action 0x0F */
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4444
static void FeatureTownName(byte *buf, int len)
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4445
{
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4446
	/* <0F> <id> <style-name> <num-parts> <parts>
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4447
	 *
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4448
	 * B id          ID of this definition in bottom 7 bits (final definition if bit 7 set)
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4449
	 * V style-name  Name of the style (only for final definition)
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4450
	 * B num-parts   Number of parts in this definition
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4451
	 * V parts       The parts */
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4452
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4453
	if (!check_length(len, 1, "FeatureTownName: definition ID")) return;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4454
	buf++; len--;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4455
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4456
	uint32 grfid = _cur_grffile->grfid;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4457
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4458
	GRFTownName *townname = AddGRFTownName(grfid);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4459
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4460
	byte id = grf_load_byte(&buf);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4461
	len--;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4462
	grfmsg(6, "FeatureTownName: definition 0x%02X", id & 0x7F);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4463
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  4464
	if (HasBit(id, 7)) {
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4465
		/* Final definition */
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  4466
		ClrBit(id, 7);
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4467
		bool new_scheme = _cur_grffile->grf_version >= 7;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4468
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4469
		if (!check_length(len, 1, "FeatureTownName: lang_id")) return;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4470
		byte lang = grf_load_byte(&buf);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4471
		len--;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4472
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4473
		byte nb_gen = townname->nb_gen;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4474
		do {
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  4475
			ClrBit(lang, 7);
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4476
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4477
			if (!check_length(len, 1, "FeatureTownName: style name")) return;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4478
			const char *name = grf_load_string(&buf, len);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4479
			len -= strlen(name) + 1;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4480
			grfmsg(6, "FeatureTownName: lang 0x%X -> '%s'", lang, TranslateTTDPatchCodes(name));
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4481
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4482
			townname->name[nb_gen] = AddGRFString(grfid, id, lang, new_scheme, name, STR_UNDEFINED);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4483
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4484
			if (!check_length(len, 1, "FeatureTownName: lang_id")) return;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4485
			lang = grf_load_byte(&buf);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4486
			len--;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4487
		} while (lang != 0);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4488
		townname->id[nb_gen] = id;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4489
		townname->nb_gen++;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4490
	}
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4491
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4492
	if (!check_length(len, 1, "FeatureTownName: number of parts")) return;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4493
	byte nb = grf_load_byte(&buf);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4494
	len--;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4495
	grfmsg(6, "FeatureTownName: %d parts", nb, nb);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4496
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4497
	townname->nbparts[id] = nb;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4498
	townname->partlist[id] = CallocT<NamePartList>(nb);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4499
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4500
	for (int i = 0; i < nb; i++) {
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4501
		if (!check_length(len, 3, "FeatureTownName: parts header")) return;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4502
		byte nbtext =  grf_load_byte(&buf);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4503
		townname->partlist[id][i].bitstart  = grf_load_byte(&buf);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4504
		townname->partlist[id][i].bitcount  = grf_load_byte(&buf);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4505
		townname->partlist[id][i].maxprob   = 0;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4506
		townname->partlist[id][i].partcount = nbtext;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4507
		townname->partlist[id][i].parts     = CallocT<NamePart>(nbtext);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4508
		len -= 3;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4509
		grfmsg(6, "FeatureTownName: part %d contains %d texts and will use GB(seed, %d, %d)", i, nbtext, townname->partlist[id][i].bitstart, townname->partlist[id][i].bitcount);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4510
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4511
		for (int j = 0; j < nbtext; j++) {
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4512
			if (!check_length(len, 2, "FeatureTownName: part")) return;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4513
			byte prob = grf_load_byte(&buf);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4514
			len--;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4515
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  4516
			if (HasBit(prob, 7)) {
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4517
				byte ref_id = grf_load_byte(&buf);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4518
				len--;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4519
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4520
				if (townname->nbparts[ref_id] == 0) {
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4521
					grfmsg(0, "FeatureTownName: definition 0x%02X doesn't exist, deactivating", ref_id);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4522
					DelGRFTownName(grfid);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4523
					_cur_grfconfig->status = GCS_DISABLED;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4524
					_skip_sprites = -1;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4525
					return;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4526
				}
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4527
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4528
				grfmsg(6, "FeatureTownName: part %d, text %d, uses intermediate definition 0x%02X (with probability %d)", i, j, ref_id, prob & 0x7F);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4529
				townname->partlist[id][i].parts[j].data.id = ref_id;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4530
			} else {
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4531
				const char *text = grf_load_string(&buf, len);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4532
				len -= strlen(text) + 1;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4533
				townname->partlist[id][i].parts[j].data.text = TranslateTTDPatchCodes(text);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4534
				grfmsg(6, "FeatureTownName: part %d, text %d, '%s' (with probability %d)", i, j, townname->partlist[id][i].parts[j].data.text, prob);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4535
			}
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4536
			townname->partlist[id][i].parts[j].prob = prob;
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4537
			townname->partlist[id][i].maxprob += GB(prob, 0, 7);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4538
		}
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4539
		grfmsg(6, "FeatureTownName: part %d, total probability %d", i, townname->partlist[id][i].maxprob);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4540
	}
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4541
}
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4542
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  4543
/* 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
  4544
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
  4545
{
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  4546
	/* <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
  4547
	 *
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  4548
	 * 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
  4549
	 * 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
  4550
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
  4551
	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
  4552
	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
  4553
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4554
	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
  4555
	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
  4556
	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
  4557
	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
  4558
	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
  4559
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  4560
	/* 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
  4561
	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
  4562
		_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
  4563
	} 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
  4564
		/* 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
  4565
		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
  4566
		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
  4567
		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
  4568
	}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  4569
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4570
	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
  4571
}
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
  4572
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4573
/* Action 0x11 */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4574
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
  4575
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4576
	/* <11> <num>
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4577
	 *
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4578
	 * 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
  4579
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
  4580
	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
  4581
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4582
	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
  4583
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4584
	_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
  4585
	_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
  4586
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4587
	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
  4588
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4589
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4590
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
  4591
{
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4592
	const GRFFile *file;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4593
	FileEntry *se = AllocateFileEntry();
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4594
	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
  4595
	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
  4596
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4597
	file = GetFileByGRFID(grfid);
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4598
	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
  4599
		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
  4600
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4601
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4602
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4603
	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
  4604
		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
  4605
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4606
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4607
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4608
	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
  4609
5024
f13f2f2d43f9 (svn r7065) Use simple assignment instead of memcpy()
tron
parents: 5011
diff changeset
  4610
	*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
  4611
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4612
	/* 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
  4613
	se->volume   = 128;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4614
	se->priority = 0;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4615
}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4616
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4617
/* 'Action 0xFE' */
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4618
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
  4619
{
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4620
	if (_grf_data_blocks == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4621
		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
  4622
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4623
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4624
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4625
	buf++;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4626
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4627
	_grf_data_blocks--;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4628
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4629
	/* 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
  4630
	 * 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
  4631
	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
  4632
		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
  4633
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4634
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4635
	switch (_grf_data_type) {
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4636
		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
  4637
		default: NOT_REACHED(); break;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4638
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4639
}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4640
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4641
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
  4642
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4643
	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
  4644
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4645
	/* 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
  4646
	 * so that the indices used elsewhere are still correct. */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4647
	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
  4648
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  4649
	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
  4650
		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
  4651
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4652
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4653
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4654
	/* 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
  4655
	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
  4656
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  4657
	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
  4658
		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
  4659
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4660
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4661
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4662
	for (;;) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4663
		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
  4664
		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
  4665
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4666
		switch (tag) {
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  4667
			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
  4668
				/* 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
  4669
				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
  4670
					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
  4671
					return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4672
				}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4673
				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
  4674
				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
  4675
				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
  4676
				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
  4677
				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
  4678
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4679
				/* 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
  4680
				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
  4681
				break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4682
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  4683
			case 'atad': // 'data'
9703
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
  4684
				se->file_size   = size;
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
  4685
				se->file_offset = FioGetPos() - (len - (buf - buf_start)) + 1;
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
  4686
				se->file_slot   = _file_index;
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4687
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4688
				/* 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
  4689
				se->volume = 0x80;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4690
				se->priority = 0;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4691
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4692
				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
  4693
				return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4694
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4695
			default:
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4696
				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
  4697
				return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4698
		}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4699
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4700
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4701
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
  4702
/* 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
  4703
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
  4704
{
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
  4705
	/* <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
  4706
	 *
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
  4707
	 * 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
  4708
	 * 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
  4709
	 * 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
  4710
	 * 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
  4711
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
  4712
	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
  4713
	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
  4714
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4715
	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
  4716
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
  4717
	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
  4718
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4719
	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
  4720
		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
  4721
		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
  4722
		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
  4723
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4724
		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
  4725
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4726
		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
  4727
			SetUnicodeGlyph(size, base_char + c, _cur_spriteid);
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  4728
			_nfo_line++;
9628
b5c2449616b5 (svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents: 9627
diff changeset
  4729
			LoadNextSprite(_cur_spriteid++, _file_index, _nfo_line);
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  4730
		}
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
  4731
	}
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
  4732
}
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
  4733
6560
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4734
/* Action 0x13 */
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4735
static void TranslateGRFStrings(byte *buf, int len)
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4736
{
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4737
	/* <13> <grfid> <num-ent> <offset> <text...>
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4738
	 *
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4739
	 * 4*B grfid     The GRFID of the file whose texts are to be translated
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4740
	 * B   num-ent   Number of strings
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4741
	 * W   offset    First text ID
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4742
	 * S   text...   Zero-terminated strings */
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4743
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4744
	buf++; len--;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4745
	if (!check_length(len, 7, "TranslateGRFString")) return;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4746
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4747
	uint32 grfid = grf_load_dword(&buf);
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4748
	const GRFConfig *c = GetGRFConfig(grfid);
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4749
	if (c == NULL || (c->status != GCS_INITIALISED && c->status != GCS_ACTIVATED)) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4750
		grfmsg(7, "TranslateGRFStrings: GRFID 0x%08x unknown, skipping action 13", BSWAP32(grfid));
6560
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4751
		return;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4752
	}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4753
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4754
	if (c->status == GCS_INITIALISED) {
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4755
		/* If the file is not active but will be activated later, give an error
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4756
		 * and disable this file. */
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4757
		GRFError *error = CallocT<GRFError>(1);
9627
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  4758
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  4759
		char tmp[256];
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  4760
		GetString(tmp, STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE, lastof(tmp));
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  4761
		error->data = strdup(tmp);
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  4762
6560
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4763
		error->message  = STR_NEWGRF_ERROR_LOAD_AFTER;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4764
		error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4765
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4766
		if (_cur_grfconfig->error != NULL) free(_cur_grfconfig->error);
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4767
		_cur_grfconfig->error = error;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4768
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4769
		_cur_grfconfig->status = GCS_DISABLED;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4770
		_skip_sprites = -1;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4771
		return;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4772
	}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4773
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4774
	byte num_strings = grf_load_byte(&buf);
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4775
	uint16 first_id  = grf_load_word(&buf);
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4776
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4777
	if (!((first_id >= 0xD000 && first_id + num_strings <= 0xD3FF) || (first_id >= 0xDC00 && first_id + num_strings <= 0xDCFF))) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4778
		grfmsg(7, "TranslateGRFStrings: Attempting to set out-of-range string IDs in action 13 (first: 0x%4X, number: 0x%2X)", first_id, num_strings);
6560
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4779
		return;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4780
	}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4781
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4782
	len -= 7;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4783
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4784
	for (uint i = 0; i < num_strings && len > 0; i++) {
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4785
		const char *string   = grf_load_string(&buf, len);
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4786
		size_t string_length = strlen(string) + 1;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4787
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4788
		len -= (int)string_length;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4789
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4790
		if (string_length == 1) {
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4791
			grfmsg(7, "TranslateGRFString: Ignoring empty string.");
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4792
			continue;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4793
		}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4794
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4795
		/* Since no language id is supplied this string has to be added as a
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4796
		 * generic string, thus the language id of 0x7F. For this to work
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4797
		 * new_scheme has to be true as well. A language id of 0x7F will be
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4798
		 * overridden by a non-generic id, so this will not change anything if
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4799
		 * a string has been provided specifically for this language. */
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4800
		AddGRFString(grfid, first_id + i, 0x7F, true, string, STR_UNDEFINED);
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4801
	}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4802
}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  4803
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4804
/* 'Action 0xFF' */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4805
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
  4806
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4807
	if (_grf_data_blocks == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4808
		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
  4809
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4810
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4811
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4812
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4813
	uint8 name_len = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4814
	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
  4815
	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
  4816
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4817
	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
  4818
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4819
	_grf_data_blocks--;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4820
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4821
	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
  4822
		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
  4823
		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
  4824
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4825
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4826
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
  4827
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
  4828
/* 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
  4829
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
  4830
{
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  4831
	SetBit(_cur_grfconfig->flags, GCF_UNSAFE);
5329
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  4832
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
  4833
	/* 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
  4834
	_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
  4835
}
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
  4836
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
  4837
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  4838
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
  4839
{
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4840
	_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
  4841
	                   |                                        (1 << 0x0D)  // newairports
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4842
	                   |                                        (1 << 0x0E)  // largestations
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4843
	                   |           ((_patches.longbridges ? 1 : 0) << 0x0F)  // longbridges
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4844
	                   |                                        (0 << 0x10)  // loadtime
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4845
	                   |                                        (1 << 0x12)  // presignals
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4846
	                   |                                        (1 << 0x13)  // extpresignals
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4847
	                   | ((_patches.never_expire_vehicles ? 1 : 0) << 0x16)  // enginespersist
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4848
	                   |                                        (1 << 0x1B)  // multihead
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4849
	                   |                                        (1 << 0x1D)  // lowmemory
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4850
	                   |                                        (1 << 0x1E); // generalfixes
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4851
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4852
	_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
  4853
	                   |        ((_patches.mammoth_trains ? 1 : 0) << 0x08)  // mammothtrains
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4854
	                   |                                        (1 << 0x09)  // trainrefit
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4855
	                   |                                        (0 << 0x0B)  // subsidiaries
5801
7d14e62bc9f3 (svn r7930) -Fix: [FS#520] Wrong GRF flag set for gradual loading (mart3p)
Darkvater
parents: 5776
diff changeset
  4856
	                   |       ((_patches.gradual_loading ? 1 : 0) << 0x0C)  // gradualloading
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4857
	                   |                                        (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
  4858
	                   |                                        (1 << 0x13)  // unifiedmaglevmode - set bit 1 mode
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4859
	                   |                                        (1 << 0x14)  // bridgespeedlimits
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4860
	                   |                                        (1 << 0x16)  // eternalgame
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4861
	                   |                                        (1 << 0x17)  // newtrains
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4862
	                   |                                        (1 << 0x18)  // newrvs
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4863
	                   |                                        (1 << 0x19)  // newships
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4864
	                   |                                        (1 << 0x1A)  // newplanes
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4865
	                   |           ((_patches.signal_side ? 1 : 0) << 0x1B)  // signalsontrafficside
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4866
	                   |       ((_patches.disable_elrails ? 0 : 1) << 0x1C); // electrifiedrailway
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4867
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4868
	_ttdpatch_flags[2] =                                        (1 << 0x01)  // loadallgraphics - obsolote
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4869
	                   |                                        (1 << 0x03)  // semaphores
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4870
	                   |                                        (0 << 0x0B)  // enhancedgui
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4871
	                   |                                        (0 << 0x0C)  // newagerating
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4872
	                   |       ((_patches.build_on_slopes ? 1 : 0) << 0x0D)  // buildonslopes
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4873
	                   |         ((_patches.full_load_any ? 1 : 0) << 0x0E)  // fullloadany
9628
b5c2449616b5 (svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents: 9627
diff changeset
  4874
	                   |                                        (1 << 0x0F)  // planespeed - TODO depends on patch when implemented
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4875
	                   |                                        (0 << 0x10)  // moreindustriesperclimate - obsolete
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4876
	                   |                                        (0 << 0x11)  // moretoylandfeatures
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4877
	                   |                                        (1 << 0x12)  // newstations
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4878
	                   |                                        (1 << 0x13)  // tracktypecostdiff
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4879
	                   |                                        (1 << 0x14)  // manualconvert
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4880
	                   |       ((_patches.build_on_slopes ? 1 : 0) << 0x15)  // buildoncoasts
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4881
	                   |                                        (1 << 0x16)  // canals
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4882
	                   |                                        (1 << 0x17)  // newstartyear
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4883
	                   |    ((_patches.freight_trains > 1 ? 1 : 0) << 0x18)  // freighttrains
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  4884
	                   |                                        (1 << 0x19)  // newhouses
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4885
	                   |                                        (1 << 0x1A)  // newbridges
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  4886
	                   |                                        (1 << 0x1B)  // newtownnames
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  4887
	                   |                                        (1 << 0x1C)  // moreanimation
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4888
	                   |    ((_patches.wagon_speed_limits ? 1 : 0) << 0x1D)  // wagonspeedlimits
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4889
	                   |                                        (1 << 0x1E)  // newshistory
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4890
	                   |                                        (0 << 0x1F); // custombridgeheads
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4891
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4892
	_ttdpatch_flags[3] =                                        (0 << 0x00)  // newcargodistribution
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4893
	                   |                                        (1 << 0x01)  // windowsnap
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4894
	                   |                                        (0 << 0x02)  // townbuildnoroad
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4895
	                   |                                        (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
  4896
	                   |                                        (0 << 0x04)  // aichoosechance
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4897
	                   |                                        (1 << 0x05)  // resolutionwidth
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4898
	                   |                                        (1 << 0x06)  // resolutionheight
9704
197cb8c6ae17 (svn r11221) [NoAI] -Sync: with trunk r11145:11220
glx
parents: 9703
diff changeset
  4899
	                   |                                        (1 << 0x07)  // newindustries
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  4900
	                   |         ((_patches.improved_load ? 1 : 0) << 0x08)  // fifoloading
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4901
	                   |                                        (0 << 0x09)  // townroadbranchprob
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4902
	                   |                                        (0 << 0x0A)  // tempsnowline
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4903
	                   |                                        (1 << 0x0B)  // newcargo
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4904
	                   |                                        (1 << 0x0C)  // enhancemultiplayer
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4905
	                   |                                        (1 << 0x0D)  // onewayroads
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4906
	                   |   ((_patches.nonuniform_stations ? 1 : 0) << 0x0E)  // irregularstations
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4907
	                   |                                        (1 << 0x0F)  // statistics
4657
188335e8d316 (svn r6533) - Fix (r6532): Somebody forgot to add newsounds to the ttdpatch flags...
peter1138
parents: 4656
diff changeset
  4908
	                   |                                        (1 << 0x10)  // newsounds
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4909
	                   |                                        (1 << 0x11)  // autoreplace
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4910
	                   |                                        (1 << 0x12)  // autoslope
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4911
	                   |                                        (0 << 0x13)  // followvehicle
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4912
	                   |                                        (1 << 0x14)  // trams
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  4913
	                   |                                        (0 << 0x15)  // enhancetunnels
9627
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  4914
	                   |                                        (1 << 0x16)  // shortrvs
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  4915
	                   |                                        (1 << 0x17)  // articulatedrvs
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  4916
	                   |                                        (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
  4917
}
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
  4918
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  4919
static void ResetCustomStations()
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  4920
{
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4921
	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
  4922
		if (file->stations == NULL) continue;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4923
		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
  4924
			if (file->stations[i] == NULL) continue;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4925
			StationSpec *statspec = file->stations[i];
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  4926
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  4927
			/* 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
  4928
			if (!statspec->copied_renderdata) {
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4929
				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
  4930
					free((void*)statspec->renderdata[t].seq);
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  4931
				}
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  4932
				free(statspec->renderdata);
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  4933
			}
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  4934
5061
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  4935
			/* Release platforms and layouts */
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  4936
			if (!statspec->copied_layouts) {
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4937
				for (uint l = 0; l < statspec->lengths; l++) {
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4938
					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
  4939
						free(statspec->layouts[l][p]);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  4940
					}
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  4941
					free(statspec->layouts[l]);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  4942
				}
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  4943
				free(statspec->layouts);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  4944
				free(statspec->platforms);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  4945
			}
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
  4946
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
  4947
			/* 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
  4948
			free(statspec);
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  4949
		}
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
  4950
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
  4951
		/* 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
  4952
		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
  4953
		file->stations = NULL;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  4954
	}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  4955
}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  4956
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  4957
static void ResetCustomHouses()
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  4958
{
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  4959
	GRFFile *file;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  4960
	uint i;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  4961
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  4962
	for (file = _first_grffile; file != NULL; file = file->next) {
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  4963
		if (file->housespec == NULL) continue;
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4964
		for (i = 0; i < HOUSE_MAX; i++) {
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4965
			free(file->housespec[i]);
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  4966
		}
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  4967
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  4968
		free(file->housespec);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  4969
		file->housespec = NULL;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  4970
	}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  4971
}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  4972
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4973
static void ResetCustomIndustries()
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4974
{
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4975
	GRFFile *file;
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4976
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4977
	for (file = _first_grffile; file != NULL; file = file->next) {
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4978
		uint i;
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4979
		/* We are verifiying both tiles and industries specs loaded from the grf file
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4980
		 * First, let's deal with industryspec */
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4981
		if (file->industryspec != NULL) {
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4982
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4983
			for (i = 0; i < NUM_INDUSTRYTYPES; i++) {
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4984
				IndustrySpec *ind = file->industryspec[i];
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4985
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4986
				if (ind != NULL) {
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4987
					/* We need to remove the sounds array */
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  4988
					if (HasBit(ind->cleanup_flag, CLEAN_RANDOMSOUNDS)) {
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4989
						free((void*)ind->random_sounds);
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4990
					}
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4991
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4992
					/* We need to remove the tiles layouts */
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  4993
					if (HasBit(ind->cleanup_flag, CLEAN_TILELSAYOUT) && ind->table != NULL) {
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4994
						for (int j = 0; j < ind->num_table; j++) {
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4995
							/* remove the individual layouts */
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4996
							if (ind->table[j] != NULL) {
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4997
								free((IndustryTileTable*)ind->table[j]);
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4998
							}
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  4999
						}
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5000
						/* remove the layouts pointers */
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5001
						free((IndustryTileTable**)ind->table);
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5002
						ind->table = NULL;
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5003
					}
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5004
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5005
					free(ind);
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5006
					ind = NULL;
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5007
				}
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5008
			}
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5009
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5010
			free(file->industryspec);
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5011
			file->industryspec = NULL;
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5012
		}
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5013
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5014
		if (file->indtspec != NULL) {
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5015
			for (i = 0; i < NUM_INDUSTRYTILES; i++) {
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5016
				if (file->indtspec[i] != NULL) {
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5017
					free(file->indtspec[i]);
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5018
					file->indtspec[i] = NULL;
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5019
				}
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5020
			}
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5021
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5022
			free(file->indtspec);
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5023
			file->indtspec = NULL;
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5024
		}
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5025
	}
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5026
}
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5027
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5028
static void ResetNewGRF()
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5029
{
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5030
	GRFFile *next;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5031
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5032
	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
  5033
		next = f->next;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5034
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5035
		free(f->filename);
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5036
		free(f->cargo_list);
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5037
		free(f);
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5038
	}
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5039
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5040
	_first_grffile = NULL;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5041
	_cur_grffile   = NULL;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5042
}
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5043
9627
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  5044
static void ResetNewGRFErrors()
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  5045
{
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  5046
	for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5047
		if (!HasBit(c->flags, GCF_COPY) && c->error != NULL) {
9627
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  5048
			free(c->error->custom_message);
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  5049
			free(c->error->data);
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  5050
			free(c->error);
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  5051
			c->error = NULL;
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  5052
		}
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  5053
	}
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  5054
}
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  5055
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  5056
/**
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
  5057
 * 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
  5058
 * 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
  5059
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5060
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
  5061
{
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  5062
	CleanUpStrings();
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  5063
	CleanUpGRFTownNames();
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  5064
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  5065
	/* Copy/reset original engine info data */
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5066
	SetupEngines();
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  5067
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  5068
	/* Copy/reset original bridge info data
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  5069
	 * First, free sprite table data */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5070
	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
  5071
		if (_bridge[i].sprite_table != NULL) {
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5072
			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
  5073
			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
  5074
		}
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
  5075
	}
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
  5076
	memcpy(&_bridge, &orig_bridge, sizeof(_bridge));
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  5077
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  5078
	/* 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
  5079
	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
  5080
	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
  5081
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  5082
	/* Reset GRM reservations */
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  5083
	memset(&_grm_engines, 0, sizeof(_grm_engines));
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  5084
	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
  5085
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  5086
	/* Unload sprite group data */
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  5087
	UnloadWagonOverrides();
3695
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  5088
	UnloadRotorOverrideSprites();
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  5089
	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
  5090
	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
  5091
	ResetEngineListOrder();
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  5092
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  5093
	/* Reset price base data */
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  5094
	ResetPriceBaseMultipliers();
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5095
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  5096
	/* Reset the curencies array */
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  5097
	ResetCurrencies();
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  5098
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5099
	/* Reset the house array */
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5100
	ResetCustomHouses();
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5101
	ResetHouses();
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5102
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5103
	/* Reset the industries structures*/
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5104
	ResetCustomIndustries();
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5105
	ResetIndustries();
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5106
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  5107
	/* Reset station classes */
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5108
	ResetStationClasses();
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5109
	ResetCustomStations();
2812
f250489941f9 (svn r3360) Fix initialization of engines for precalculation of default refit mask.
peter1138
parents: 2769
diff changeset
  5110
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  5111
	/* Reset canal sprite groups */
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  5112
	memset(_canal_sg, 0, sizeof(_canal_sg));
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  5113
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  5114
	/* Reset the snowline table. */
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  5115
	ClearSnowLine();
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  5116
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5117
	/* Reset NewGRF files */
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5118
	ResetNewGRF();
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5119
9627
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  5120
	/* Reset NewGRF errors. */
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  5121
	ResetNewGRFErrors();
6a7c8ead2328 (svn r10120) [NoAI] -Sync with trunk r10096:r10119
glx
parents: 9626
diff changeset
  5122
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
  5123
	/* 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
  5124
	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
  5125
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
  5126
	/* 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
  5127
	_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
  5128
	_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
  5129
	_traininfo_vehicle_width = 29;
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5130
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  5131
	/* Reset track cost multipliers. */
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  5132
	memcpy(&_railtype_cost_multiplier, &_default_railtype_cost_multiplier, sizeof(_default_railtype_cost_multiplier));
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  5133
9628
b5c2449616b5 (svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents: 9627
diff changeset
  5134
	_loaded_newgrf_features.has_2CC           = false;
b5c2449616b5 (svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents: 9627
diff changeset
  5135
	_loaded_newgrf_features.has_newhouses     = false;
9704
197cb8c6ae17 (svn r11221) [NoAI] -Sync: with trunk r11145:11220
glx
parents: 9703
diff changeset
  5136
	_loaded_newgrf_features.has_newindustries = false;
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
  5137
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5138
	InitializeSoundPool();
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  5139
	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
  5140
}
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
  5141
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
  5142
/** Reset all NewGRFData that was used only while processing data */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5143
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
  5144
{
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  5145
	/* Clear the GOTO labels used for GRF processing */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5146
	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
  5147
		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
  5148
		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
  5149
		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
  5150
	}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  5151
	_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
  5152
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  5153
	/* 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
  5154
	free(_cur_grffile->spritegroups);
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  5155
	_cur_grffile->spritegroups = NULL;
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  5156
	_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
  5157
}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  5158
6473
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5159
static void BuildCargoTranslationMap()
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5160
{
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5161
	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
  5162
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5163
	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
  5164
		const CargoSpec *cs = GetCargo(c);
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5165
		if (!cs->IsValid()) continue;
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5166
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5167
		if (_cur_grffile->cargo_max == 0) {
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5168
			/* 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
  5169
			_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
  5170
		} else {
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5171
			/* 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
  5172
			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
  5173
				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
  5174
					_cur_grffile->cargo_map[c] = i;
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5175
					break;
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5176
				}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5177
			}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5178
		}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5179
	}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5180
}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5181
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
  5182
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
  5183
{
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5184
	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
  5185
	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
  5186
		/* 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
  5187
		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
  5188
		_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
  5189
		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
  5190
	}
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
  5191
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
  5192
	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
  5193
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  5194
	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
  5195
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  5196
	newfile->filename = strdup(config->filename);
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  5197
	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
  5198
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
  5199
	/* 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
  5200
	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
  5201
	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
  5202
	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
  5203
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
  5204
	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
  5205
		_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
  5206
		_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
  5207
	} 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
  5208
		_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
  5209
		_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
  5210
	}
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
  5211
}
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
  5212
5037
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  5213
6471
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5214
/** 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
  5215
 * 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
  5216
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
  5217
	'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
  5218
	'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
  5219
	'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
  5220
	'PLST', 'FZDR',
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5221
	0 };
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5222
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5223
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
  5224
	0 };
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5225
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5226
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
  5227
	'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
  5228
	'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
  5229
	'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
  5230
	'PLST', 'FZDR',
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5231
	0 };
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5232
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5233
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
  5234
	'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
  5235
	'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
  5236
	0 };
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5237
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5238
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
  5239
	_default_refitmasks_rail,
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5240
	_default_refitmasks_road,
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5241
	_default_refitmasks_ships,
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5242
	_default_refitmasks_aircraft,
5037
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  5243
};
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  5244
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  5245
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5246
/**
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5247
 * 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
  5248
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5249
static void CalculateRefitMasks()
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5250
{
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5251
	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
  5252
		uint32 mask = 0;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5253
		uint32 not_mask = 0;
6610
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5254
		uint32 xor_mask = 0;
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5255
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5256
		if (_engine_info[engine].refit_mask != 0) {
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5257
			const GRFFile *file = GetEngineGRF(engine);
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5258
			if (file != NULL && file->cargo_max != 0) {
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5259
				/* Apply cargo translation table to the refit mask */
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5260
				uint num_cargo = min(32, file->cargo_max);
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5261
				for (uint i = 0; i < num_cargo; i++) {
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5262
					if (!HasBit(_engine_info[engine].refit_mask, i)) continue;
6610
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5263
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5264
					CargoID c = GetCargoIDByLabel(file->cargo_list[i]);
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5265
					if (c == CT_INVALID) continue;
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5266
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5267
					SetBit(xor_mask, c);
6610
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5268
				}
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5269
			} else {
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5270
				/* No cargo table, so use the cargo bitnum values */
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5271
				for (CargoID c = 0; c < NUM_CARGO; c++) {
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5272
					const CargoSpec *cs = GetCargo(c);
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5273
					if (!cs->IsValid()) continue;
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5274
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5275
					if (HasBit(_engine_info[engine].refit_mask, cs->bitnum)) SetBit(xor_mask, c);
6610
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5276
				}
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5277
			}
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5278
		}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5279
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5280
		if (cargo_allowed[engine] != 0) {
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  5281
			/* Build up the list of cargo types from the set cargo classes. */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5282
			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
  5283
				const CargoSpec *cs = GetCargo(i);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5284
				if (cargo_allowed[engine]    & cs->classes) SetBit(mask,     i);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5285
				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
  5286
			}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5287
		} else {
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  5288
			/* 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
  5289
			if (xor_mask == 0 && (
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  5290
						GetEngine(engine)->type != VEH_TRAIN || (
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  5291
							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
  5292
							RailVehInfo(engine)->railveh_type != RAILVEH_WAGON
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  5293
						)
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  5294
					)) {
6471
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5295
				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
  5296
				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
  5297
					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
  5298
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5299
					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
  5300
					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
  5301
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5302
					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
  5303
				}
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  5304
			}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5305
		}
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
  5306
		_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
  5307
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
  5308
		/* 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
  5309
		 * 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
  5310
		switch (GetEngine(engine)->type) {
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  5311
			default: NOT_REACHED();
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  5312
			case VEH_AIRCRAFT: break;
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  5313
			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
  5314
				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
  5315
				if (rvi->cargo_type == CT_INVALID) rvi->cargo_type = FindFirstRefittableCargo(engine);
6608
80bc656cc6fb (svn r9094) -Codechange: Don't set up refit masks for engine types not in the current climate, and exclude engine types if their cargo type is invalid and they have no refittable type.
peter1138
parents: 6607
diff changeset
  5316
				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
  5317
				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
  5318
			}
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  5319
			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
  5320
				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
  5321
				if (rvi->cargo_type == CT_INVALID) rvi->cargo_type = FindFirstRefittableCargo(engine);
6608
80bc656cc6fb (svn r9094) -Codechange: Don't set up refit masks for engine types not in the current climate, and exclude engine types if their cargo type is invalid and they have no refittable type.
peter1138
parents: 6607
diff changeset
  5322
				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
  5323
				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
  5324
			}
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  5325
			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
  5326
				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
  5327
				if (svi->cargo_type == CT_INVALID) svi->cargo_type = FindFirstRefittableCargo(engine);
6608
80bc656cc6fb (svn r9094) -Codechange: Don't set up refit masks for engine types not in the current climate, and exclude engine types if their cargo type is invalid and they have no refittable type.
peter1138
parents: 6607
diff changeset
  5328
				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
  5329
				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
  5330
			}
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
  5331
		}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5332
	}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5333
}
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
  5334
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5335
/** Add all new houses to the house array. House properties can be set at any
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5336
 * time in the GRF file, so we can only add a house spec to the house array
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5337
 * after the file has finished loading. We also need to check the dates, due to
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5338
 * the TTDPatch behaviour described below that we need to emulate. */
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5339
static void FinaliseHouseArray()
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5340
{
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5341
	/* If there are no houses with start dates before 1930, then all houses
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5342
	 * with start dates of 1930 have them reset to 0. This is in order to be
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5343
	 * compatible with TTDPatch, where if no houses have start dates before
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5344
	 * 1930 and the date is before 1930, the game pretends that this is 1930.
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5345
	 * If there have been any houses defined with start dates before 1930 then
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5346
	 * the dates are left alone.
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5347
	 * On the other hand, why 1930? Just 'fix' the houses with the lowest
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5348
	 * minimum introduction date to 0.
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5349
	 */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5350
	Year min_date = MAX_YEAR;
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5351
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5352
	for (GRFFile *file = _first_grffile; file != NULL; file = file->next) {
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5353
		if (file->housespec == NULL) continue;
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5354
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5355
		for (int i = 0; i < HOUSE_MAX; i++) {
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5356
			HouseSpec *hs = file->housespec[i];
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5357
			if (hs != NULL) {
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  5358
				_house_mngr.SetEntitySpec(hs);
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5359
				if (hs->min_date < min_date) min_date = hs->min_date;
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5360
			}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5361
		}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5362
	}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5363
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5364
	if (min_date != 0) {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5365
		for (int i = 0; i < HOUSE_MAX; i++) {
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5366
			HouseSpec *hs = GetHouseSpecs(i);
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5367
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5368
			if (hs->enabled && hs->min_date == min_date) hs->min_date = 0;
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5369
		}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5370
	}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5371
}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5372
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5373
/** Add all new industries to the industry array. Industry properties can be set at any
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5374
 * time in the GRF file, so we can only add a industry spec to the industry array
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5375
 * after the file has finished loading. */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5376
static void FinaliseIndustriesArray()
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5377
{
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5378
	for (GRFFile *file = _first_grffile; file != NULL; file = file->next) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5379
		if (file->industryspec != NULL) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5380
			for (int i = 0; i < NUM_INDUSTRYTYPES; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5381
				IndustrySpec *indsp = file->industryspec[i];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5382
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5383
				if (indsp != NULL && indsp->enabled) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5384
					StringID strid;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5385
					/* process the conversion of text at the end, so to be sure everything will be fine
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5386
					 * and available.  Check if it does not return undefind marker, which is a very good sign of a
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5387
					 * substitute industry who has not changed the string been examined, thus using it as such */
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5388
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->name);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5389
					if (strid != STR_UNDEFINED) indsp->name = strid;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5390
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5391
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->closure_text);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5392
					if (strid != STR_UNDEFINED) indsp->closure_text = strid;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5393
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5394
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->production_up_text);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5395
					if (strid != STR_UNDEFINED) indsp->production_up_text = strid;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5396
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5397
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->production_down_text);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5398
					if (strid != STR_UNDEFINED) indsp->production_down_text = strid;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5399
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5400
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->new_industry_text);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5401
					if (strid != STR_UNDEFINED) indsp->new_industry_text = strid;
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5402
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5403
					_industry_mngr.SetEntitySpec(indsp);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5404
					_loaded_newgrf_features.has_newindustries = true;
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5405
				}
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5406
			}
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5407
		}
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5408
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5409
		if (file->indtspec != NULL) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5410
			for (int i = 0; i < NUM_INDUSTRYTILES; i++) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5411
				IndustryTileSpec *indtsp = file->indtspec[i];
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5412
				if (indtsp != NULL) {
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5413
					_industile_mngr.SetEntitySpec(indtsp);
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5414
				}
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5415
			}
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5416
		}
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5417
	}
9641
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5418
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5419
	for (uint j = 0; j < NUM_INDUSTRYTYPES; j++) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5420
		IndustrySpec *indsp = &_industry_specs[j];
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5421
		if (indsp->enabled && indsp->grf_prop.grffile != NULL) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5422
			for (uint i = 0; i < 3; i++) {
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5423
				indsp->conflicting[i] = MapNewGRFIndustryType(indsp->conflicting[i], indsp->grf_prop.grffile->grfid);
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5424
			}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5425
		}
855e32c08c9b (svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents: 9631
diff changeset
  5426
	}
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5427
}
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5428
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5429
/** Each cargo string needs to be mapped from TTDPatch to OpenTTD string IDs.
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5430
 * This is done after loading so that strings from Action 4 will be mapped
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5431
 * properly. */
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5432
static void MapNewCargoStrings()
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5433
{
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5434
	for (CargoID c = 0; c < NUM_CARGO; c++) {
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5435
		CargoSpec *cs = &_cargo[c];
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5436
		/* Don't map if the cargo is unavailable or not from NewGRF */
9718
f82a4facea8b (svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents: 9704
diff changeset
  5437
		if (cs->grfid == 0) continue;
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5438
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5439
		cs->name         = MapGRFStringID(cs->grfid, cs->name);
9686
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9641
diff changeset
  5440
		cs->name_single  = MapGRFStringID(cs->grfid, cs->name_single);
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5441
		cs->units_volume = MapGRFStringID(cs->grfid, cs->units_volume);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5442
		cs->quantifier   = MapGRFStringID(cs->grfid, cs->quantifier);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5443
		cs->abbrev       = MapGRFStringID(cs->grfid, cs->abbrev);
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5444
	}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5445
}
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5446
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5447
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5448
/* 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
  5449
 * 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
  5450
 * partial implementation yet). */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5451
/* 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
  5452
 * 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
  5453
 * 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
  5454
static void DecodeSpecialSprite(uint num, GrfLoadingStage stage)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5455
{
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  5456
	/* 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
  5457
	 * 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
  5458
	 * 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
  5459
	 * "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
  5460
	 * 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
  5461
	 * 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
  5462
	 * 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
  5463
	 * 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
  5464
	 * --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
  5465
	/* 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
  5466
	 * 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
  5467
	 * 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
  5468
	static const SpecialSpriteHandler handlers[][GLS_END] = {
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5469
		/* 0x00 */ { NULL,     SafeChangeInfo, NULL,       NULL,           ReserveChangeInfo, FeatureChangeInfo, },
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  5470
		/* 0x01 */ { SkipAct1, SkipAct1,  SkipAct1,        SkipAct1,       SkipAct1,          NewSpriteSet, },
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  5471
		/* 0x02 */ { NULL,     NULL,      NULL,            NULL,           NULL,              NewSpriteGroup, },
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5472
		/* 0x03 */ { NULL,     GRFUnsafe, NULL,            NULL,           NULL,              FeatureMapSpriteGroup, },
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5473
		/* 0x04 */ { NULL,     NULL,      NULL,            NULL,           NULL,              FeatureNewName, },
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  5474
		/* 0x05 */ { SkipAct5, SkipAct5,  SkipAct5,        SkipAct5,       SkipAct5,          GraphicsNew, },
9545
179f651eb116 (svn r9468) [NoAI] -Sync with trunk r9431:9467
truelight
parents: 9517
diff changeset
  5475
		/* 0x06 */ { NULL,     NULL,      NULL,            CfgApply,       CfgApply,          CfgApply, },
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5476
		/* 0x07 */ { NULL,     NULL,      NULL,            NULL,           SkipIf,            SkipIf, },
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  5477
		/* 0x08 */ { ScanInfo, NULL,      NULL,            GRFInfo,        GRFInfo,           GRFInfo, },
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5478
		/* 0x09 */ { NULL,     NULL,      NULL,            SkipIf,         SkipIf,            SkipIf, },
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  5479
		/* 0x0A */ { SkipActA, SkipActA,  SkipActA,        SkipActA,       SkipActA,          SpriteReplace, },
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5480
		/* 0x0B */ { NULL,     NULL,      NULL,            GRFLoadError,   GRFLoadError,      GRFLoadError, },
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5481
		/* 0x0C */ { NULL,     NULL,      NULL,            GRFComment,     NULL,              GRFComment, },
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5482
		/* 0x0D */ { NULL,     SafeParamSet, NULL,         ParamSet,       ParamSet,          ParamSet, },
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5483
		/* 0x0E */ { NULL,     SafeGRFInhibit, NULL,       GRFInhibit,     GRFInhibit,        GRFInhibit, },
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  5484
		/* 0x0F */ { NULL,     GRFUnsafe, NULL,            FeatureTownName, NULL,             NULL, },
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5485
		/* 0x10 */ { NULL,     NULL,      DefineGotoLabel, NULL,           NULL,              NULL, },
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5486
		/* 0x11 */ { NULL,     GRFUnsafe, NULL,            NULL,           NULL,              GRFSound, },
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5487
		/* 0x12 */ { NULL,     NULL,      NULL,            NULL,           NULL,              LoadFontGlyph, },
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5488
		/* 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
  5489
	};
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  5490
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5491
	byte* buf;
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  5492
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5493
	if (_preload_sprite == NULL) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5494
		/* 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
  5495
		 * 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
  5496
		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
  5497
		FioReadBlock(buf, num);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5498
	} else {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5499
		/* 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
  5500
		buf = _preload_sprite;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5501
		_preload_sprite = NULL;
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5502
		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
  5503
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5504
		/* 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
  5505
		FioSeekTo(num, SEEK_CUR);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5506
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5507
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5508
	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
  5509
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5510
	if (action == 0xFF) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  5511
		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
  5512
		GRFDataBlock(buf, num);
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5513
	} else if (action == 0xFE) {
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5514
		grfmsg(7, "DecodeSpecialSprite: Handling import block in stage %d", stage);
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5515
		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
  5516
	} else if (action >= lengthof(handlers)) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  5517
		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
  5518
	} else if (handlers[action][stage] == NULL) {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  5519
		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
  5520
	} else {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  5521
		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
  5522
		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
  5523
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5524
	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
  5525
}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5526
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5527
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  5528
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
  5529
{
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  5530
	const char *filename = config->filename;
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5531
	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
  5532
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5533
	/* 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
  5534
	 * 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
  5535
	 * 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
  5536
	 * 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
  5537
	 * 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
  5538
	 *
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5539
	 * 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
  5540
	 * 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
  5541
	 * 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
  5542
	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
  5543
		_cur_grffile = GetFileByFilename(filename);
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5544
		if (_cur_grffile == NULL) error("File '%s' lost in cache.\n", filename);
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  5545
		if (stage == GLS_RESERVE && config->status != GCS_INITIALISED) return;
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5546
		if (stage == GLS_ACTIVATION && !HasBit(config->flags, GCF_RESERVED)) return;
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5547
		_cur_grffile->is_ottdfile = config->IsOpenTTDBaseGRF();
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5548
	}
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5549
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5550
	if (file_index > LAST_GRF_SLOT) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5551
		DEBUG(grf, 0, "'%s' is not loaded as the maximum number of GRFs has been reached", filename);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5552
		config->status = GCS_DISABLED;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5553
		config->error  = CallocT<GRFError>(1);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5554
		config->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5555
		config->error->message  = STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED;
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5556
		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
  5557
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5558
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5559
	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
  5560
	_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
  5561
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  5562
	_cur_grfconfig = config;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  5563
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  5564
	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
  5565
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5566
	/* 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
  5567
	 * 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
  5568
	 * 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
  5569
	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
  5570
		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
  5571
	} else {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  5572
		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
  5573
		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
  5574
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5575
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5576
	_skip_sprites = 0; // XXX
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  5577
	_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
  5578
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5579
	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
  5580
		byte type = FioReadByte();
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  5581
		_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
  5582
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5583
		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
  5584
			if (_skip_sprites == 0) {
2958
3f8946daf55f (svn r3520) Remove unused parameters from some functions
tron
parents: 2935
diff changeset
  5585
				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
  5586
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
  5587
				/* 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
  5588
				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
  5589
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
  5590
				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
  5591
			} 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
  5592
				FioSkipBytes(num);
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  5593
			}
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  5594
		} else {
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  5595
			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
  5596
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5597
			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
  5598
			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
  5599
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5600
			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
  5601
				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
  5602
			} 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
  5603
				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
  5604
					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
  5605
					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
  5606
						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
  5607
						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
  5608
					} 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
  5609
						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
  5610
						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
  5611
						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
  5612
					}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5613
				}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5614
			}
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  5615
		}
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
  5616
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5617
		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
  5618
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5619
}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5620
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5621
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
  5622
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  5623
extern void SortTownGeneratorNames();
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  5624
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5625
static void AfterLoadGRFs()
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5626
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5627
	/* Update the bitmasks for the vehicle lists */
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5628
	Player *p;
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5629
	FOR_ALL_PLAYERS(p) {
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5630
		p->avail_railtypes = GetPlayerRailtypes(p->index);
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5631
		p->avail_roadtypes = GetPlayerRoadtypes(p->index);
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5632
	}
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
  5633
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5634
	/* Pre-calculate all refit masks after loading GRF files. */
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5635
	CalculateRefitMasks();
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5636
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5637
	/* Set the block size in the depot windows based on vehicle sprite sizes */
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5638
	InitDepotWindowBlockSizes();
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5639
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5640
	/* Add all new houses to the house array. */
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5641
	FinaliseHouseArray();
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5642
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5643
	/* Add all new industries to the industry array. */
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5644
	FinaliseIndustriesArray();
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9629
diff changeset
  5645
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  5646
	/* Create dynamic list of industry legends for smallmap_gui.cpp */
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  5647
	BuildIndustriesLegend();
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  5648
9517
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5649
	/* Map cargo strings. This is a separate step because cargos are
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5650
	 * loaded before strings... */
be1775555bbd (svn r9431) [NoAI] -Sync with trunk r9394:9430
truelight
parents: 9505
diff changeset
  5651
	MapNewCargoStrings();
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  5652
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  5653
	/* Update the townname generators list */
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  5654
	SortTownGeneratorNames();
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5655
}
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5656
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
  5657
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
  5658
{
2930
a3bfaa5a9222 (svn r3486) - NewGRF fix: Always reinitialize the ttdpatch flags as patch settings may have changed.
peter1138
parents: 2895
diff changeset
  5659
	InitializeGRFSpecial();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5660
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
  5661
	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
  5662
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5663
	/*
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5664
	 * Reset the status of all files, so we can 'retry' to load them.
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5665
	 * This is needed when one for example rearranges the NewGRFs in-game
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5666
	 * and a previously disabled NewGRF becomes useable. If it would not
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5667
	 * be reset, the NewGRF would remain disabled even though it should
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5668
	 * have been enabled.
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5669
	 */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5670
	for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5671
		if (c->status != GCS_NOT_FOUND) c->status = GCS_UNKNOWN;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5672
	}
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
  5673
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
  5674
	/* 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
  5675
	 * 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
  5676
	 * and load information from it. */
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5677
	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
  5678
		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
  5679
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5680
		_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
  5681
		_cur_spriteid = load_index;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5682
		for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  5683
			if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND) continue;
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5684
			if (stage > GLS_INIT && HasBit(c->flags, GCF_INIT_ONLY)) continue;
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  5685
9505
9711235f5693 (svn r9396) [NoAI] -Sync with trunk r9362:9393
glx
parents: 9476
diff changeset
  5686
			/* @todo usererror() */
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9628
diff changeset
  5687
			if (!FioCheckFileExists(c->filename)) error("NewGRF file is missing '%s'", c->filename);
3628
bd4a6601e5a2 (svn r4527) - Feature [NewGRF]: Add support for specifying parameters to GRF files. Usage: "mygrf = 1". You can pass up to 128 parameters, each one seperated by a comma or a space-character. Big thanks to peter1138 for the inspiration and examples.
Darkvater
parents: 3620
diff changeset
  5688
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
  5689
			if (stage == GLS_LABELSCAN) InitNewGRFFile(c, _cur_spriteid);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5690
			LoadNewGRFFile(c, slot++, stage);
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
  5691
			if (stage == GLS_RESERVE) {
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5692
				SetBit(c->flags, GCF_RESERVED);
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5693
			} else if (stage == GLS_ACTIVATION) {
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5694
				ClrBit(c->flags, GCF_RESERVED);
5727
0fd7e97094e2 (svn r7760) -Codechange: Debug messages for newgrf showed the starting sprite, not the current sprite index. Also only output the debug message during activation, when sprites are loaded.
peter1138
parents: 5726
diff changeset
  5695
				ClearTemporaryNewGRFData();
6473
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5696
				BuildCargoTranslationMap();
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9599
diff changeset
  5697
				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
  5698
			}
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
  5699
		}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5700
	}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5701
9476
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5702
	/* Call any functions that should be run after GRFs have been loaded. */
1d1ed96f32ad (svn r9323) [NoAI] -Sync with trunk r9206:9322
truelight
parents: 6614
diff changeset
  5703
	AfterLoadGRFs();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5704
}
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  5705
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  5706
bool HasGrfMiscBit(GrfMiscBit bit)
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  5707
{
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9718
diff changeset
  5708
	return HasBit(_misc_grf_features, bit);
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
  5709
}