newgrf.c
author matthijs
Wed, 22 Mar 2006 22:26:16 +0000
branch0.4.5
changeset 9958 bed516c67d61
parent 2935 ebbf3553f15c
child 2958 3f8946daf55f
permissions -rw-r--r--
(svn r4041) [Debian] Change next version number to 0.4.6 instead of 0.4.5.1.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include <stdarg.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1883
diff changeset
     7
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1183
diff changeset
     8
#include "debug.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "fileio.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
    11
#include "functions.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "engine.h"
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
    13
#include "spritecache.h"
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    14
#include "station.h"
405
6830ae7a0d5d (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents: 404
diff changeset
    15
#include "sprite.h"
452
520e4ed6945d (svn r662) [newgrf] Moved grfspecial.c to newgrf.c/newgrf.h
dominik
parents: 449
diff changeset
    16
#include "newgrf.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2013
diff changeset
    17
#include "variables.h"
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
    18
#include "bridge.h"
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
    19
#include "economy.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
/* TTDPatch extended GRF format codec
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
 * (c) Petr Baudis 2004 (GPL'd)
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
    23
 * 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
    24
 *
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
 * Contains portions of documentation by TTDPatch team.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
 * 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
    27
 * 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
    28
 * 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
    29
455
e7ac799e1437 (svn r665) code fixes for newgrf.c/newgrf.h
dominik
parents: 452
diff changeset
    30
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
    31
uint16 _custom_sprites_base;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
    32
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
    33
static uint _file_index; // XXX
420
d3a089648ec3 (svn r617) -newgrf: Support for parameter 0x8E (train Y-pitch in info windows) both setting and testing. This should fix displaced wagons in DBSetXL as reported by DarkVater. (pasky)
darkvater
parents: 419
diff changeset
    34
extern int _traininfo_vehicle_pitch;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
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
    36
static GRFFile *_cur_grffile;
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    37
GRFFile *_first_grffile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
static int _cur_spriteid;
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
    39
static int _cur_stage;
2849
73c752b82488 (svn r3397) - NewGRF fix: Show nfo sprite number instead of current sprite id for warning messages -- this makes this output more useful...
peter1138
parents: 2846
diff changeset
    40
static int nfo_line;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
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
    42
/* 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
    43
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
    44
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
    45
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    46
typedef enum grfspec_feature {
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    47
	GSF_TRAIN,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    48
	GSF_ROAD,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    49
	GSF_SHIP,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    50
	GSF_AIRCRAFT,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    51
	GSF_STATION,
2438
eaef2b29fa3d (svn r2964) Fix: newgrf: Include missing grf feature canal.
peter1138
parents: 2421
diff changeset
    52
	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
    53
	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
    54
	GSF_TOWNHOUSE,
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
    55
	GSF_GLOBALVAR,
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    56
} grfspec_feature;
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    57
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    58
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
typedef void (*SpecialSpriteHandler)(byte *buf, int len);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    61
static const int _vehcounts[4] = {
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    62
	/* GSF_TRAIN */    NUM_TRAIN_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    63
	/* GSF_ROAD */     NUM_ROAD_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    64
	/* GSF_SHIP */     NUM_SHIP_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    65
	/* GSF_AIRCRAFT */ NUM_AIRCRAFT_ENGINES
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    66
};
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    67
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
static const int _vehshifts[4] = {
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    69
	/* GSF_TRAIN */    0,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    70
	/* GSF_ROAD */     ROAD_ENGINES_INDEX,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    71
	/* GSF_SHIP */     SHIP_ENGINES_INDEX,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    72
	/* GSF_AIRCRAFT */ AIRCRAFT_ENGINES_INDEX,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
    75
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
    76
static uint16 cargo_disallowed[TOTAL_NUM_ENGINES];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    78
/* Debugging messages policy:
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    79
 *
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    80
 * These should be the severities used for direct DEBUG() calls
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    81
 * (there is room for exceptions, but you have to have a good cause):
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    82
 *
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    83
 * 0..2 - dedicated to grfmsg()
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    84
 * 3
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    85
 * 4
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    86
 * 5
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    87
 * 6 - action handler entry reporting - one per action
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    88
 * 7 - basic action progress reporting - in loops, only single one allowed
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    89
 * 8 - more detailed progress reporting - less important stuff, in deep loops etc
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    90
 * 9 - extremely detailed progress reporting - detailed reports inside of deep loops and so
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    91
 */
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    92
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    93
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    94
typedef enum grfmsg_severity {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
	GMS_NOTICE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
	GMS_WARN,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
	GMS_ERROR,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
	GMS_FATAL,
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    99
} grfmsg_severity;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   101
static void CDECL grfmsg(grfmsg_severity severity, const char *str, ...)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   103
	static const char* const severitystr[] = {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   104
		"Notice",
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   105
		"Warning",
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   106
		"Error",
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   107
		"Fatal"
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   108
	};
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   109
	int export_severity = 0;
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 51
diff changeset
   110
	char buf[1024];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
	va_start(va, str);
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   114
	vsnprintf(buf, sizeof(buf), str, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
	va_end(va);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   116
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   117
	export_severity = 2 - (severity == GMS_FATAL ? 2 : severity);
2849
73c752b82488 (svn r3397) - NewGRF fix: Show nfo sprite number instead of current sprite id for warning messages -- this makes this output more useful...
peter1138
parents: 2846
diff changeset
   118
	DEBUG(grf, export_severity) ("[%s:%d][%s] %s", _cur_grffile->filename, nfo_line, severitystr[severity], buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   121
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   122
#define check_length(real, wanted, where) \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   123
do { \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   124
	if (real < wanted) { \
2849
73c752b82488 (svn r3397) - NewGRF fix: Show nfo sprite number instead of current sprite id for warning messages -- this makes this output more useful...
peter1138
parents: 2846
diff changeset
   125
		grfmsg(GMS_ERROR, "%s: Invalid special sprite length %d (expected %d)!", \
73c752b82488 (svn r3397) - NewGRF fix: Show nfo sprite number instead of current sprite id for warning messages -- this makes this output more useful...
peter1138
parents: 2846
diff changeset
   126
		       where, real, wanted); \
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   127
		return; \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   128
	} \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   129
} while (0)
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   130
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   131
500
ef288590e096 (svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents: 490
diff changeset
   132
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
   133
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
	return *(*buf)++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
static uint16 grf_load_word(byte **buf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
	uint16 val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
	byte *p = *buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
	val = p[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
	val |= p[1] << 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
	*buf = p + 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
	return val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   147
static uint16 grf_load_extended(byte** buf)
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   148
{
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   149
	uint16 val;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   150
	val = grf_load_byte(buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   151
	if (val == 0xFF) val = grf_load_word(buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   152
	return val;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   153
}
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   154
2324
117bd73a0731 (svn r2850) [newgrf] Patch from peter1139
miham
parents: 2204
diff changeset
   155
static uint32 grf_load_dword(byte **buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
	uint32 val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
	byte *p = *buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
	val = p[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	val |= p[1] << 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	val |= p[2] << 16;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
	val |= p[3] << 24;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	*buf = p + 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
	return val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   167
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   168
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
   169
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   170
	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
   171
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   172
	for (file = _first_grffile; file != NULL; file = file->next) {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   173
		if (file->grfid == grfid) break;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   174
	}
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
   175
	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
   176
}
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
   177
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   178
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
   179
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   180
	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
   181
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   182
	for (file = _first_grffile; file != NULL; file = file->next) {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   183
		if (strcmp(file->filename, filename) == 0) break;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   184
	}
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
   185
	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
   186
}
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
   187
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
   188
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   189
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
   190
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   191
#define FOR_EACH_OBJECT for (i = 0; i < numinfo; i++)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
static void dewagonize(int condition, int engine)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
	EngineInfo *ei = &_engine_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   198
	if (condition != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
		ei->unk2 &= ~0x80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
		rvi->flags &= ~2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
		ei->unk2 |= 0x80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
		rvi->flags |= 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   207
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
   208
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
	EngineInfo *ei = &_engine_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
	byte *buf = *bufp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
	int i;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   213
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
	switch (prop) {
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   216
		case 0x05: { /* Track type */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   217
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
				uint8 tracktype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
2530
b8d5a5284024 (svn r3059) Use bitfields to encode railtype and climates of engines instead of manual shifting/anding
tron
parents: 2516
diff changeset
   220
				ei[i].railtype = tracktype;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   222
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   223
		case 0x08: { /* AI passenger service */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
			/* TODO */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   225
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
				grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   228
			ret = true;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   229
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   230
		case 0x09: { /* Speed */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   231
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
				uint16 speed = grf_load_word(&buf);
2476
5beb5ae528fd (svn r3002) -Fix, Newgrf: Max speed of 0xFFFF means no max speed.
peter1138
parents: 2464
diff changeset
   233
				if (speed == 0xFFFF)
5beb5ae528fd (svn r3002) -Fix, Newgrf: Max speed of 0xFFFF means no max speed.
peter1138
parents: 2464
diff changeset
   234
					speed = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
				rvi[i].max_speed = speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   238
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   239
		case 0x0B: { /* Power */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   240
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
				uint16 power = grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   243
				if (rvi[i].flags & RVI_MULTIHEAD)
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   244
					power /= 2;
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   245
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
				rvi[i].power = power;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
				dewagonize(power, engine + i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   249
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   250
		case 0x0D: { /* Running cost factor */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   251
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
				uint8 runcostfact = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   254
				if (rvi[i].flags & RVI_MULTIHEAD)
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   255
					runcostfact /= 2;
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   256
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
				rvi[i].running_cost_base = runcostfact;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   259
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   260
		case 0x0E: { /* Running cost base */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   261
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
				uint32 base = grf_load_dword(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
				switch (base) {
2840
d68a605b2087 (svn r3388) - NewGRF: Allow train running cost class to differ from engine class. Also fix typo in r3384.
peter1138
parents: 2838
diff changeset
   265
					case 0x4C30: rvi[i].running_cost_class = 0; break;
d68a605b2087 (svn r3388) - NewGRF: Allow train running cost class to differ from engine class. Also fix typo in r3384.
peter1138
parents: 2838
diff changeset
   266
					case 0x4C36: rvi[i].running_cost_class = 1; break;
d68a605b2087 (svn r3388) - NewGRF: Allow train running cost class to differ from engine class. Also fix typo in r3384.
peter1138
parents: 2838
diff changeset
   267
					case 0x4C3C: rvi[i].running_cost_class = 2; break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   270
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   271
		case 0x12: { /* Sprite ID */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   272
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
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
   275
				/* 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
   276
				 * as an array index, so we need it to be half the original value. */
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
   277
				if (spriteid < 0xFD)
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
   278
					spriteid >>= 1;
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
   279
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
				rvi[i].image_index = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   282
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   283
		case 0x13: { /* Dual-headed */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   284
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
				uint8 dual = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   287
				if (dual != 0) {
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   288
					if (!(rvi[i].flags & RVI_MULTIHEAD)) {
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   289
						// adjust power and running cost if needed
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   290
						rvi[i].power /= 2;
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   291
						rvi[i].running_cost_base /= 2;
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   292
					}
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   293
					rvi[i].flags |= RVI_MULTIHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
				} else {
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   295
					if (rvi[i].flags & RVI_MULTIHEAD) {
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   296
						// adjust power and running cost if needed
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   297
						rvi[i].power *= 2;
2840
d68a605b2087 (svn r3388) - NewGRF: Allow train running cost class to differ from engine class. Also fix typo in r3384.
peter1138
parents: 2838
diff changeset
   298
						rvi[i].running_cost_base *= 2;
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   299
					}
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   300
					rvi[i].flags &= ~RVI_MULTIHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   303
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   304
		case 0x14: { /* Cargo capacity */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   305
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
				uint8 capacity = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
				rvi[i].capacity = capacity;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   310
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   311
		case 0x15: { /* Cargo type */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   312
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
				uint8 ctype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
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
   315
				if (ctype < NUM_CARGO) {
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   316
					rvi[i].cargo_type = ctype;
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   317
				} else {
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   318
					grfmsg(GMS_NOTICE, "RailVehicleChangeInfo: Invalid cargo type %d, ignoring.", ctype);
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   319
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   321
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   322
		case 0x16: { /* Weight */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   323
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
				uint8 weight = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
2542
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   326
				SB(rvi[i].weight, 0, 8, weight);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   328
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   329
		case 0x17: { /* Cost factor */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   330
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
				uint8 cfactor = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
				rvi[i].base_cost = cfactor;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   335
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   336
		case 0x18: { /* AI rank */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
			/* TODO: _railveh_score should be merged to _rail_vehicle_info. */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   338
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
				grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   341
			ret = true;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   342
		} break;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   343
		case 0x19: { /* Engine traction type */
2838
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   344
			/* What do the individual numbers mean?
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   345
			 * 0x00 .. 0x07: Steam
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   346
			 * 0x08 .. 0x27: Diesel
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   347
			 * 0x28 .. 0x31: Electric
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   348
			 * 0x32 .. 0x37: Monorail
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   349
			 * 0x38 .. 0x41: Maglev
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   350
			 */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   351
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
				uint8 traction = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
				int engclass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
				if (traction <= 0x07)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
					engclass = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
				else if (traction <= 0x27)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
					engclass = 1;
2838
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   359
				else if (traction <= 0x41)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
					engclass = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
				else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
				rvi[i].engclass = engclass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   366
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   367
		case 0x1B: { /* Powered wagons power bonus */
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   368
			FOR_EACH_OBJECT {
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   369
				uint16 wag_power = grf_load_word(&buf);
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   370
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   371
				rvi[i].pow_wag_power = wag_power;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   372
			}
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   373
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   374
		case 0x1D: { /* Refit cargo */
440
778ed2e8de1c (svn r649) Support for custom rail vehicle refit bitmasks. (pasky)
miham
parents: 439
diff changeset
   375
			FOR_EACH_OBJECT {
778ed2e8de1c (svn r649) Support for custom rail vehicle refit bitmasks. (pasky)
miham
parents: 439
diff changeset
   376
				uint32 refit_mask = grf_load_dword(&buf);
778ed2e8de1c (svn r649) Support for custom rail vehicle refit bitmasks. (pasky)
miham
parents: 439
diff changeset
   377
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   378
				_engine_info[engine + i].refit_mask = refit_mask;
440
778ed2e8de1c (svn r649) Support for custom rail vehicle refit bitmasks. (pasky)
miham
parents: 439
diff changeset
   379
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   380
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   381
		case 0x1E: { /* Callback */
1895
398f156479c8 (svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents: 1894
diff changeset
   382
			FOR_EACH_OBJECT {
398f156479c8 (svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents: 1894
diff changeset
   383
				byte callbacks = grf_load_byte(&buf);
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   384
1895
398f156479c8 (svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents: 1894
diff changeset
   385
				rvi[i].callbackmask = callbacks;
398f156479c8 (svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents: 1894
diff changeset
   386
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   387
		} break;
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   388
		case 0x21: { /* Shorter vehicle */
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   389
			FOR_EACH_OBJECT {
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   390
				byte shorten_factor = grf_load_byte(&buf);
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   391
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   392
				rvi[i].shorten_factor = shorten_factor;
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   393
			}
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   394
		} break;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   395
		case 0x22: { /* Visual effect */
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   396
			// see note in engine.h about rvi->visual_effect
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   397
			FOR_EACH_OBJECT {
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   398
				byte visual = grf_load_byte(&buf);
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   399
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   400
				rvi[i].visual_effect = visual;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   401
			}
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   402
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   403
		case 0x23: { /* Powered wagons weight bonus */
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   404
			FOR_EACH_OBJECT {
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   405
				byte wag_weight = grf_load_byte(&buf);
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   406
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   407
				rvi[i].pow_wag_weight = wag_weight;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   408
			}
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   409
		} break;
2542
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   410
		case 0x24: { /* High byte of vehicle weight */
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   411
			FOR_EACH_OBJECT {
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   412
				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
   413
2545
d1965652e523 (svn r3074) -NewGrf: Fix stupid typo in weight setting.
peter1138
parents: 2542
diff changeset
   414
				if (weight > 4) {
2542
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   415
					grfmsg(GMS_NOTICE, "RailVehicleChangeInfo: Nonsensical weight of %d tons, ignoring.", weight << 8);
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   416
				} else {
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   417
					SB(rvi[i].weight, 8, 8, weight);
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   418
				}
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   419
			}
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   420
		} break;
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   421
		case 0x28: { /* Cargo classes allowed */
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   422
			FOR_EACH_OBJECT {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   423
				cargo_allowed[engine + i] = grf_load_word(&buf);
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   424
			}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   425
		} break;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   426
		case 0x29: { /* Cargo classes disallowed */
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   427
			FOR_EACH_OBJECT {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   428
				cargo_disallowed[engine + i] = grf_load_word(&buf);
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   429
			}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   430
		} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
		/* TODO */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
		/* Fall-through for unimplemented one byte long properties. */
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   433
		case 0x1A:	/* Sort order */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   434
		case 0x1C:	/* Refit cost */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   435
		case 0x1F:	/* Tractive effort */
1871
1e74cb21d312 (svn r2377) - Fix: [newgrf] Ignore action 0 prop 0x20 (air drag)
orudge
parents: 1862
diff changeset
   436
		case 0x20:	/* Air drag */
1872
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   437
		case 0x25:	/* User-defined bit mask to set when checking veh. var. 42 */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   438
		case 0x26:	/* Retire vehicle early */
2935
ebbf3553f15c (svn r3491) - NewGRF Fix: Handle loading of rail vehicle flags (unimplemented)
peter1138
parents: 2930
diff changeset
   439
		case 0x27:	/* Miscellaneous flags */
1872
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   440
			{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
			/* TODO */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   442
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
				grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   445
			ret = true;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   446
		}	break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
		default:
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   448
			ret = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   454
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
   455
{
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   456
	RoadVehicleInfo *rvi = &_road_vehicle_info[engine];
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   457
	byte *buf = *bufp;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   458
	int i;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   459
	bool ret = false;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   460
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   461
	switch (prop) {
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   462
		case 0x08: { /* Speed */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   463
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   464
				uint8 speed = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   465
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   466
				rvi[i].max_speed = speed; // ?? units
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   467
			}
1968
6e2e29505de0 (svn r2474) - Fix: [newgrf] Some road vehicle action 0 properties were loaded as the wrong type (int8,int16,int32) causing undefined results. (like cargo types being wrong)
hackykid
parents: 1922
diff changeset
   468
		} break;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   469
		case 0x09: { /* Running cost factor */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   470
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   471
				uint8 runcost = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   472
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   473
				rvi[i].running_cost = runcost;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   474
			}
1968
6e2e29505de0 (svn r2474) - Fix: [newgrf] Some road vehicle action 0 properties were loaded as the wrong type (int8,int16,int32) causing undefined results. (like cargo types being wrong)
hackykid
parents: 1922
diff changeset
   475
		} break;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   476
		case 0x0A: { /* Running cost base */
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   477
			/* TODO: I have no idea. --pasky */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   478
			FOR_EACH_OBJECT {
1968
6e2e29505de0 (svn r2474) - Fix: [newgrf] Some road vehicle action 0 properties were loaded as the wrong type (int8,int16,int32) causing undefined results. (like cargo types being wrong)
hackykid
parents: 1922
diff changeset
   479
				grf_load_dword(&buf);
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   480
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   481
			ret = true;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   482
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   483
		case 0x0E: { /* Sprite ID */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   484
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   485
				uint8 spriteid = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   486
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   487
				if (spriteid == 0xFF)
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   488
					spriteid = 0xFD; // cars have different custom id in the GRF file
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   489
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
   490
				if (spriteid < 0xFD)
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
   491
					spriteid >>= 1;
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
   492
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   493
				rvi[i].image_index = spriteid;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   494
			}
1968
6e2e29505de0 (svn r2474) - Fix: [newgrf] Some road vehicle action 0 properties were loaded as the wrong type (int8,int16,int32) causing undefined results. (like cargo types being wrong)
hackykid
parents: 1922
diff changeset
   495
		} break;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   496
		case 0x0F: { /* Cargo capacity */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   497
			FOR_EACH_OBJECT {
1968
6e2e29505de0 (svn r2474) - Fix: [newgrf] Some road vehicle action 0 properties were loaded as the wrong type (int8,int16,int32) causing undefined results. (like cargo types being wrong)
hackykid
parents: 1922
diff changeset
   498
				uint16 capacity = grf_load_byte(&buf);
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   499
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   500
				rvi[i].capacity = capacity;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   501
			}
1968
6e2e29505de0 (svn r2474) - Fix: [newgrf] Some road vehicle action 0 properties were loaded as the wrong type (int8,int16,int32) causing undefined results. (like cargo types being wrong)
hackykid
parents: 1922
diff changeset
   502
		} break;
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   503
		case 0x10: { /* Cargo type */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   504
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   505
				uint8 cargo = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   506
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
   507
				if (cargo < NUM_CARGO) {
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   508
					rvi[i].cargo_type = cargo;
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   509
				} else {
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   510
					grfmsg(GMS_NOTICE, "RoadVehicleChangeInfo: Invalid cargo type %d, ignoring.", cargo);
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   511
				}
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   512
			}
1968
6e2e29505de0 (svn r2474) - Fix: [newgrf] Some road vehicle action 0 properties were loaded as the wrong type (int8,int16,int32) causing undefined results. (like cargo types being wrong)
hackykid
parents: 1922
diff changeset
   513
		} break;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   514
		case 0x11: { /* Cost factor */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   515
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   516
				uint8 cost_factor = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   517
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   518
				rvi[i].base_cost = cost_factor; // ?? is it base_cost?
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   519
			}
1968
6e2e29505de0 (svn r2474) - Fix: [newgrf] Some road vehicle action 0 properties were loaded as the wrong type (int8,int16,int32) causing undefined results. (like cargo types being wrong)
hackykid
parents: 1922
diff changeset
   520
		} break;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   521
		case 0x12: { /* SFX */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   522
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   523
				uint8 sfx = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   524
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   525
				rvi[i].sfx = sfx;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   526
			}
1968
6e2e29505de0 (svn r2474) - Fix: [newgrf] Some road vehicle action 0 properties were loaded as the wrong type (int8,int16,int32) causing undefined results. (like cargo types being wrong)
hackykid
parents: 1922
diff changeset
   527
		} break;
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   528
		case 0x13:      /* Power in 10hp */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   529
		case 0x14:      /* Weight in 1/4 tons */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   530
		case 0x15:      /* Speed in mph*0.8 */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   531
			/* TODO: Support for road vehicles realistic power
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   532
			 * computations (called rvpower in TTDPatch) is just
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   533
			 * missing in OTTD yet. --pasky */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   534
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   535
				grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   536
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   537
			ret = true;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   538
			break;
1968
6e2e29505de0 (svn r2474) - Fix: [newgrf] Some road vehicle action 0 properties were loaded as the wrong type (int8,int16,int32) causing undefined results. (like cargo types being wrong)
hackykid
parents: 1922
diff changeset
   539
		case 0x16: { /* Cargos available for refitting */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   540
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   541
				uint32 refit_mask = grf_load_dword(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   542
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   543
				_engine_info[ROAD_ENGINES_INDEX + engine + i].refit_mask = refit_mask;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   544
			}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   545
		} break;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   546
		case 0x1D: { /* Cargo classes allowed */
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   547
			FOR_EACH_OBJECT {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   548
				cargo_allowed[ROAD_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   549
			}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   550
		} break;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   551
		case 0x1E: { /* Cargo classes disallowed */
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   552
			FOR_EACH_OBJECT {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   553
				cargo_disallowed[ROAD_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   554
			}
1968
6e2e29505de0 (svn r2474) - Fix: [newgrf] Some road vehicle action 0 properties were loaded as the wrong type (int8,int16,int32) causing undefined results. (like cargo types being wrong)
hackykid
parents: 1922
diff changeset
   555
		} break;
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   556
		case 0x17:      /* Callback */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   557
		case 0x18:      /* Tractive effort */
1872
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   558
		case 0x19:      /* Air drag */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   559
		case 0x1A:      /* Refit cost */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   560
		case 0x1B:      /* Retire vehicle early */
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   561
		case 0x1C:      /* Miscellaneous flags */
1872
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   562
			{
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   563
			/* TODO */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   564
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   565
				grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   566
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   567
			ret = true;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   568
			break;
1873
c8637fc2977b (svn r2379) - Fix: [newgrf] Note to self, check thoroughly before committing!
orudge
parents: 1872
diff changeset
   569
		}
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   570
		default:
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   571
			ret = true;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   572
	}
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
	*bufp = buf;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   575
	return ret;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   576
}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   577
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   578
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
   579
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
	ShipVehicleInfo *svi = &_ship_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
	byte *buf = *bufp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
	int i;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   583
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
	//printf("e %x prop %x?\n", engine, prop);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
	switch (prop) {
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   587
		case 0x08: {	/* Sprite ID */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   588
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   591
				if (spriteid == 0xFF)
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   592
					spriteid = 0xFD; // ships have different custom id in the GRF file
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
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
   594
				if (spriteid < 0xFD)
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
   595
					spriteid >>= 1;
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
   596
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
				svi[i].image_index = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   599
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   600
		case 0x09: {	/* Refittable */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   601
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
				uint8 refittable = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
				svi[i].refittable = refittable;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   606
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   607
		case 0x0A: {	/* Cost factor */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   608
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
				uint8 cost_factor = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
				svi[i].base_cost = cost_factor; // ?? is it base_cost?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   613
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   614
		case 0x0B: {	/* Speed */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   615
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
				uint8 speed = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
				svi[i].max_speed = speed; // ?? units
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   620
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   621
		case 0x0C: { /* Cargo type */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   622
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
				uint8 cargo = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
				// XXX: Need to consult this with patchman yet.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
#if 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
				// Documentation claims this is already the
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
				// per-landscape cargo type id, but newships.grf
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
				// assume otherwise.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
				cargo = local_cargo_id_ctype[cargo];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
#endif
2846
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   632
				if (cargo < NUM_CARGO) {
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   633
					svi[i].cargo_type = cargo;
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   634
				} else {
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   635
					grfmsg(GMS_NOTICE, "ShipVehicleChangeInfo: Invalid cargo type %d, ignoring.", cargo);
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   636
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   638
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   639
		case 0x0D: {	/* Cargo capacity */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   640
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
				uint16 capacity = grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
				svi[i].capacity = capacity;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   645
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   646
		case 0x0F: {	/* Running cost factor */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   647
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
				uint8 runcost = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
				svi[i].running_cost = runcost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   652
		} break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   653
		case 0x10: {	/* SFX */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   654
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
				uint8 sfx = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
				svi[i].sfx = sfx;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   659
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   660
		case 0x11: {	/* Cargos available for refitting */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   661
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
				uint32 refit_mask = grf_load_dword(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   664
				_engine_info[SHIP_ENGINES_INDEX + engine + i].refit_mask = refit_mask;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   666
		}	break;
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   667
		case 0x18: { /* Cargo classes allowed */
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   668
			FOR_EACH_OBJECT {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   669
				cargo_allowed[SHIP_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   670
			}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   671
		} break;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   672
		case 0x19: { /* Cargo classes disallowed */
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   673
			FOR_EACH_OBJECT {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   674
				cargo_disallowed[SHIP_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   675
			}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   676
		} break;
1872
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   677
		case 0x12: /* Callback */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   678
		case 0x13: /* Refit cost */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   679
		case 0x14: /* Ocean speed fraction */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   680
		case 0x15: /* Canal speed fraction */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   681
		case 0x16: /* Retire vehicle early */
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   682
		case 0x17: /* Miscellaneous flags */
1872
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   683
		{
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   684
			/* TODO */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   685
			FOR_EACH_OBJECT {
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   686
				grf_load_byte(&buf);
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   687
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   688
			ret = true;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   689
		}	break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
		default:
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   691
			ret = true;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   696
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
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
   698
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
   699
{
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
   700
	AircraftVehicleInfo *avi = &_aircraft_vehicle_info[engine];
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   701
	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
   702
	int i;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   703
	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
   704
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
   705
	//printf("e %x prop %x?\n", engine, prop);
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   706
	switch (prop) {
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   707
		case 0x08: {	/* Sprite ID */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   708
			FOR_EACH_OBJECT {
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   709
				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
   710
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
   711
				if (spriteid == 0xFF)
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
   712
					spriteid = 0xFD; // ships have different custom id in the GRF file
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
   713
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
   714
				if (spriteid < 0xFD)
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
   715
					spriteid >>= 1;
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
   716
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
   717
				avi[i].image_index = spriteid;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   718
			}
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
   719
		}	break;
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
   720
		case 0x09: {	/* Helicopter */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   721
			FOR_EACH_OBJECT {
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   722
				uint8 heli = grf_load_byte(&buf);
1180
04f306272df7 (svn r1682) - Fix: [newgrf] Helicopters from grf sets are now correctly recognized
dominik
parents: 922
diff changeset
   723
				avi[i].subtype &= ~0x01; // remove old property
1183
a9273fb4d48e (svn r1685) - Fix: [newgrf] airplanes from grf sets are not treated as helicopters, as introduced in r1682
dominik
parents: 1180
diff changeset
   724
				avi[i].subtype |= (heli == 0) ? 0 : 1;
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
   725
			}
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
   726
		}	break;
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
   727
		case 0x0A: {	/* Large */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   728
			FOR_EACH_OBJECT {
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   729
				uint8 large = grf_load_byte(&buf);
1180
04f306272df7 (svn r1682) - Fix: [newgrf] Helicopters from grf sets are now correctly recognized
dominik
parents: 922
diff changeset
   730
				avi[i].subtype &= ~0x02; // remove old property
1183
a9273fb4d48e (svn r1685) - Fix: [newgrf] airplanes from grf sets are not treated as helicopters, as introduced in r1682
dominik
parents: 1180
diff changeset
   731
				avi[i].subtype |= (large == 1) ? 2 : 0;
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
   732
			}
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
   733
		}	break;
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
   734
		case 0x0B: {	/* Cost factor */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   735
			FOR_EACH_OBJECT {
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   736
				uint8 cost_factor = 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
   737
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
   738
				avi[i].base_cost = cost_factor; // ?? is it base_cost?
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
   739
			}
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
   740
		}	break;
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
   741
		case 0x0C: {	/* Speed */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   742
			FOR_EACH_OBJECT {
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   743
				uint8 speed = 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
   744
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
   745
				avi[i].max_speed = speed; // ?? units
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
   746
			}
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
   747
		}	break;
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
   748
		case 0x0D: {	/* Acceleration */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   749
			FOR_EACH_OBJECT {
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   750
				uint8 accel = 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
   751
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
   752
				avi[i].acceleration = accel;
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
   753
			}
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
   754
		} break;
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
   755
		case 0x0E: {	/* Running cost factor */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   756
			FOR_EACH_OBJECT {
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   757
				uint8 runcost = 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
   758
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
   759
				avi[i].running_cost = runcost;
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
   760
			}
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
   761
		} break;
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
   762
		case 0x0F: {	/* Passenger capacity */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   763
			FOR_EACH_OBJECT {
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   764
				uint16 capacity = grf_load_word(&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
   765
922
fc040662bd43 (svn r1410) Replaced all occurences of 'passanger' by 'passenger' in the code
celestar
parents: 542
diff changeset
   766
				avi[i].passenger_capacity = capacity;
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
   767
			}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   768
		}	break;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   769
		case 0x11: {	/* Mail capacity */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   770
			FOR_EACH_OBJECT {
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   771
				uint8 capacity = 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
   772
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
   773
				avi[i].mail_capacity = capacity;
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
   774
			}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   775
		}	break;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   776
		case 0x12: {	/* SFX */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   777
			FOR_EACH_OBJECT {
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   778
				uint8 sfx = 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
   779
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
   780
				avi[i].sfx = sfx;
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
   781
			}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   782
		}	break;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   783
		case 0x13: {	/* Cargos available for refitting */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   784
			FOR_EACH_OBJECT {
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   785
				uint32 refit_mask = grf_load_dword(&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
   786
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   787
				_engine_info[AIRCRAFT_ENGINES_INDEX + engine + i].refit_mask = refit_mask;
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
   788
			}
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
   789
		}	break;
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   790
		case 0x18: { /* Cargo classes allowed */
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   791
			FOR_EACH_OBJECT {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   792
				cargo_allowed[AIRCRAFT_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   793
			}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   794
		} break;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   795
		case 0x19: { /* Cargo classes disallowed */
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   796
			FOR_EACH_OBJECT {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   797
				cargo_disallowed[AIRCRAFT_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   798
			}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   799
		} break;
1872
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   800
		case 0x14: /* Callback */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   801
		case 0x15: /* Refit cost */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   802
		case 0x16: /* Retire vehicle early */
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   803
		case 0x17: /* Miscellaneous flags */
1872
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   804
		{
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   805
			/* TODO */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   806
			FOR_EACH_OBJECT {
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   807
				grf_load_byte(&buf);
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   808
			}
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   809
			ret = true;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   810
		}	break;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   811
		default:
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   812
			ret = true;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   813
	}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   814
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   815
	*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
   816
	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
   817
}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   818
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   819
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
   820
{
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   821
	byte *buf = *bufp;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   822
	int i;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   823
	int ret = 0;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   824
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   825
	/* This is one single huge TODO. It doesn't handle anything more than
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   826
	 * just waypoints for now. */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   827
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   828
	//printf("sci %d %d [0x%02x]\n", stid, numinfo, prop);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   829
	switch (prop) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   830
		case 0x08:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   831
		{	/* Class ID */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   832
			FOR_EACH_OBJECT {
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   833
				StationSpec *stat = &_cur_grffile->stations[stid + i];
438
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   834
				uint32 classid;
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
   835
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   836
				/* classid, for a change, is always little-endian */
438
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   837
				classid = *(buf++) << 24;
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   838
				classid |= *(buf++) << 16;
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   839
				classid |= *(buf++) << 8;
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   840
				classid |= *(buf++);
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   841
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   842
				stat->sclass = AllocateStationClass(classid);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   843
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   844
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   845
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   846
		case 0x09:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   847
		{	/* Define sprite layout */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   848
			FOR_EACH_OBJECT {
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   849
				StationSpec *stat = &_cur_grffile->stations[stid + i];
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   850
				int t;
398
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
   851
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   852
				stat->tiles = grf_load_extended(&buf);
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   853
				stat->renderdata = calloc(stat->tiles, sizeof(*stat->renderdata));
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
   854
				for (t = 0; t < stat->tiles; t++) {
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
   855
					DrawTileSprites *dts = &stat->renderdata[t];
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   856
					int seq_count = 0;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   857
					PalSpriteID ground_sprite;
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   858
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   859
					ground_sprite = grf_load_dword(&buf);
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   860
					if (ground_sprite == 0) {
536
aef4753985d3 (svn r907) Sprinkle holy ANSI water:
tron
parents: 500
diff changeset
   861
						static const DrawTileSeqStruct empty = {0x80, 0, 0, 0, 0, 0, 0};
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   862
						dts->seq = &empty;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   863
						continue;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   864
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   865
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   866
					if (HASBIT(ground_sprite, 31)) {
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   867
						// Bit 31 indicates that we should use a custom sprite.
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   868
						dts->ground_sprite = GB(ground_sprite, 0, 15) - 0x42D;
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   869
						dts->ground_sprite += _cur_grffile->first_spriteset;
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   870
					} else {
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   871
						dts->ground_sprite = ground_sprite;
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   872
					}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   873
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   874
					dts->seq = NULL;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   875
					while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   876
						DrawTileSeqStruct *dtss;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   877
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   878
						// no relative bounding box support
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   879
						dts->seq = realloc((void*)dts->seq, ++seq_count * sizeof(DrawTileSeqStruct));
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   880
						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
   881
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   882
						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
   883
						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
   884
						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
   885
						dtss->delta_z = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   886
						dtss->width = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   887
						dtss->height = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   888
						dtss->unk = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   889
						dtss->image = grf_load_dword(&buf) - 0x42d;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   890
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   891
				}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   892
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   893
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   894
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   895
		case 0x0a:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   896
		{	/* Copy sprite layout */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   897
			FOR_EACH_OBJECT {
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   898
				StationSpec *stat = &_cur_grffile->stations[stid + i];
398
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
   899
				byte srcid = grf_load_byte(&buf);
2624
47d7768c6dca (svn r3166) Constify read-only accesses of custom stations
peter1138
parents: 2614
diff changeset
   900
				const StationSpec *srcstat = &_cur_grffile->stations[srcid];
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   901
				int t;
398
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
   902
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
   903
				stat->tiles = srcstat->tiles;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   904
				stat->renderdata = calloc(stat->tiles, sizeof(*stat->renderdata));
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
   905
				for (t = 0; t < stat->tiles; t++) {
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
   906
					DrawTileSprites *dts = &stat->renderdata[t];
2624
47d7768c6dca (svn r3166) Constify read-only accesses of custom stations
peter1138
parents: 2614
diff changeset
   907
					const DrawTileSprites *sdts = &srcstat->renderdata[t];
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   908
					DrawTileSeqStruct const *sdtss = sdts->seq;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   909
					int seq_count = 0;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   910
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   911
					dts->ground_sprite = sdts->ground_sprite;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   912
					if (!dts->ground_sprite) {
536
aef4753985d3 (svn r907) Sprinkle holy ANSI water:
tron
parents: 500
diff changeset
   913
						static const DrawTileSeqStruct empty = {0x80, 0, 0, 0, 0, 0, 0};
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   914
						dts->seq = &empty;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   915
						continue;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   916
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   917
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   918
					dts->seq = NULL;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   919
					while (1) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   920
						DrawTileSeqStruct *dtss;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   921
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   922
						// no relative bounding box support
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   923
						dts->seq = realloc((void*)dts->seq, ++seq_count * sizeof(DrawTileSeqStruct));
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   924
						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
   925
						*dtss = *sdtss;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   926
						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
   927
						sdtss++;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   928
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   929
				}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   930
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   931
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   932
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   933
		case 0x0b:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   934
		{	/* Callback */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   935
			/* TODO */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   936
			FOR_EACH_OBJECT {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   937
				grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   938
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   939
			ret = 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   940
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   941
		}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   942
		case 0x0C:
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   943
		{	/* Platforms number */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   944
			FOR_EACH_OBJECT {
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   945
				StationSpec *stat = &_cur_grffile->stations[stid + i];
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   946
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   947
				stat->allowed_platforms = ~grf_load_byte(&buf);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   948
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   949
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   950
		}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   951
		case 0x0D:
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   952
		{	/* Platforms length */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   953
			FOR_EACH_OBJECT {
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   954
				StationSpec *stat = &_cur_grffile->stations[stid + i];
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   955
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   956
				stat->allowed_lengths = ~grf_load_byte(&buf);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   957
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   958
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   959
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   960
		case 0x0e:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   961
		{	/* Define custom layout */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   962
			FOR_EACH_OBJECT {
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   963
				StationSpec *stat = &_cur_grffile->stations[stid + i];
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   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
					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
   967
					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
   968
					StationLayout layout;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   969
					int l, p;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   970
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   971
					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
   972
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   973
					//debug("l %d > %d ?", length, stat->lengths);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   974
					if (length > stat->lengths) {
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   975
						stat->platforms = realloc(stat->platforms, length);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   976
						memset(stat->platforms + stat->lengths, 0, length - stat->lengths);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   977
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   978
						stat->layouts = realloc(stat->layouts, length * sizeof(*stat->layouts));
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   979
						memset(stat->layouts + stat->lengths, 0,
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   980
						       (length - stat->lengths) * sizeof(*stat->layouts));
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   981
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   982
						stat->lengths = length;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   983
					}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   984
					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
   985
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   986
					//debug("p %d > %d ?", number, stat->platforms[l]);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   987
					if (number > stat->platforms[l]) {
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   988
						stat->layouts[l] = realloc(stat->layouts[l],
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   989
						                               number * sizeof(**stat->layouts));
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   990
						// We expect NULL being 0 here, but C99 guarantees that.
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   991
						memset(stat->layouts[l] + stat->platforms[l], 0,
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   992
						       (number - stat->platforms[l]) * sizeof(**stat->layouts));
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   993
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   994
						stat->platforms[l] = number;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   995
					}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   996
542
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
   997
					p = 0;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   998
					layout = malloc(length * number);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   999
					for (l = 0; l < length; l++)
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1000
						for (p = 0; p < number; p++)
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1001
							layout[l * number + p] = grf_load_byte(&buf);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1002
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1003
					l--;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1004
					p--;
542
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
  1005
					assert(p >= 0);
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1006
					free(stat->layouts[l][p]);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1007
					stat->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
  1008
				}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1009
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1010
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1011
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1012
		case 0x0f:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1013
		{	/* Copy custom layout */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1014
			/* TODO */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1015
			FOR_EACH_OBJECT {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1016
				grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1017
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1018
			ret = 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1019
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1020
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1021
		case 0x10:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1022
		{	/* Little/lots cargo threshold */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1023
			/* TODO */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1024
			FOR_EACH_OBJECT {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1025
				grf_load_word(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1026
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1027
			ret = 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1028
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1029
		}
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1030
		case 0x11:
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1031
		{	/* Pylon placement */
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1032
			/* TODO; makes sense only for electrified tracks */
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1033
			FOR_EACH_OBJECT {
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1034
				grf_load_word(&buf);
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1035
			}
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1036
			ret = 1;
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1037
			break;
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1038
		}
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1039
		case 0x12:
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1040
		{	/* Cargo types for random triggers */
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1041
			/* TODO */
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1042
			FOR_EACH_OBJECT {
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1043
				grf_load_dword(&buf);
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1044
			}
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1045
			ret = 1;
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1046
			break;
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1047
		}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1048
		default:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1049
			ret = 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1050
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1051
	}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1052
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1053
	*bufp = buf;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1054
	return ret;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1055
}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1056
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
  1057
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
  1058
{
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
  1059
	byte *buf = *bufp;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1060
	int i;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1061
	int ret = 0;
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
  1062
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
  1063
	switch (prop) {
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1064
		case 0x08: /* Year of availability */
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
  1065
			FOR_EACH_OBJECT {
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1066
				_bridge[brid + i].avail_year = 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
  1067
			}
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
  1068
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1069
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
  1070
		case 0x09: /* Minimum length */
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
  1071
			FOR_EACH_OBJECT {
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1072
				_bridge[brid + i].min_length = 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
  1073
			}
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
  1074
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1075
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
  1076
		case 0x0A: /* Maximum length */
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
  1077
			FOR_EACH_OBJECT {
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1078
				_bridge[brid + i].max_length = 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
  1079
			}
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
  1080
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1081
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
  1082
		case 0x0B: /* Cost factor */
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
  1083
			FOR_EACH_OBJECT {
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1084
				_bridge[brid + i].price = 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
  1085
			}
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
  1086
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1087
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
  1088
		case 0x0C: /* Maximum speed */
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
  1089
			FOR_EACH_OBJECT {
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1090
				_bridge[brid + i].speed = grf_load_word(&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
  1091
			}
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
  1092
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1093
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
  1094
		case 0x0D: /* Bridge sprite tables */
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1095
			FOR_EACH_OBJECT {
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1096
				Bridge *bridge = &_bridge[brid + i];
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1097
				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
  1098
				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
  1099
				byte table, sprite;
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
  1100
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1101
				if (bridge->sprite_table == NULL) {
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1102
					/* Allocate memory for sprite table pointers and set to NULL */
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1103
					bridge->sprite_table = malloc(7 * sizeof(*bridge->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
  1104
					for (table = 0; table < 7; 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
  1105
						bridge->sprite_table[table] = NULL;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1106
				}
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1107
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1108
				for (table = tableid; table < tableid + numtables; table++) {
2480
c5fa654776a2 (svn r3006) -Fix, NewGRF: Don't assert on user input, skip data instead.
peter1138
parents: 2479
diff changeset
  1109
					if (table < 7) {
c5fa654776a2 (svn r3006) -Fix, NewGRF: Don't assert on user input, skip data instead.
peter1138
parents: 2479
diff changeset
  1110
						if (bridge->sprite_table[table] == NULL) {
c5fa654776a2 (svn r3006) -Fix, NewGRF: Don't assert on user input, skip data instead.
peter1138
parents: 2479
diff changeset
  1111
							bridge->sprite_table[table] = malloc(32 * sizeof(**bridge->sprite_table));
c5fa654776a2 (svn r3006) -Fix, NewGRF: Don't assert on user input, skip data instead.
peter1138
parents: 2479
diff changeset
  1112
						}
c5fa654776a2 (svn r3006) -Fix, NewGRF: Don't assert on user input, skip data instead.
peter1138
parents: 2479
diff changeset
  1113
c5fa654776a2 (svn r3006) -Fix, NewGRF: Don't assert on user input, skip data instead.
peter1138
parents: 2479
diff changeset
  1114
						for (sprite = 0; sprite < 32; sprite++)
c5fa654776a2 (svn r3006) -Fix, NewGRF: Don't assert on user input, skip data instead.
peter1138
parents: 2479
diff changeset
  1115
							bridge->sprite_table[table][sprite] = grf_load_dword(&buf);
c5fa654776a2 (svn r3006) -Fix, NewGRF: Don't assert on user input, skip data instead.
peter1138
parents: 2479
diff changeset
  1116
					} else {
c5fa654776a2 (svn r3006) -Fix, NewGRF: Don't assert on user input, skip data instead.
peter1138
parents: 2479
diff changeset
  1117
						grfmsg(GMS_WARN, "BridgeChangeInfo: Table %d >= 7, skipping.", table);
c5fa654776a2 (svn r3006) -Fix, NewGRF: Don't assert on user input, skip data instead.
peter1138
parents: 2479
diff changeset
  1118
						// Skip past invalid data.
c5fa654776a2 (svn r3006) -Fix, NewGRF: Don't assert on user input, skip data instead.
peter1138
parents: 2479
diff changeset
  1119
						for (sprite = 0; sprite < 32; sprite++)
c5fa654776a2 (svn r3006) -Fix, NewGRF: Don't assert on user input, skip data instead.
peter1138
parents: 2479
diff changeset
  1120
							grf_load_dword(&buf);
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1121
					}
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1122
				}
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1123
			}
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1124
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1125
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1126
		case 0x0E: /* Flags; bit 0 - disable far pillars */
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1127
			FOR_EACH_OBJECT {
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1128
				_bridge[brid + i].flags = 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
  1129
			}
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1130
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1131
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1132
		default:
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
			ret = 1;
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
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
  1136
	*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
  1137
	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
  1138
}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1139
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1140
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
  1141
{
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1142
	byte *buf = *bufp;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1143
	int i;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1144
	bool ret = false;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1145
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1146
	switch (prop) {
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1147
		case 0x08: { /* Cost base factor */
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1148
			FOR_EACH_OBJECT {
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1149
				byte factor = grf_load_byte(&buf);
2508
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1150
				uint price = gvid + i;
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1151
2508
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1152
				if (price < NUM_PRICES) {
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1153
					SetPriceBaseMultiplier(price, factor);
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1154
				} else {
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1155
					grfmsg(GMS_WARN, "GlobalVarChangeInfo: Price %d out of range, ignoring.", price);
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1156
				}
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1157
			}
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1158
		} break;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1159
		default:
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1160
			ret = true;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1161
	}
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1162
	*bufp = buf;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1163
	return ret;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1164
}
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1165
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1166
/* Action 0x00 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
static void VehicleChangeInfo(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1169
	byte *bufend = buf + len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
	/* <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
  1173
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
	 * 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
  1175
	 *                 4 for defining new train station sets
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
	 * 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
  1177
	 * B num-info      how many vehicles/stations to change
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
	 * B id            ID of first vehicle/station to change, if num-info is
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
	 *                 greater than one, this one and the following
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
	 *                 vehicles/stations will be changed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
	 * 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
  1182
	 * 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
  1183
	/* TODO: Bridges, town houses. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1184
2438
eaef2b29fa3d (svn r2964) Fix: newgrf: Include missing grf feature canal.
peter1138
parents: 2421
diff changeset
  1185
	static const VCI_Handler handler[] = {
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
  1186
		/* GSF_TRAIN */    RailVehicleChangeInfo,
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
  1187
		/* GSF_ROAD */     RoadVehicleChangeInfo,
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
  1188
		/* GSF_SHIP */     ShipVehicleChangeInfo,
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
  1189
		/* GSF_AIRCRAFT */ AircraftVehicleChangeInfo,
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1190
		/* GSF_STATION */  StationChangeInfo,
2438
eaef2b29fa3d (svn r2964) Fix: newgrf: Include missing grf feature canal.
peter1138
parents: 2421
diff changeset
  1191
		/* GSF_CANAL */    NULL,
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1192
		/* GSF_BRIDGE */   BridgeChangeInfo,
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1193
		/* GSF_TOWNHOUSE */NULL,
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1194
		/* GSF_GLOBALVAR */GlobalVarChangeInfo,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
	};
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1196
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1197
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1198
	uint8 numprops;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1199
	uint8 numinfo;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1200
	byte engine;
542
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
  1201
	EngineInfo *ei = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
396
f7dc2d2144b6 (svn r588) -newgrf: Silent ignore those stupid one-byte zero special sprites (dbsetw.grf is crawling with them) (pasky).
darkvater
parents: 391
diff changeset
  1203
	if (len == 1) {
f7dc2d2144b6 (svn r588) -newgrf: Silent ignore those stupid one-byte zero special sprites (dbsetw.grf is crawling with them) (pasky).
darkvater
parents: 391
diff changeset
  1204
		DEBUG(grf, 8) ("Silently ignoring one-byte special sprite 0x00.");
f7dc2d2144b6 (svn r588) -newgrf: Silent ignore those stupid one-byte zero special sprites (dbsetw.grf is crawling with them) (pasky).
darkvater
parents: 391
diff changeset
  1205
		return;
f7dc2d2144b6 (svn r588) -newgrf: Silent ignore those stupid one-byte zero special sprites (dbsetw.grf is crawling with them) (pasky).
darkvater
parents: 391
diff changeset
  1206
	}
f7dc2d2144b6 (svn r588) -newgrf: Silent ignore those stupid one-byte zero special sprites (dbsetw.grf is crawling with them) (pasky).
darkvater
parents: 391
diff changeset
  1207
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1208
	check_length(len, 6, "VehicleChangeInfo");
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1209
	feature = buf[1];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1210
	numprops = buf[2];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1211
	numinfo = buf[3];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1212
	engine = buf[4];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  1213
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
  1214
	DEBUG(grf, 6) ("VehicleChangeInfo: Feature %d, %d properties, to apply to %d+%d",
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
  1215
	               feature, numprops, engine, numinfo);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
  1216
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
  1217
	if (feature >= lengthof(handler) || handler[feature] == NULL) {
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1218
		grfmsg(GMS_WARN, "VehicleChangeInfo: Unsupported feature %d, skipping.", feature);
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1219
		return;
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1220
	}
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1221
2439
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1222
	if (feature <= GSF_AIRCRAFT) {
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1223
		if (engine + numinfo > _vehcounts[feature]) {
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1224
			grfmsg(GMS_ERROR, "VehicleChangeInfo: Last engine ID %d out of bounds (max %d), skipping.", engine + numinfo, _vehcounts[feature]);
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1225
			return;
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1226
		}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1227
		ei = &_engine_info[engine + _vehshifts[feature]];
2439
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1228
	}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1229
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1230
	buf += 5;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1231
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1232
	while (numprops-- && buf < bufend) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1233
		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
  1234
		bool ignoring = false;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1235
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1236
		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
  1237
			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
  1238
			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
  1239
			case GSF_SHIP:
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1240
			case GSF_AIRCRAFT:
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1241
				/* Common properties for vehicles */
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1242
				switch (prop) {
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1243
					case 0x00: { /* Introduction date */
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1244
						FOR_EACH_OBJECT {
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1245
							uint16 date = grf_load_word(&buf);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1246
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1247
							ei[i].base_intro = date;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1248
						}
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1249
					}	break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1250
					case 0x02: { /* Decay speed */
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1251
						FOR_EACH_OBJECT {
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1252
							uint8 decay = grf_load_byte(&buf);
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1253
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1254
							ei[i].unk2 &= 0x80;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1255
							ei[i].unk2 |= decay & 0x7f;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1256
						}
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1257
					}	break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1258
					case 0x03: { /* Vehicle life */
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1259
						FOR_EACH_OBJECT {
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1260
							uint8 life = grf_load_byte(&buf);
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1261
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1262
							ei[i].lifelength = life;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1263
						}
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1264
					}	break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1265
					case 0x04: { /* Model life */
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1266
						FOR_EACH_OBJECT {
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1267
							uint8 life = grf_load_byte(&buf);
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1268
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1269
							ei[i].base_life = life;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1270
						}
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1271
					}	break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1272
					case 0x06: { /* Climates available */
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1273
						FOR_EACH_OBJECT {
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1274
							uint8 climates = grf_load_byte(&buf);
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1275
2530
b8d5a5284024 (svn r3059) Use bitfields to encode railtype and climates of engines instead of manual shifting/anding
tron
parents: 2516
diff changeset
  1276
							ei[i].climates = climates;
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1277
						}
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1278
					}	break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1279
					case 0x07: { /* Loading speed */
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1280
						/* TODO */
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1281
						/* Hyronymus explained me what does
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1282
						 * this mean and insists on having a
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1283
						 * credit ;-). --pasky */
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1284
						/* TODO: This needs to be supported by
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1285
						 * LoadUnloadVehicle() first. */
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1286
						FOR_EACH_OBJECT {
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1287
							grf_load_byte(&buf);
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1288
						}
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1289
						ignoring = true;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1290
						break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1291
					}
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1292
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1293
					default:
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1294
						if (handler[feature](engine, numinfo, prop, &buf, bufend - buf))
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1295
							ignoring = true;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1296
						break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1297
				}
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1298
				break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1299
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1300
			default:
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1301
				if (handler[feature](engine, numinfo, prop, &buf, bufend - buf))
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1302
					ignoring = true;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1303
				break;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1304
		}
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1305
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1306
		if (ignoring)
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1307
			grfmsg(GMS_NOTICE, "VehicleChangeInfo: Ignoring property %x (not implemented).", prop);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1310
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1311
#undef FOR_EACH_OBJECT
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1312
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1313
/**
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1314
 * Creates a spritegroup representing a callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1315
 * @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
  1316
 * @return A spritegroup representing that callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1317
 */
2752
b5fe5a7e6282 (svn r3297) Staticise
tron
parents: 2645
diff changeset
  1318
static SpriteGroup* NewCallBackResultSpriteGroup(uint16 value)
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1319
{
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1320
	SpriteGroup *group = calloc(1, sizeof(*group));
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1321
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1322
	group->type = SGT_CALLBACK;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1323
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1324
	// Old style callback results have the highest byte 0xFF so signify it is a callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1325
	// New style ones only have the highest bit set (allows 15-bit results, instead of just 8)
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1326
	if ((value >> 8) == 0xFF)
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1327
		value &= 0xFF;
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1328
	else
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1329
		value &= ~0x8000;
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1330
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1331
	group->g.callback.result = value;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1332
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1333
	return group;
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1334
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1335
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
  1336
/**
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
  1337
 * Creates a spritegroup representing a sprite number result.
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1338
 * @param value The sprite number.
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1339
 * @param sprites The number of sprites per set.
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1340
 * @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
  1341
 */
2752
b5fe5a7e6282 (svn r3297) Staticise
tron
parents: 2645
diff changeset
  1342
static SpriteGroup* NewResultSpriteGroup(uint16 value, byte 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
  1343
{
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
  1344
	SpriteGroup *group = calloc(1, sizeof(*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
  1345
	group->type = SGT_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
  1346
	group->g.result.result = value;
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
  1347
	group->g.result.sprites = sprites;
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
  1348
	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
  1349
}
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
  1350
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1351
/* 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
  1352
static void NewSpriteSet(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1354
	/* <01> <feature> <num-sets> <num-ent>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1356
	 * B feature       feature to define sprites for
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
	 *                 0, 1, 2, 3: veh-type, 4: train stations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1358
	 * B num-sets      number of sprite sets
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1359
	 * 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
  1360
	 *                 For vehicles, this is the number of different
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
	 *                         vehicle directions in each sprite set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
	 *                         Set num-dirs=8, unless your sprites are symmetric.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1363
	 *                         In that case, use num-dirs=4.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1364
	 *                 For stations, must be 12 (hex) for the eighteen
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
	 *                         different sprites that make up a station */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
	/* TODO: No stations support. */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1367
	uint8 feature;
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1368
	uint num_sets;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1369
	uint num_ents;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1370
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1372
	check_length(len, 4, "NewSpriteSet");
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1373
	buf++;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1374
	feature  = grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1375
	num_sets = grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1376
	num_ents = grf_load_extended(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
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
  1378
	_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
  1379
	_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
  1380
	_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
  1381
	_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
  1382
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1383
	DEBUG(grf, 7) (
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1384
		"New sprite set at %d of type %d, "
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1385
		"consisting of %d sets with %d views each (total %d)",
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1386
		_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
  1387
	);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1388
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1389
	for (i = 0; i < num_sets * num_ents; i++) {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1390
		LoadNextSprite(_cur_spriteid++, _file_index);
2849
73c752b82488 (svn r3397) - NewGRF fix: Show nfo sprite number instead of current sprite id for warning messages -- this makes this output more useful...
peter1138
parents: 2846
diff changeset
  1391
		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
  1392
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1394
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1395
/* 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
  1396
static void NewSpriteGroup(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1397
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1398
	byte *bufend = buf + len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
	/* <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
  1401
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1402
	 * B feature       see action 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
	 * B set-id        ID of this particular definition
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
	 * B type/num-entries
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
	 *                 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
  1406
	 *                 list definition, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
	 *                 otherwise it specifies a number of entries, the exact
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
	 *                 meaning depends on the feature
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
	 * V feature-specific-data (huge mess, don't even look it up --pasky) */
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1410
	/* TODO: No 0x80-types (ugh). */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1411
	/* TODO: Also, empty sprites aren't handled for now. Need to investigate
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1412
	 * the "opacity" rules for these, that is which sprite to fall back to
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1413
	 * when. --pasky */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1414
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1415
	uint8 setid;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1416
	/* XXX: For stations, these two are "little cargo" and "lotsa cargo" sets. */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1417
	uint8 numloaded;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1418
	uint8 numloading;
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1419
	SpriteGroup *group;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1420
	RealSpriteGroup *rg;
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1421
	byte *loaded_ptr;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1422
	byte *loading_ptr;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1423
	int i;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  1424
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1425
	check_length(len, 5, "NewSpriteGroup");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1426
	feature = buf[1];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1427
	setid = buf[2];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1428
	numloaded = buf[3];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1429
	numloading = buf[4];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1430
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
  1431
	if (setid >= _cur_grffile->spritegroups_count) {
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1432
		// Allocate memory for new sprite group references.
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1433
		_cur_grffile->spritegroups = realloc(_cur_grffile->spritegroups, (setid + 1) * sizeof(*_cur_grffile->spritegroups));
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1434
		// Initialise new space to NULL
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1435
		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
  1436
			_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
  1437
	}
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
  1438
408
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1439
	if (numloaded == 0x81 || numloaded == 0x82) {
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1440
		DeterministicSpriteGroup *dg;
419
2fbd23a1cedc (svn r616) -newgrf: Fixed crashing when trying to resolve references to unknown or callback result spritegroups in variational spritegroup handler of NewSpriteGroup() (pasky).
darkvater
parents: 418
diff changeset
  1441
		uint16 groupid;
408
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1442
		int i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
408
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1444
		// Ok, this is gonna get a little wild, so hold your breath...
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
408
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1446
		/* This stuff is getting actually evaluated in
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1447
		 * EvalDeterministicSpriteGroup(). */
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1448
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1449
		buf += 4; len -= 4;
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1450
		check_length(len, 6, "NewSpriteGroup 0x81/0x82");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1451
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
  1452
		group = calloc(1, sizeof(*group));
408
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1453
		group->type = SGT_DETERMINISTIC;
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1454
		dg = &group->g.determ;
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1455
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1456
		/* XXX: We don't free() anything, assuming that if there was
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1457
		 * some action here before, it got associated by action 3.
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1458
		 * We should perhaps keep some refcount? --pasky */
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1459
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1460
		dg->var_scope = numloaded == 0x82 ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF;
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1461
		dg->variable = grf_load_byte(&buf);
2445
b475b9d30a26 (svn r2971) - Newgrf: Support loading VarAction2 parameter for variables 0x60-0x7F. This parameter isn't used yet.
peter1138
parents: 2444
diff changeset
  1462
		/* Variables 0x60 - 0x7F include an extra parameter */
b475b9d30a26 (svn r2971) - Newgrf: Support loading VarAction2 parameter for variables 0x60-0x7F. This parameter isn't used yet.
peter1138
parents: 2444
diff changeset
  1463
		if (IS_BYTE_INSIDE(dg->variable, 0x60, 0x80))
b475b9d30a26 (svn r2971) - Newgrf: Support loading VarAction2 parameter for variables 0x60-0x7F. This parameter isn't used yet.
peter1138
parents: 2444
diff changeset
  1464
			dg->parameter = grf_load_byte(&buf);
408
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1465
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1466
		dg->shift_num = grf_load_byte(&buf);
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1467
		dg->and_mask = grf_load_byte(&buf);
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1468
		dg->operation = dg->shift_num >> 6; /* w00t */
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1469
		dg->shift_num &= 0x3F;
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1470
		if (dg->operation != DSG_OP_NONE) {
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1471
			dg->add_val = grf_load_byte(&buf);
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1472
			dg->divmod_val = grf_load_byte(&buf);
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1473
		}
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1474
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1475
		/* (groupid & 0x8000) means this is callback result. */
419
2fbd23a1cedc (svn r616) -newgrf: Fixed crashing when trying to resolve references to unknown or callback result spritegroups in variational spritegroup handler of NewSpriteGroup() (pasky).
darkvater
parents: 418
diff changeset
  1476
408
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1477
		dg->num_ranges = grf_load_byte(&buf);
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1478
		dg->ranges = calloc(dg->num_ranges, sizeof(*dg->ranges));
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1479
		for (i = 0; i < dg->num_ranges; i++) {
419
2fbd23a1cedc (svn r616) -newgrf: Fixed crashing when trying to resolve references to unknown or callback result spritegroups in variational spritegroup handler of NewSpriteGroup() (pasky).
darkvater
parents: 418
diff changeset
  1480
			groupid = grf_load_word(&buf);
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1481
			if (HASBIT(groupid, 15)) {
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1482
				dg->ranges[i].group = NewCallBackResultSpriteGroup(groupid);
2490
a0db300b6da6 (svn r3016) -NewGRF: Implement the start of reference counting for sprite groups. This will allow unloading.
peter1138
parents: 2489
diff changeset
  1483
				dg->ranges[i].group->ref_count++;
2515
480538b48b0f (svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
peter1138
parents: 2508
diff changeset
  1484
			} else if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
480538b48b0f (svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
peter1138
parents: 2508
diff changeset
  1485
				grfmsg(GMS_WARN, "NewSpriteGroup(%02x:0x%x): Groupid %04x does not exist, leaving empty.", setid, numloaded, groupid);
480538b48b0f (svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
peter1138
parents: 2508
diff changeset
  1486
				dg->ranges[i].group = NULL;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1487
			} else {
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1488
				dg->ranges[i].group = _cur_grffile->spritegroups[groupid];
2490
a0db300b6da6 (svn r3016) -NewGRF: Implement the start of reference counting for sprite groups. This will allow unloading.
peter1138
parents: 2489
diff changeset
  1489
				dg->ranges[i].group->ref_count++;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1490
			}
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1491
413
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1492
			dg->ranges[i].low = grf_load_byte(&buf);
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1493
			dg->ranges[i].high = grf_load_byte(&buf);
408
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1494
		}
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1495
419
2fbd23a1cedc (svn r616) -newgrf: Fixed crashing when trying to resolve references to unknown or callback result spritegroups in variational spritegroup handler of NewSpriteGroup() (pasky).
darkvater
parents: 418
diff changeset
  1496
		groupid = grf_load_word(&buf);
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1497
		if (HASBIT(groupid, 15)) {
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1498
			dg->default_group = NewCallBackResultSpriteGroup(groupid);
2515
480538b48b0f (svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
peter1138
parents: 2508
diff changeset
  1499
			dg->default_group->ref_count++;
480538b48b0f (svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
peter1138
parents: 2508
diff changeset
  1500
		} else if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
480538b48b0f (svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
peter1138
parents: 2508
diff changeset
  1501
			grfmsg(GMS_WARN, "NewSpriteGroup(%02x:0x%x): Groupid %04x does not exist, leaving empty.", setid, numloaded, groupid);
480538b48b0f (svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
peter1138
parents: 2508
diff changeset
  1502
			dg->default_group = NULL;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1503
		} else {
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1504
			dg->default_group = _cur_grffile->spritegroups[groupid];
2515
480538b48b0f (svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
peter1138
parents: 2508
diff changeset
  1505
		dg->default_group->ref_count++;
419
2fbd23a1cedc (svn r616) -newgrf: Fixed crashing when trying to resolve references to unknown or callback result spritegroups in variational spritegroup handler of NewSpriteGroup() (pasky).
darkvater
parents: 418
diff changeset
  1506
		}
2fbd23a1cedc (svn r616) -newgrf: Fixed crashing when trying to resolve references to unknown or callback result spritegroups in variational spritegroup handler of NewSpriteGroup() (pasky).
darkvater
parents: 418
diff changeset
  1507
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  1508
		if (_cur_grffile->spritegroups[setid] != NULL)
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  1509
			UnloadSpriteGroup(&_cur_grffile->spritegroups[setid]);
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
  1510
		_cur_grffile->spritegroups[setid] = group;
2490
a0db300b6da6 (svn r3016) -NewGRF: Implement the start of reference counting for sprite groups. This will allow unloading.
peter1138
parents: 2489
diff changeset
  1511
		group->ref_count++;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1512
		return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1513
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
  1514
	} else if (numloaded == 0x80 || numloaded == 0x83) {
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1515
		RandomizedSpriteGroup *rg;
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
  1516
		int i;
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
  1517
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
  1518
		/* This stuff is getting actually evaluated in
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
  1519
		 * EvalRandomizedSpriteGroup(). */
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
  1520
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
  1521
		buf += 4;
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
  1522
		len -= 4;
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
  1523
		check_length(len, 6, "NewSpriteGroup 0x80/0x83");
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
  1524
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
  1525
		group = calloc(1, sizeof(*group));
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
  1526
		group->type = SGT_RANDOMIZED;
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
  1527
		rg = &group->g.random;
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
  1528
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
  1529
		/* XXX: We don't free() anything, assuming that if there was
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
  1530
		 * some action here before, it got associated by action 3.
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
  1531
		 * We should perhaps keep some refcount? --pasky */
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
  1532
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
  1533
		rg->var_scope = numloaded == 0x83 ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF;
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
  1534
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
  1535
		rg->triggers = grf_load_byte(&buf);
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
  1536
		rg->cmp_mode = rg->triggers & 0x80;
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
  1537
		rg->triggers &= 0x7F;
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
  1538
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
  1539
		rg->lowest_randbit = grf_load_byte(&buf);
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
  1540
		rg->num_groups = grf_load_byte(&buf);
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
  1541
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
  1542
		rg->groups = calloc(rg->num_groups, sizeof(*rg->groups));
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
  1543
		for (i = 0; i < rg->num_groups; i++) {
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
  1544
			uint16 groupid = grf_load_word(&buf);
448
5aa84112454c (svn r658) Ignore callbackish randomized spritegroups - they would just crash us (pasky)
tron
parents: 445
diff changeset
  1545
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
  1546
			if (HASBIT(groupid, 15)) {
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1547
				rg->groups[i] = NewCallBackResultSpriteGroup(groupid);
2490
a0db300b6da6 (svn r3016) -NewGRF: Implement the start of reference counting for sprite groups. This will allow unloading.
peter1138
parents: 2489
diff changeset
  1548
				rg->groups[i]->ref_count++;
2515
480538b48b0f (svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
peter1138
parents: 2508
diff changeset
  1549
			} else if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
480538b48b0f (svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
peter1138
parents: 2508
diff changeset
  1550
				grfmsg(GMS_WARN, "NewSpriteGroup(%02x:0x%x): Groupid %04x does not exist, leaving empty.", setid, numloaded, groupid);
480538b48b0f (svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
peter1138
parents: 2508
diff changeset
  1551
				rg->groups[i] = NULL;
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
  1552
			} else {
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
  1553
				rg->groups[i] = _cur_grffile->spritegroups[groupid];
2490
a0db300b6da6 (svn r3016) -NewGRF: Implement the start of reference counting for sprite groups. This will allow unloading.
peter1138
parents: 2489
diff changeset
  1554
				rg->groups[i]->ref_count++;
448
5aa84112454c (svn r658) Ignore callbackish randomized spritegroups - they would just crash us (pasky)
tron
parents: 445
diff changeset
  1555
			}
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
  1556
		}
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
  1557
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  1558
		if (_cur_grffile->spritegroups[setid] != NULL)
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  1559
			UnloadSpriteGroup(&_cur_grffile->spritegroups[setid]);
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
  1560
		_cur_grffile->spritegroups[setid] = group;
2490
a0db300b6da6 (svn r3016) -NewGRF: Implement the start of reference counting for sprite groups. This will allow unloading.
peter1138
parents: 2489
diff changeset
  1561
		group->ref_count++;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1562
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1563
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1564
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1565
	if (!_cur_grffile->spriteset_start) {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1566
		grfmsg(GMS_ERROR, "NewSpriteGroup: No sprite set to work on! Skipping.");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1567
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1568
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1570
	if (_cur_grffile->spriteset_feature != feature) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1571
		grfmsg(GMS_ERROR, "NewSpriteGroup: Group feature %x doesn't match set feature %x! Playing it risky and trying to use it anyway.", feature, _cur_grffile->spriteset_feature);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1572
		// return; // XXX: we can't because of MB's newstats.grf --pasky
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1573
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1574
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1575
	check_length(bufend - buf, 5, "NewSpriteGroup");
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1576
	buf += 5;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1577
	check_length(bufend - buf, 2 * numloaded, "NewSpriteGroup");
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1578
	loaded_ptr = buf;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1579
	loading_ptr = buf + 2 * numloaded;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1580
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  1581
	if (_cur_grffile->first_spriteset == 0)
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  1582
		_cur_grffile->first_spriteset = _cur_grffile->spriteset_start;
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  1583
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1584
	if (numloaded > 16) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1585
		grfmsg(GMS_WARN, "NewSpriteGroup: More than 16 sprites in group %x, skipping the rest.", setid);
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1586
		numloaded = 16;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1587
	}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1588
	if (numloading > 16) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1589
		grfmsg(GMS_WARN, "NewSpriteGroup: More than 16 sprites in group %x, skipping the rest.", setid);
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1590
		numloading = 16;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1591
	}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1592
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
  1593
	group = calloc(1, sizeof(*group));
408
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1594
	group->type = SGT_REAL;
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1595
	rg = &group->g.real;
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1596
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1597
	rg->sprites_per_set = _cur_grffile->spriteset_numents;
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1598
	rg->loaded_count  = numloaded;
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1599
	rg->loading_count = numloading;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1600
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1601
	DEBUG(grf, 6) ("NewSpriteGroup: New SpriteGroup 0x%02hhx, %u views, %u loaded, %u loading, sprites %u - %u",
408
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1602
			setid, rg->sprites_per_set, rg->loaded_count, rg->loading_count,
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1603
			_cur_grffile->spriteset_start - _cur_grffile->sprite_offset,
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1604
			_cur_grffile->spriteset_start + (_cur_grffile->spriteset_numents * (numloaded + numloading)) - _cur_grffile->sprite_offset);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1605
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1606
	for (i = 0; i < numloaded; i++) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1607
		uint16 spriteset_id = grf_load_word(&loaded_ptr);
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
  1608
		if (HASBIT(spriteset_id, 15)) {
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
  1609
			rg->loaded[i] = NewCallBackResultSpriteGroup(spriteset_id);
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
  1610
		} else {
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
  1611
			rg->loaded[i] = NewResultSpriteGroup(_cur_grffile->spriteset_start + spriteset_id * _cur_grffile->spriteset_numents, rg->sprites_per_set);
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1612
		}
2490
a0db300b6da6 (svn r3016) -NewGRF: Implement the start of reference counting for sprite groups. This will allow unloading.
peter1138
parents: 2489
diff changeset
  1613
		rg->loaded[i]->ref_count++;
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
  1614
		DEBUG(grf, 8) ("NewSpriteGroup: + rg->loaded[%i]  = %u (subset %u)", i, rg->loaded[i]->g.result.result, spriteset_id);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1615
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1616
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1617
	for (i = 0; i < numloading; i++) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1618
		uint16 spriteset_id = grf_load_word(&loading_ptr);
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
  1619
		if (HASBIT(spriteset_id, 15)) {
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
  1620
			rg->loading[i] = NewCallBackResultSpriteGroup(spriteset_id);
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
  1621
		} else {
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
  1622
			rg->loading[i] = NewResultSpriteGroup(_cur_grffile->spriteset_start + spriteset_id * _cur_grffile->spriteset_numents, rg->sprites_per_set);
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1623
		}
2490
a0db300b6da6 (svn r3016) -NewGRF: Implement the start of reference counting for sprite groups. This will allow unloading.
peter1138
parents: 2489
diff changeset
  1624
		rg->loading[i]->ref_count++;
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
  1625
		DEBUG(grf, 8) ("NewSpriteGroup: + rg->loading[%i] = %u (subset %u)", i, rg->loading[i]->g.result.result, spriteset_id);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1626
	}
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
  1627
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  1628
	if (_cur_grffile->spritegroups[setid] != NULL)
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  1629
		UnloadSpriteGroup(&_cur_grffile->spritegroups[setid]);
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
  1630
	_cur_grffile->spritegroups[setid] = group;
2490
a0db300b6da6 (svn r3016) -NewGRF: Implement the start of reference counting for sprite groups. This will allow unloading.
peter1138
parents: 2489
diff changeset
  1631
	group->ref_count++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1632
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1633
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1634
/* Action 0x03 */
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1635
static void NewVehicle_SpriteGroupMapping(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1636
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1637
	/* <03> <feature> <n-id> <ids>... <num-cid> [<cargo-type> <cid>]... <def-cid>
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1638
	 * id-list	:= [<id>] [id-list]
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1639
	 * cargo-list	:= <cargo-type> <cid> [cargo-list]
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1641
	 * B feature       see action 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1642
	 * B n-id          bits 0-6: how many IDs this definition applies to
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1643
	 *                 bit 7: if set, this is a wagon override definition (see below)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
	 * B ids           the IDs for which this definition applies
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1645
	 * B num-cid       number of cargo IDs (sprite group IDs) in this definition
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1646
	 *                 can be zero, in that case the def-cid is used always
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1647
	 * B cargo-type    type of this cargo type (e.g. mail=2, wood=7, see below)
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1648
	 * W cid           cargo ID (sprite group ID) for this type of cargo
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1649
	 * W def-cid       default cargo ID (sprite group ID) */
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1650
	/* TODO: Bridges, town houses. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1651
	/* TODO: Multiple cargo support could be useful even for trains/cars -
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1652
	 * cargo id 0xff is used for showing images in the build train list. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1653
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1654
	static byte *last_engines;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1655
	static int last_engines_count;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1656
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1657
	uint8 idcount;
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1658
	bool wagover;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1659
	uint8 cidcount;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1660
	int c, i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1661
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1662
	check_length(len, 7, "VehicleMapSpriteGroup");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1663
	feature = buf[1];
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1664
	idcount = buf[2] & 0x7F;
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1665
	wagover = (buf[2] & 0x80) == 0x80;
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1666
	check_length(len, 3 + idcount, "VehicleMapSpriteGroup");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1667
	cidcount = buf[3 + idcount];
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1668
	check_length(len, 4 + idcount + cidcount * 3, "VehicleMapSpriteGroup");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1669
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1670
	DEBUG(grf, 6) ("VehicleMapSpriteGroup: Feature %d, %d ids, %d cids, wagon override %d.",
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1671
			feature, idcount, cidcount, wagover);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1672
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1673
	if (feature > GSF_STATION) {
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1674
		grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Unsupported feature %d, skipping.", feature);
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1675
		return;
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1676
	}
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1677
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1678
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
  1679
	if (feature == GSF_STATION) {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1680
		// We do things differently for stations.
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1681
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
  1682
		for (i = 0; i < idcount; i++) {
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1683
			uint8 stid = buf[3 + i];
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1684
			StationSpec *stat = &_cur_grffile->stations[stid];
403
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1685
			byte *bp = &buf[4 + idcount];
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1686
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
  1687
			for (c = 0; c < cidcount; c++) {
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1688
				uint8 ctype = grf_load_byte(&bp);
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1689
				uint16 groupid = grf_load_word(&bp);
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1690
2516
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  1691
				if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  1692
					grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x or empty, skipping.",
403
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1693
					       groupid, _cur_grffile->spritegroups_count);
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1694
					return;
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1695
				}
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
  1696
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
  1697
				if (ctype != 0xFF) {
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
  1698
					/* TODO: No support for any other cargo. */
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
  1699
					continue;
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
  1700
				}
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
  1701
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1702
				stat->spritegroup[1] = _cur_grffile->spritegroups[groupid];
2490
a0db300b6da6 (svn r3016) -NewGRF: Implement the start of reference counting for sprite groups. This will allow unloading.
peter1138
parents: 2489
diff changeset
  1703
				stat->spritegroup[1]->ref_count++;
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
  1704
			}
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
  1705
		}
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
  1706
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
  1707
		{
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
  1708
			byte *bp = buf + 4 + idcount + cidcount * 3;
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1709
			uint16 groupid = grf_load_word(&bp);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1710
2516
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  1711
			if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  1712
				grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x or empty, skipping.",
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1713
				       groupid, _cur_grffile->spritegroups_count);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1714
				return;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1715
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1716
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
  1717
			for (i = 0; i < idcount; i++) {
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1718
				uint8 stid = buf[3 + i];
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1719
				StationSpec *stat = &_cur_grffile->stations[stid];
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1720
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1721
				stat->spritegroup[0] = _cur_grffile->spritegroups[groupid];
2490
a0db300b6da6 (svn r3016) -NewGRF: Implement the start of reference counting for sprite groups. This will allow unloading.
peter1138
parents: 2489
diff changeset
  1722
				stat->spritegroup[0]->ref_count++;
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
  1723
				stat->grfid = _cur_grffile->grfid;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  1724
				stat->localidx = stid;
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  1725
				SetCustomStation(stat);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1726
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1727
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1728
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1729
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1730
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1731
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1732
	/* If ``n-id'' (or ``idcount'') is zero, this is a ``feature
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1733
	 * callback''. I have no idea how this works, so we will ignore it for
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1734
	 * now.  --octo */
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1735
	if (idcount == 0) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1736
		grfmsg(GMS_NOTICE, "NewMapping: Feature callbacks not implemented yet.");
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1737
		return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1738
	}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1739
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1740
	// FIXME: Tropicset contains things like:
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1741
	// 03 00 01 19 01 00 00 00 00 - this is missing one 00 at the end,
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1742
	// what should we exactly do with that? --pasky
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1743
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1744
	if (!_cur_grffile->spriteset_start || !_cur_grffile->spritegroups) {
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1745
		grfmsg(GMS_WARN, "VehicleMapSpriteGroup: No sprite set to work on! Skipping.");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1746
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1747
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1748
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1749
	if (!wagover && last_engines_count != idcount) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1750
		last_engines = realloc(last_engines, idcount);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1751
		last_engines_count = idcount;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1752
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1753
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1754
	if (wagover) {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1755
		if (last_engines_count == 0) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1756
			grfmsg(GMS_ERROR, "VehicleMapSpriteGroup: WagonOverride: No engine to do override with.");
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1757
			return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1758
		}
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1759
		DEBUG(grf, 6) ("VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons.",
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1760
				last_engines_count, idcount);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1761
	}
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
  1762
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1763
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1764
	for (i = 0; i < idcount; i++) {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1765
		uint8 engine_id = buf[3 + i];
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1766
		uint8 engine = engine_id + _vehshifts[feature];
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1767
		byte *bp = &buf[4 + idcount];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1768
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1769
		if (engine_id > _vehcounts[feature]) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1770
			grfmsg(GMS_ERROR, "Id %u for feature %x is out of bounds.",
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1771
					engine_id, feature);
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1772
			return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1773
		}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1774
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1775
		DEBUG(grf, 7) ("VehicleMapSpriteGroup: [%d] Engine %d...", i, engine);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1776
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1777
		for (c = 0; c < cidcount; c++) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1778
			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
  1779
			uint16 groupid = grf_load_word(&bp);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1780
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1781
			DEBUG(grf, 8) ("VehicleMapSpriteGroup: * [%d] Cargo type %x, group id %x", c, ctype, groupid);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1782
2516
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  1783
			if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  1784
				grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x or empty, skipping.", groupid, _cur_grffile->spritegroups_count);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1785
				return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1786
			}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1787
1802
448f187042d3 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1611
diff changeset
  1788
			if (ctype == GC_INVALID) ctype = GC_PURCHASE;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1789
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1790
			if (wagover) {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1791
				// TODO: No multiple cargo types per vehicle yet. --pasky
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
  1792
				SetWagonOverrideSprites(engine, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1793
			} 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
  1794
				SetCustomEngineSprites(engine, ctype, _cur_grffile->spritegroups[groupid]);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1795
				last_engines[i] = engine;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1796
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1797
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1798
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1799
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1800
	{
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1801
		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
  1802
		uint16 groupid = grf_load_word(&bp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1803
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1804
		DEBUG(grf, 8) ("-- Default group id %x", groupid);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1805
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1806
		for (i = 0; i < idcount; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1807
			uint8 engine = buf[3 + i] + _vehshifts[feature];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1808
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1809
			// 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
  1810
			if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  1811
				grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x or empty, skipping.", groupid, _cur_grffile->spritegroups_count);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1812
				return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1813
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1814
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1815
			if (wagover) {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1816
				// TODO: No multiple cargo types per vehicle yet. --pasky
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
  1817
				SetWagonOverrideSprites(engine, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1818
			} 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
  1819
				SetCustomEngineSprites(engine, GC_DEFAULT, _cur_grffile->spritegroups[groupid]);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1820
				last_engines[i] = engine;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1821
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1822
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1823
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1824
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1825
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1826
/* Action 0x04 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1827
static void VehicleNewName(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1828
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1829
	/* <04> <veh-type> <language-id> <num-veh> <offset> <data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1830
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1831
	 * B veh-type      see action 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1832
	 * B language-id   language ID with bit 7 cleared (see below)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1833
	 * 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
  1834
	 * B/W offset      number of the first vehicle that gets a new name
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1835
	 * 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
  1836
	 *                 which the next name begins. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1837
	/* TODO: No support for changing non-vehicle text. Perhaps we shouldn't
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1838
	 * implement it at all, but it could be useful for some "modpacks"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1839
	 * (completely new scenarios changing all graphics and logically also
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1840
	 * factory names etc). We should then also support all languages (by
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1841
	 * name), not only the original four ones. --pasky */
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1842
	/* TODO: Support for custom station class/type names. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1843
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1844
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1845
	uint8 lang;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1846
	uint8 num;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1847
	uint16 id;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1848
	uint16 endid;
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  1849
	const char* name;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1850
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1851
	check_length(len, 6, "VehicleNewName");
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1852
	buf++;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1853
	feature  = grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1854
	lang     = grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1855
	num      = grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1856
	id       = (lang & 0x80) ? grf_load_word(&buf) : grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1857
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1858
	if (feature > 3) {
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1859
		DEBUG(grf, 7) ("VehicleNewName: Unsupported feature %d, skipping", feature);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1860
		return;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1861
	}
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1862
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1863
	id      += _vehshifts[feature];
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1864
	endid    = id + num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1865
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1866
	DEBUG(grf, 6) ("VehicleNewName: About to rename engines %d..%d (feature %d) in language 0x%x.",
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1867
	               id, endid, feature, lang);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1868
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1869
	if (lang & 0x80) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1870
		grfmsg(GMS_WARN, "VehicleNewName: No support for changing in-game texts. Skipping.");
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1871
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1872
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1873
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1874
	if (!(lang & 3)) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1875
		/* XXX: If non-English name, silently skip it. */
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1876
		DEBUG(grf, 7) ("VehicleNewName: Skipping non-English name.");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1877
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1878
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1879
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1880
	name = (const char*)buf;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1881
	len -= (lang & 0x80) ? 6 : 5;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1882
	for (; id < endid && len > 0; id++) {
2458
c95808cd2ac9 (svn r2984) Use adequate types, this should aid portability a bit
tron
parents: 2456
diff changeset
  1883
		size_t ofs = strlen(name) + 1;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1884
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1885
		if (ofs < 128) {
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  1886
			DEBUG(grf, 8) ("VehicleNewName: %d <- %s", id, name);
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  1887
			SetCustomEngineName(id, name);
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1888
		} else {
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1889
			DEBUG(grf, 7) ("VehicleNewName: Too long a name (%d)", ofs);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1890
		}
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  1891
		name += ofs;
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  1892
		len -= ofs;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1893
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1894
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1895
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1896
/* Action 0x05 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1897
static void GraphicsNew(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1898
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1899
	/* <05> <graphics-type> <num-sprites> <other data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1900
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1901
	 * 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
  1902
	 * 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
  1903
	 * V other data    Graphics type specific data.  Currently unused. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1904
	/* TODO */
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1905
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1906
	uint8 type;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1907
	uint16 num;
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1908
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1909
	check_length(len, 2, "GraphicsNew");
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1910
	buf++;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1911
	type = grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1912
	num  = grf_load_extended(&buf);
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1913
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1914
	grfmsg(GMS_NOTICE, "GraphicsNew: Custom graphics (type %x) sprite block of length %d (unimplemented, ignoring).\n",
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1915
	       type, num);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1916
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1917
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1918
/* Action 0x06 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1919
static void CfgApply(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1920
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1921
	/* <06> <param-num> <param-size> <offset> ... <FF>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1922
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1923
	 * B param-num     Number of parameter to substitute (First = "zero")
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1924
	 *                 Ignored if that parameter was not specified in newgrf.cfg
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
	 * B param-size    How many bytes to replace.  If larger than 4, the
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1926
	 *                 bytes of the following parameter are used.  In that
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1927
	 *                 case, nothing is applied unless *all* parameters
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1928
	 *                 were specified.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
	 * B offset        Offset into data from beginning of next sprite
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1930
	 *                 to place where parameter is to be stored. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1931
	/* TODO */
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1932
	grfmsg(GMS_NOTICE, "CfgApply: Ignoring (not implemented).\n");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1933
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1934
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1935
/* Action 0x07 */
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1936
/* Action 0x09 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1937
static void SkipIf(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1938
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1939
	/* <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
  1940
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1941
	 * B param-num
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1942
	 * B param-size
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1943
	 * B condition-type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1944
	 * V value
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1945
	 * B num-sprites */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1946
	/* TODO: More params. More condition types. */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1947
	uint8 param;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1948
	uint8 paramsize;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1949
	uint8 condtype;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1950
	uint8 numsprites;
2336
48ace1344af0 (svn r2862) Return a proper version number, when testing the TTDPatch version in the SkipIf action. Pretend to be version 2.0.1 alpha 49 for now.
tron
parents: 2324
diff changeset
  1951
	uint32 param_val = 0;
48ace1344af0 (svn r2862) Return a proper version number, when testing the TTDPatch version in the SkipIf action. Pretend to be version 2.0.1 alpha 49 for now.
tron
parents: 2324
diff changeset
  1952
	uint32 cond_val = 0;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1953
	bool result;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1954
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1955
	check_length(len, 6, "SkipIf");
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1956
	param = buf[1];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1957
	paramsize = buf[2];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1958
	condtype = buf[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1959
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
  1960
	if (condtype < 2) {
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  1961
		/* 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
  1962
		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
  1963
	}
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
  1964
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
  1965
	buf += 4;
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  1966
	switch (paramsize) {
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  1967
		case 4: cond_val = grf_load_dword(&buf); break;
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  1968
		case 2: cond_val = grf_load_word(&buf);  break;
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  1969
		case 1: cond_val = grf_load_byte(&buf);  break;
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  1970
		default: break;
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  1971
	}
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
  1972
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
  1973
	switch (param) {
401
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  1974
		case 0x83:    /* current climate, 0=temp, 1=arctic, 2=trop, 3=toyland */
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
  1975
			param_val = _opt.landscape;
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
  1976
			break;
401
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  1977
		case 0x84:    /* .grf loading stage, 0=initialization, 1=activation */
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1978
			param_val = _cur_stage;
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
  1979
			break;
401
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  1980
		case 0x85:    /* TTDPatch flags, only for bit tests */
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
  1981
			param_val = _ttdpatch_flags[cond_val / 0x20];
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
  1982
			cond_val %= 0x20;
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
  1983
			break;
401
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  1984
		case 0x86:    /* road traffic side, bit 4 clear=left, set=right */
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
  1985
			param_val = _opt.road_side << 4;
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
  1986
			break;
401
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  1987
		case 0x88: {  /* see if specified GRFID is active */
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  1988
			param_val = (GetFileByGRFID(cond_val) != NULL);
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
  1989
		}	break;
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
  1990
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
  1991
		case 0x8B: { /* TTDPatch version */
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
  1992
			uint major    = 2;
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
  1993
			uint minor    = 0;
48ace1344af0 (svn r2862) Return a proper version number, when testing the TTDPatch version in the SkipIf action. Pretend to be version 2.0.1 alpha 49 for now.
tron
parents: 2324
diff changeset
  1994
			uint revision = 10; // special case: 2.0.1 is 2.0.10
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
  1995
			uint build    = 49;
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
  1996
			param_val = (major << 24) | (minor << 20) | (revision << 16) | (build * 10);
401
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  1997
			break;
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
  1998
		}
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
  1999
401
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  2000
		case 0x8D:    /* TTD Version, 00=DOS, 01=Windows */
2582
5766de903758 (svn r3119) Don't pretend to be the Windows version of TTD all the time. When being asked answer according to _use_dos_palette. (Suggestion by Belugas)
tron
parents: 2549
diff changeset
  2001
			param_val = !_use_dos_palette;
401
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  2002
			break;
420
d3a089648ec3 (svn r617) -newgrf: Support for parameter 0x8E (train Y-pitch in info windows) both setting and testing. This should fix displaced wagons in DBSetXL as reported by DarkVater. (pasky)
darkvater
parents: 419
diff changeset
  2003
		case 0x8E:
d3a089648ec3 (svn r617) -newgrf: Support for parameter 0x8E (train Y-pitch in info windows) both setting and testing. This should fix displaced wagons in DBSetXL as reported by DarkVater. (pasky)
darkvater
parents: 419
diff changeset
  2004
			param_val = _traininfo_vehicle_pitch;
d3a089648ec3 (svn r617) -newgrf: Support for parameter 0x8E (train Y-pitch in info windows) both setting and testing. This should fix displaced wagons in DBSetXL as reported by DarkVater. (pasky)
darkvater
parents: 419
diff changeset
  2005
			break;
2614
0e69ad985358 (svn r3152) - NewGRF: [ 1340189 ] Action 7/9 new value : is it TTDPatch or OpenTTD? (belugas)
peter1138
parents: 2611
diff changeset
  2006
		case 0x9D:    /* TTD Platform, 00=TTDPatch, 01=OpenTTD */
0e69ad985358 (svn r3152) - NewGRF: [ 1340189 ] Action 7/9 new value : is it TTDPatch or OpenTTD? (belugas)
peter1138
parents: 2611
diff changeset
  2007
			param_val = 1;
0e69ad985358 (svn r3152) - NewGRF: [ 1340189 ] Action 7/9 new value : is it TTDPatch or OpenTTD? (belugas)
peter1138
parents: 2611
diff changeset
  2008
			break;
401
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  2009
		/* TODO */
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  2010
		case 0x8F:    /* Track type cost multipliers */
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
  2011
		default:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2012
			if (param < 0x80) {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2013
				/* Parameter. */
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2014
				param_val = _cur_grffile->param[param];
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
  2015
			} else {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2016
				/* In-game variable. */
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2017
				grfmsg(GMS_WARN, "Unsupported in-game variable 0x%02X. Ignoring test.", param);
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2018
				return;
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
  2019
			}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2020
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2021
1606
4ec79f87951a (svn r2110) - Fix: Fixed test for various flags (e.g. newtrains in usset). result is bool so !! any non-zero values before assigning them to it - they apparently didn't fit. ;-)
pasky
parents: 1542
diff changeset
  2022
	DEBUG(grf, 7) ("Test condtype %d, param %x, condval %x", condtype, param_val, cond_val);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2023
	switch (condtype) {
1606
4ec79f87951a (svn r2110) - Fix: Fixed test for various flags (e.g. newtrains in usset). result is bool so !! any non-zero values before assigning them to it - they apparently didn't fit. ;-)
pasky
parents: 1542
diff changeset
  2024
		case 0: result = !!(param_val & (1 << cond_val));
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2025
			break;
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
  2026
		case 1: result = !(param_val & (1 << cond_val));
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
  2027
			break;
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
  2028
		/* TODO: For the following, make it to work with 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
  2029
		case 2: result = (param_val == cond_val);
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
  2030
			break;
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
  2031
		case 3: result = (param_val != cond_val);
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
  2032
			break;
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
  2033
		case 4: result = (param_val < cond_val);
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
  2034
			break;
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
  2035
		case 5: result = (param_val > cond_val);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2036
			break;
1606
4ec79f87951a (svn r2110) - Fix: Fixed test for various flags (e.g. newtrains in usset). result is bool so !! any non-zero values before assigning them to it - they apparently didn't fit. ;-)
pasky
parents: 1542
diff changeset
  2037
		case 6: result = !!param_val; /* GRFID is active (only for param-num=88) */
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
  2038
			break;
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
  2039
		case 7: result = !param_val; /* GRFID is not active (only for param-num=88) */
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
  2040
			break;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2041
		default:
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2042
			grfmsg(GMS_WARN, "Unsupported test %d. Ignoring.", condtype);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2043
			return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2044
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2045
1607
320079c7ac28 (svn r2111) So, result is bool therefore no need for this horrible == 0 thing.
pasky
parents: 1606
diff changeset
  2046
	if (!result) {
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  2047
		grfmsg(GMS_NOTICE, "Not skipping sprites, test was false.");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2048
		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
  2049
	}
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
  2050
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
  2051
	numsprites = grf_load_byte(&buf);
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2052
	grfmsg(GMS_NOTICE, "Skipping %d sprites, test was true.", numsprites);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2053
	_skip_sprites = numsprites;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2054
	if (_skip_sprites == 0) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2055
		/* Zero means there are no sprites to skip, so
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2056
		 * we use -1 to indicate that all further
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2057
		 * sprites should be skipped. */
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2058
		_skip_sprites = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2059
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2060
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2061
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2062
static void GRFInfo(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2063
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2064
	/* <08> <version> <grf-id> <name> <info>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2065
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2066
	 * B version       newgrf version, currently 06
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2067
	 * 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
  2068
	 * S name          name of this .grf set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2069
	 * S info          string describing the set, and e.g. author and copyright */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2070
	/* TODO: Check version. (We should have own versioning done somehow.) */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2071
	uint8 version;
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  2072
	uint32 grfid;
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  2073
	const char *name;
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  2074
	const char *info;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2075
2479
eb73083a5f5f (svn r3005) -Fix, NewGRF: Some GRF files don't specify a name or description, in which case the Action 8 is 8 bytes, not 9. (pb_viaduct)
peter1138
parents: 2478
diff changeset
  2076
	check_length(len, 8, "GRFInfo");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2077
	version = buf[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
  2078
	/* this is de facto big endian - grf_load_dword() unsuitable */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2079
	grfid = buf[2] << 24 | buf[3] << 16 | buf[4] << 8 | buf[5];
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  2080
	name = (const char*)(buf + 6);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2081
	info = name + strlen(name) + 1;
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  2082
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
  2083
	_cur_grffile->grfid = grfid;
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
  2084
	_cur_grffile->flags |= 0x0001; /* set active flag */
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
  2085
2013
1b80954e9594 (svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents: 1968
diff changeset
  2086
	DEBUG(grf, 1) ("[%s] Loaded GRFv%d set %08lx - %s:\n%s",
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
  2087
	               _cur_grffile->filename, version, grfid, name, info);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2088
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2089
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2090
static void SpriteReplace(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2091
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2092
	/* <0A> <num-sets> <set1> [<set2> ...]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2093
	 * <set>: <num-sprites> <first-sprite>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2094
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2095
	 * 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
  2096
	 * Each set:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2097
	 * 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
  2098
	 * 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
  2099
	uint8 num_sets;
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2100
	uint i;
361
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  2101
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
  2102
	buf++; /* skip action byte */
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  2103
	num_sets = grf_load_byte(&buf);
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  2104
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
  2105
	for (i = 0; i < num_sets; i++) {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2106
		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
  2107
		uint16 first_sprite = grf_load_word(&buf);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2108
		uint j;
398
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
  2109
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
  2110
		grfmsg(GMS_NOTICE,
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2111
			"SpriteReplace: [Set %d] Changing %d sprites, beginning with %d",
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2112
			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
  2113
		);
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
  2114
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
  2115
		for (j = 0; j < num_sprites; j++) {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2116
			LoadNextSprite(first_sprite + j, _file_index); // XXX
2849
73c752b82488 (svn r3397) - NewGRF fix: Show nfo sprite number instead of current sprite id for warning messages -- this makes this output more useful...
peter1138
parents: 2846
diff changeset
  2117
			nfo_line++;
361
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  2118
		}
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
  2119
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2120
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2121
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2122
static void GRFError(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2123
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2124
	/* <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
  2125
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2126
	 * B severity      00: notice, contine loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2127
	 *                 01: warning, continue loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2128
	 *                 02: error, but continue loading grf file, and attempt
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2129
	 *                     loading grf again when loading or starting next game
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2130
	 *                 03: error, abort loading and prevent loading again in
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2131
	 *                     the future (only when restarting the patch)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2132
	 * 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
  2133
	 * B message-id    message to show, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2134
	 * 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
  2135
	 *                 not present for built-in messages.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2136
	 * V data          additional data for built-in (or custom) messages
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2137
	 * B parnum        see action 6, only used with built-in message 03 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2138
	/* TODO: For now we just show the message, sometimes incomplete and never translated. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2139
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2140
	static const char * const msgstr[4] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2141
		"Requires at least pseudo-TTDPatch version %s.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2142
		"This file is for %s version of TTD.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2143
		"Designed to be used with %s.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2144
		"Invalid parameter %s.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2145
	};
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2146
	uint8 severity;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2147
	uint8 msgid;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2148
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2149
	check_length(len, 6, "GRFError");
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2150
	severity = buf[1];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2151
	msgid = buf[3];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2152
441
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2153
	// Undocumented TTDPatch feature.
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2154
	if ((severity & 0x80) == 0 && _cur_stage == 0)
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2155
		return;
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2156
	severity &= 0x7F;
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2157
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  2158
	if (msgid == 0xFF) {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2159
		grfmsg(severity, "%s", buf+4);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2160
	} else {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2161
		grfmsg(severity, msgstr[msgid], buf+4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2162
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2163
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2164
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2165
static void GRFComment(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2166
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2167
	/* <0C> [<ignored...>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2168
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2169
	 * V ignored       Anything following the 0C is ignored */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2170
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2171
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2172
/* Action 0x0D */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2173
static void ParamSet(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2174
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2175
	/* <0D> <target> <operation> <source1> <source2> [<data>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2176
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2177
	 * B target        parameter number where result is stored
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2178
	 * B operation     operation to perform, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2179
	 * B source1       first source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2180
	 * B source2       second source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2181
	 * 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
  2182
	 *                 if both source1 and source2 refer to actual parameters
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2183
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2184
	 * Operations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2185
	 * 00      Set parameter equal to source1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2186
	 * 01      Addition, source1 + source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2187
	 * 02      Subtraction, source1 - source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2188
	 * 03      Unsigned multiplication, source1 * source2 (both unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2189
	 * 04      Signed multiplication, source1 * source2 (both signed)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2190
	 * 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
  2191
	 *         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
  2192
	 *         negative, source1 is unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2193
	 * 06      Signed bit shift, source1 by source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2194
	 *         (source2 like in 05, and source1 as well)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2195
	 */
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
  2196
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
  2197
	byte target;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2198
	byte oper;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2199
	uint32 src1;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2200
	uint32 src2;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2201
	uint32 data = 0;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2202
	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
  2203
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
  2204
	check_length(len, 5, "ParamSet");
418
67457dd7e5bc (svn r615) Fix the same bug in ParamSet action loading, pointer out by Bjarni too. (pasky)
bjarni
parents: 416
diff changeset
  2205
	buf++;
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2206
	target = grf_load_byte(&buf);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2207
	oper = grf_load_byte(&buf);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2208
	src1 = grf_load_byte(&buf);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2209
	src2 = grf_load_byte(&buf);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2210
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2211
	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
  2212
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
  2213
	/* 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
  2214
	 * 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
  2215
	 * 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
  2216
	 * - 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
  2217
	 * - 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
  2218
	 *   an earlier action D */
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2219
	if (oper & 0x80) {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2220
		if (_cur_grffile->param_end < 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
  2221
			oper &= 0x7F;
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
  2222
		else
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
  2223
			return;
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
  2224
	}
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
  2225
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
  2226
	/* The source1 and source2 operands refer to the grf parameter number
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
  2227
	 * like in action 6 and 7.  In addition, they can refer to the special
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
  2228
	 * variables available in action 7, or they can be FF to use the 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
  2229
	 * of <data>.  If referring to parameters that are undefined, a 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
  2230
	 * of 0 is used 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
  2231
	if (src1 == 0xFF) {
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
  2232
		src1 = data;
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
  2233
	} else {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2234
		src1 = _cur_grffile->param_end >= src1 ? _cur_grffile->param[src1] : 0;
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
  2235
	}
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
  2236
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
  2237
	if (src2 == 0xFF) {
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
  2238
		src2 = data;
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
  2239
	} else {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2240
		src2 = _cur_grffile->param_end >= src2 ? _cur_grffile->param[src2] : 0;
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
  2241
	}
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
  2242
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
  2243
	/* 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
  2244
	 * 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
  2245
	 * 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
  2246
	 * 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
  2247
	 * 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
  2248
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
  2249
	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
  2250
		case 0x00:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2251
			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
  2252
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2253
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2254
		case 0x01:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2255
			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
  2256
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2257
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2258
		case 0x02:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2259
			res = src1 - src2;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2260
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2261
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
  2262
		case 0x03:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2263
			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
  2264
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2265
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
  2266
		case 0x04:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2267
			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
  2268
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2269
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
  2270
		case 0x05:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2271
			if ((int32)src2 < 0)
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2272
				res = 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
  2273
			else
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2274
				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
  2275
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2276
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
  2277
		case 0x06:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2278
			if ((int32)src2 < 0)
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2279
				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
  2280
			else
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2281
				res = (int32)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
  2282
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2283
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2284
		case 0x07: /* Bitwise AND */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2285
			res = src1 & src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2286
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2287
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2288
		case 0x08: /* Bitwise OR */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2289
			res = src1 | src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2290
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2291
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2292
		case 0x09: /* Unsigned division */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2293
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2294
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2295
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2296
				res = src1 / src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2297
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2298
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2299
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2300
		case 0x0A: /* Signed divison */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2301
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2302
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2303
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2304
				res = (int32)src1 / (int32)src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2305
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2306
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2307
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2308
		case 0x0B: /* Unsigned modulo */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2309
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2310
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2311
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2312
				res = src1 % src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2313
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2314
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2315
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2316
		case 0x0C: /* Signed modulo */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2317
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2318
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2319
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2320
				res = (int32)src1 % (int32)src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2321
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2322
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2323
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
  2324
		default:
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2325
			grfmsg(GMS_ERROR, "ParamSet: Unknown operation %d, skipping.", oper);
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2326
			return;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2327
	}
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2328
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2329
	switch (target) {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2330
		case 0x8E: // Y-Offset for train sprites
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2331
			_traininfo_vehicle_pitch = res;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2332
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2333
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2334
		// TODO implement
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2335
		case 0x8F: // Rail track type cost factors
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2336
		case 0x93: // Tile refresh offset to left
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2337
		case 0x94: // Tile refresh offset to right
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2338
		case 0x95: // Tile refresh offset upwards
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2339
		case 0x96: // Tile refresh offset downwards
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2340
		case 0x97: // Snow line height
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2341
		case 0x99: // Global ID offset
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2342
			DEBUG(grf, 7) ("ParamSet: Skipping unimplemented target 0x%02X", target);
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2343
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2344
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2345
		default:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2346
			if (target < 0x80) {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2347
				_cur_grffile->param[target] = res;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2348
				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
  2349
			} else {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2350
				DEBUG(grf, 7) ("ParamSet: Skipping unknown target 0x%02X", target);
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2351
			}
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2352
			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
  2353
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2354
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2355
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2356
static void GRFInhibit(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2357
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2358
	/* <0E> <num> <grfids...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2359
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2360
	 * B num           Number of GRFIDs that follow
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2361
	 * 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
  2362
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
  2363
	byte num;
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2364
	int i;
398
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
  2365
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
  2366
	check_length(len, 1, "GRFInhibit");
416
810c6de8eeed (svn r613) Fix bug in GRFInhibit action loading, pointed out by Bjarni. (pasky)
bjarni
parents: 413
diff changeset
  2367
	buf++, len--;
367
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2368
	num = grf_load_byte(&buf); len--;
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2369
	check_length(len, 4 * num, "GRFInhibit");
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2370
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
  2371
	for (i = 0; i < num; i++) {
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2372
		uint32 grfid = grf_load_dword(&buf);
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  2373
		GRFFile *file = GetFileByGRFID(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
  2374
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
  2375
		/* Unset activation flag */
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
  2376
		if (file != NULL) {
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
  2377
			grfmsg(GMS_NOTICE, "GRFInhibit: Deactivating file ``%s''", file->filename);
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
  2378
			file->flags &= 0xFFFE;
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
  2379
		}
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
  2380
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2381
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2382
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
  2383
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
  2384
static void InitializeGRFSpecial(void)
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  2385
{
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
  2386
	/* FIXME: We should rather reflect reality in _ttdpatch_flags[]. */
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
  2387
2628
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2388
	_ttdpatch_flags[0] = (_patches.always_small_airport ? (1 << 0x0C) : 0)  /* keepsmallairport */
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2389
	                   | (1 << 0x0E)  /* largestations */
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2390
	                   | (_patches.longbridges ? (1 << 0x0F) : 0)           /* longbridges */
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2391
	                   | (1 << 0x12)  /* presignals */
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2392
	                   | (1 << 0x13)  /* extpresignals */
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2393
	                   | (_patches.never_expire_vehicles ? (1 << 0x16) : 0) /* enginespersist */
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2394
	                   | (1 << 0x1B); /* multihead */
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2395
	_ttdpatch_flags[1] = (_patches.mammoth_trains ? (1 << 0x08) : 0)        /* mammothtrains */
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2396
	                   | (1 << 0x09)  /* trainrefit */
441
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2397
	                   | (1 << 0x14)  /* bridgespeedlimits */
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2398
	                   | (1 << 0x16)  /* eternalgame */
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2399
	                   | (1 << 0x17)  /* newtrains */
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2400
	                   | (1 << 0x18)  /* newrvs */
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2401
	                   | (1 << 0x19)  /* newships */
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2402
	                   | (1 << 0x1A)  /* newplanes */
2628
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2403
	                   | (_patches.signal_side ? (1 << 0x1B) : 0);          /* signalsontrafficside */
441
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2404
	                   /* Uncomment following if you want to fool the GRF file.
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2405
	                    * Some GRF files will refuse to load without this
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2406
	                    * but you can still squeeze something from them even
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2407
	                    * without the support - i.e. USSet. --pasky */
1862
d07180add12f (svn r2368) - Fix: Add 'multihead' TTDPatch option to OpenTTD newgrf flags-emulation (DBSETXLW doesn't complain about it anymore)
Darkvater
parents: 1802
diff changeset
  2408
			               //| (1 << 0x1C); /* electrifiedrailway */
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
  2409
2628
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2410
	_ttdpatch_flags[2] = (_patches.build_on_slopes ? (1 << 0x0D) : 0)       /* buildonslopes */
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2411
	                   | (_patches.build_on_slopes ? (1 << 0x15) : 0)       /* buildoncoasts */
441
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2412
	                   | (1 << 0x16)  /* canals */
2456
93041d70867b (svn r2982) Newgrf: Added patch option for wagon speed limits. This is enabled by default.
peter1138
parents: 2445
diff changeset
  2413
	                   | (1 << 0x17)  /* newstartyear */
2628
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2414
	                   | (1 << 0x1A)  /* newbridges */
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2415
	                   | (_patches.wagon_speed_limits ? (1 << 0x1D) : 0);   /* wagonspeedlimits */
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2416
	_ttdpatch_flags[3] = (1 << 0x03)  /* pathbasedsignalling */
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2417
	                   | (1 << 0x0C)  /* enhancemultiplayer */
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2418
	                   | (1 << 0x0E)  /* irregularstations */
396166c3a2a5 (svn r3170) - NewGRF: make ttdpatch flags to reflect patch option status, and added some more values.
peter1138
parents: 2627
diff changeset
  2419
	                   | (1 << 0x10); /* autoreplace */
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
  2420
}
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
  2421
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
  2422
/**
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2423
 * Unload unused sprite groups from the specified GRF file.
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2424
 * Called after loading each GRF file.
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2425
 * @param file GRF file
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2426
 */
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2427
static void ReleaseSpriteGroups(GRFFile *file)
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2428
{
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2429
	int i;
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2430
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2431
	// Bail out if no spritegroups were defined.
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2432
	if (file->spritegroups == NULL)
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2433
		return;
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2434
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2435
	DEBUG(grf, 6)("ReleaseSpriteGroups: Releasing for `%s'.", file->filename);
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2436
	for (i = 0; i < file->spritegroups_count; i++) {
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2437
		if (file->spritegroups[i] != NULL)
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2438
			UnloadSpriteGroup(&file->spritegroups[i]);
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2439
	}
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2440
	free(file->spritegroups);
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2441
	file->spritegroups = NULL;
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2442
	file->spritegroups_count = 0;
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2443
}
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2444
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2445
static void ResetCustomStations(void)
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2446
{
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2447
	GRFFile *file;
2627
8c964f74bd7b (svn r3169) Little bit of coding style fixing, and change from value to lengthof()
peter1138
parents: 2625
diff changeset
  2448
	uint i;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2449
	CargoID c;
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2450
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2451
	for (file = _first_grffile; file != NULL; file = file->next) {
2627
8c964f74bd7b (svn r3169) Little bit of coding style fixing, and change from value to lengthof()
peter1138
parents: 2625
diff changeset
  2452
		for (i = 0; i < lengthof(file->stations); i++) {
8c964f74bd7b (svn r3169) Little bit of coding style fixing, and change from value to lengthof()
peter1138
parents: 2625
diff changeset
  2453
			if (file->stations[i].grfid != file->grfid) continue;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2454
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2455
			// TODO: Release renderdata, platforms and layouts
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2456
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2457
			// Release this stations sprite groups.
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2458
			for (c = 0; c < NUM_GLOBAL_CID; c++) {
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2459
				if (file->stations[i].spritegroup[c] != NULL)
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2460
					UnloadSpriteGroup(&file->stations[i].spritegroup[c]);
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2461
			}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2462
		}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2463
	}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2464
}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2465
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2466
/**
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
  2467
 * 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
  2468
 * 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
  2469
 */
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
  2470
static void ResetNewGRFData(void)
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  2471
{
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
  2472
	int i;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  2473
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
  2474
	// Copy/reset original engine info data
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  2475
	memcpy(&_engine_info, &orig_engine_info, sizeof(orig_engine_info));
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  2476
	memcpy(&_rail_vehicle_info, &orig_rail_vehicle_info, sizeof(orig_rail_vehicle_info));
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  2477
	memcpy(&_ship_vehicle_info, &orig_ship_vehicle_info, sizeof(orig_ship_vehicle_info));
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  2478
	memcpy(&_aircraft_vehicle_info, &orig_aircraft_vehicle_info, sizeof(orig_aircraft_vehicle_info));
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  2479
	memcpy(&_road_vehicle_info, &orig_road_vehicle_info, sizeof(orig_road_vehicle_info));
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  2480
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
  2481
	// Copy/reset original bridge info data
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  2482
	// First, free sprite table data
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  2483
	for (i = 0; i < MAX_BRIDGES; i++) {
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  2484
		if (_bridge[i].sprite_table != NULL) {
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
  2485
			byte j;
2480
c5fa654776a2 (svn r3006) -Fix, NewGRF: Don't assert on user input, skip data instead.
peter1138
parents: 2479
diff changeset
  2486
			for (j = 0; j < 7; j++)
c5fa654776a2 (svn r3006) -Fix, NewGRF: Don't assert on user input, skip data instead.
peter1138
parents: 2479
diff changeset
  2487
				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
  2488
			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
  2489
		}
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
  2490
	}
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
  2491
	memcpy(&_bridge, &orig_bridge, sizeof(_bridge));
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2492
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2493
	// Reset refit/cargo class data
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2494
	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
  2495
	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
  2496
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2497
	// Unload sprite group data
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2498
	UnloadWagonOverrides();
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2499
	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
  2500
	UnloadCustomEngineNames();
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  2501
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  2502
	// Reset price base data
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  2503
	ResetPriceBaseMultipliers();
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2504
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2505
	// Reset station classes
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2506
	ResetStationClasses();
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  2507
	ResetCustomStations();
2812
f250489941f9 (svn r3360) Fix initialization of engines for precalculation of default refit mask.
peter1138
parents: 2769
diff changeset
  2508
f250489941f9 (svn r3360) Fix initialization of engines for precalculation of default refit mask.
peter1138
parents: 2769
diff changeset
  2509
	// Add engine type to engine data. This is needed for the refit precalculation.
f250489941f9 (svn r3360) Fix initialization of engines for precalculation of default refit mask.
peter1138
parents: 2769
diff changeset
  2510
	AddTypeToEngines();
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
  2511
}
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
  2512
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
  2513
static void InitNewGRFFile(const char* filename, 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
  2514
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  2515
	GRFFile *newfile;
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  2516
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
  2517
	newfile = GetFileByFilename(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
  2518
	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
  2519
		/* 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
  2520
		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
  2521
		_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
  2522
		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
  2523
	}
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
  2524
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  2525
	newfile = calloc(1, sizeof(*newfile));
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  2526
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
  2527
	if (newfile == 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
  2528
		error ("Out of memory");
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
  2529
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
  2530
	newfile->filename = strdup(filename);
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
  2531
	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
  2532
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
  2533
	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
  2534
		_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
  2535
		_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
  2536
	} 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
  2537
		_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
  2538
		_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
  2539
	}
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
  2540
}
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
  2541
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2542
/**
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2543
 * 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
  2544
 */
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2545
static void CalculateRefitMasks(void)
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2546
{
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2547
	EngineID engine;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2548
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2549
	for (engine = 0; engine < TOTAL_NUM_ENGINES; engine++) {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2550
		uint32 mask = 0;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2551
		uint32 not_mask = 0;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2552
		uint32 xor_mask = _engine_info[engine].refit_mask;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2553
		byte i;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2554
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2555
		if (cargo_allowed[engine] != 0) {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2556
			// Build up the list of cargo types from the set cargo classes.
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2557
			for (i = 0; i < lengthof(cargo_classes); i++) {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2558
				if (HASBIT(cargo_allowed[engine], i))
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2559
					mask |= cargo_classes[i];
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2560
				if (HASBIT(cargo_disallowed[engine], i))
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2561
					not_mask |= cargo_classes[i];
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2562
			}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2563
		} else {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2564
			// Don't apply default refit mask to wagons or engines with no capacity
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2565
			if (xor_mask == 0 && !(GetEngine(engine)->type == VEH_Train && (RailVehInfo(engine)->capacity == 0 || RailVehInfo(engine)->flags & RVI_WAGON)))
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2566
				xor_mask = _default_refitmasks[GetEngine(engine)->type - VEH_Train];
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2567
		}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2568
		_engine_info[engine].refit_mask = ((mask & ~not_mask) ^ xor_mask) & _landscape_global_cargo_mask[_opt.landscape];
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2569
	}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2570
}
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
  2571
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2572
/* 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
  2573
 * 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
  2574
 * partial implementation yet). */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2575
/* 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
  2576
 * 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
  2577
 * better make this more robust in the future. */
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
  2578
static void DecodeSpecialSprite(const char* filename, uint num, uint stage)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2579
{
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  2580
	/* 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
  2581
	 * here.  In TTDPatch, for some reason actions 1 and 2 are carried out
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  2582
	 * during stage 0, whilst action 3 is carried out during stage 1 (to
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  2583
	 * "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
  2584
	 * 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
  2585
	 * 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
  2586
	 * in an earlier stage than associating, so...  We just process actions
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  2587
	 * 1 and 2 in stage 1 now, let's hope that won't get us into problems.
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  2588
	 * --pasky */
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
  2589
	uint32 action_mask = (stage == 0) ? 0x0001FF40 : 0x0001FFBF;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2590
	static const SpecialSpriteHandler handlers[] = {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2591
		/* 0x00 */ VehicleChangeInfo,
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2592
		/* 0x01 */ NewSpriteSet,
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2593
		/* 0x02 */ NewSpriteGroup,
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2594
		/* 0x03 */ NewVehicle_SpriteGroupMapping,
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2595
		/* 0x04 */ VehicleNewName,
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2596
		/* 0x05 */ GraphicsNew,
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2597
		/* 0x06 */ CfgApply,
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2598
		/* 0x07 */ SkipIf,
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2599
		/* 0x08 */ GRFInfo,
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2600
		/* 0x09 */ SkipIf,
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2601
		/* 0x0A */ SpriteReplace,
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2602
		/* 0x0B */ GRFError,
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2603
		/* 0x0C */ GRFComment,
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2604
		/* 0x0D */ ParamSet,
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2605
		/* 0x0E */ GRFInhibit,
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2606
		/* 0x0F */ NULL, // TODO implement
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2607
		/* 0x10 */ NULL  // TODO implement
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2608
	};
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2609
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
  2610
	byte* buf = malloc(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
  2611
	byte action;
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2612
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
  2613
	if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory");
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2614
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
  2615
	FioReadBlock(buf, 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
  2616
	action = buf[0];
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2617
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2618
	if (action >= lengthof(handlers)) {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2619
		DEBUG(grf, 7) ("Skipping unknown action 0x%02X", action);
2645
964bd8fe3ce2 (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents: 2628
diff changeset
  2620
	} else if (!HASBIT(action_mask, action)) {
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
  2621
		DEBUG(grf, 7) ("Skipping action 0x%02X in stage %d", action, stage);
2645
964bd8fe3ce2 (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents: 2628
diff changeset
  2622
	} else if (handlers[action] == NULL) {
964bd8fe3ce2 (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents: 2628
diff changeset
  2623
		DEBUG(grf, 7) ("Skipping unsupported Action 0x%02X", action);
964bd8fe3ce2 (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents: 2628
diff changeset
  2624
	} else {
964bd8fe3ce2 (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents: 2628
diff changeset
  2625
		DEBUG(grf, 7) ("Handling action 0x%02X in stage %d", action, stage);
964bd8fe3ce2 (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents: 2628
diff changeset
  2626
		handlers[action](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
  2627
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2628
	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
  2629
}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2630
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2631
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2632
static void LoadNewGRFFile(const char* filename, uint file_index, uint 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
  2633
{
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2634
	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
  2635
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2636
	/* 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
  2637
	 * 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
  2638
	 * 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
  2639
	 * 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
  2640
	 * 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
  2641
	 *
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2642
	 * 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
  2643
	 * 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
  2644
	 * processed once at initialization.  */
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2645
	if (stage != 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
  2646
		_cur_grffile = GetFileByFilename(filename);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2647
		if (_cur_grffile == NULL) error("File ``%s'' lost in cache.\n", 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
  2648
		if (!(_cur_grffile->flags & 0x0001)) return;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2649
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2650
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2651
	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
  2652
	_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
  2653
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2654
	DEBUG(grf, 7) ("Reading NewGRF-file '%s'", filename);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2655
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2656
	/* 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
  2657
	 * 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
  2658
	 * 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
  2659
	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
  2660
		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
  2661
	} 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
  2662
		error("Custom .grf has invalid format.");
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2663
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2664
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2665
	_skip_sprites = 0; // XXX
2849
73c752b82488 (svn r3397) - NewGRF fix: Show nfo sprite number instead of current sprite id for warning messages -- this makes this output more useful...
peter1138
parents: 2846
diff changeset
  2666
	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
  2667
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2668
	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
  2669
		byte type = FioReadByte();
2849
73c752b82488 (svn r3397) - NewGRF fix: Show nfo sprite number instead of current sprite id for warning messages -- this makes this output more useful...
peter1138
parents: 2846
diff changeset
  2670
		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
  2671
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2672
		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
  2673
			if (_skip_sprites == 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
  2674
				DecodeSpecialSprite(filename, num, 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
  2675
				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
  2676
			} 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
  2677
				FioSkipBytes(num);
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2678
			}
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2679
		} else {
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2680
			if (_skip_sprites == 0) DEBUG(grf, 7) ("Skipping unexpected sprite");
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2681
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2682
			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
  2683
			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
  2684
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2685
			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
  2686
				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
  2687
			} 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
  2688
				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
  2689
					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
  2690
					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
  2691
						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
  2692
						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
  2693
					} 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
  2694
						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
  2695
						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
  2696
						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
  2697
					}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2698
				}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2699
			}
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2700
		}
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
  2701
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2702
		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
  2703
	}
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2704
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2705
	// Release our sprite group references.
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2706
	// Any groups that are referenced elsewhere will be cleaned up later.
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2707
	// This removes groups that aren't used. (Perhaps skipped?)
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  2708
	ReleaseSpriteGroups(_cur_grffile);
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
  2709
}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2710
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2711
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2712
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
  2713
{
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2714
	uint 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
  2715
2930
a3bfaa5a9222 (svn r3486) - NewGRF fix: Always reinitialize the ttdpatch flags as patch settings may have changed.
peter1138
parents: 2895
diff changeset
  2716
	InitializeGRFSpecial();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2717
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
  2718
	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
  2719
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
  2720
	/* 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
  2721
	 * 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
  2722
	 * and load information from it. */
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2723
	_custom_sprites_base = load_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
  2724
	for (stage = 0; stage < 2; 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
  2725
		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
  2726
		uint j;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2727
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2728
		_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
  2729
		_cur_spriteid = load_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
  2730
		for (j = 0; j != lengthof(_newgrf_files) && _newgrf_files[j] != NULL; j++) {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2731
			if (!FiosCheckFileExists(_newgrf_files[j])) {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2732
				// TODO: usrerror()
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2733
				error("NewGRF file missing: %s", _newgrf_files[j]);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2734
			}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2735
			if (stage == 0) InitNewGRFFile(_newgrf_files[j], _cur_spriteid);
2400
0b51bc385750 (svn r2926) -Fix: Use the same file slots in both initialisation stages when loading a patch grf
tron
parents: 2346
diff changeset
  2736
			LoadNewGRFFile(_newgrf_files[j], slot++, 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
  2737
			DEBUG(spritecache, 2) ("Currently %i sprites are loaded", load_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
  2738
		}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2739
	}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2740
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2741
	// Pre-calculate all refit masks after loading GRF files
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  2742
	CalculateRefitMasks();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2743
}