newgrf.c
author tron
Sun, 14 Aug 2005 18:10:18 +0000
changeset 2340 0a9f3eeccb96
parent 2336 48ace1344af0
child 2342 c19fb4f2df30
permissions -rw-r--r--
(svn r2866) Move all functions and tables which aren't directly involved in managing the sprite heap to a new file gfxinit.c.
This doesn't ease the global variable mess, but makes the distinction between sprite heap and gfx loading routines easier.
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"
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    13
#include "station.h"
405
6830ae7a0d5d (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents: 404
diff changeset
    14
#include "sprite.h"
452
520e4ed6945d (svn r662) [newgrf] Moved grfspecial.c to newgrf.c/newgrf.h
dominik
parents: 449
diff changeset
    15
#include "newgrf.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2013
diff changeset
    16
#include "variables.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
/* TTDPatch extended GRF format codec
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
 * (c) Petr Baudis 2004 (GPL'd)
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
    20
 * 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
    21
 *
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
 * Contains portions of documentation by TTDPatch team.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
 * 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
    24
 * 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
    25
 * 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
    26
455
e7ac799e1437 (svn r665) code fixes for newgrf.c/newgrf.h
dominik
parents: 452
diff changeset
    27
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
extern int _skip_sprites;
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
    29
extern int _replace_sprites_count[16];
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
    30
extern int _replace_sprites_offset[16];
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
    31
extern int _traininfo_vehicle_pitch;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
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
    33
static GRFFile *_cur_grffile;
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    34
GRFFile *_first_grffile;
478
19987403ee5d (svn r745) Added newgrf GUI (in options menu)\nThe interface currently only displays the installed grf sets, you can't (de)activate them through the gui yet
dominik
parents: 455
diff changeset
    35
int _grffile_count;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
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
    37
static int _cur_stage;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
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
    39
static int32 _paramlist[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
    40
static int _param_max;
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
    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,
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
    52
	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
    53
	GSF_TOWNHOUSE,
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    54
} grfspec_feature;
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    55
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    56
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
typedef void (*SpecialSpriteHandler)(byte *buf, int len);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    59
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
    60
	/* GSF_TRAIN */    NUM_TRAIN_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    61
	/* GSF_ROAD */     NUM_ROAD_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    62
	/* GSF_SHIP */     NUM_SHIP_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    63
	/* GSF_AIRCRAFT */ NUM_AIRCRAFT_ENGINES
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    64
};
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    65
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
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
    67
	/* GSF_TRAIN */    0,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    68
	/* GSF_ROAD */     ROAD_ENGINES_INDEX,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    69
	/* GSF_SHIP */     SHIP_ENGINES_INDEX,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    70
	/* GSF_AIRCRAFT */ AIRCRAFT_ENGINES_INDEX,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    74
/* Debugging messages policy:
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    75
 *
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    76
 * 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
    77
 * (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
    78
 *
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    79
 * 0..2 - dedicated to grfmsg()
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    80
 * 3
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    81
 * 4
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    82
 * 5
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    83
 * 6 - action handler entry reporting - one per action
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    84
 * 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
    85
 * 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
    86
 * 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
    87
 */
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    88
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
    89
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    90
typedef enum grfmsg_severity {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
	GMS_NOTICE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
	GMS_WARN,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
	GMS_ERROR,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
	GMS_FATAL,
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    95
} grfmsg_severity;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    97
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
    98
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    99
	static const char* const severitystr[] = {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   100
		"Notice",
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   101
		"Warning",
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   102
		"Error",
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   103
		"Fatal"
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   104
	};
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   105
	int export_severity = 0;
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 51
diff changeset
   106
	char buf[1024];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
	va_start(va, str);
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   110
	vsnprintf(buf, sizeof(buf), str, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
	va_end(va);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   112
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   113
	export_severity = 2 - (severity == GMS_FATAL ? 2 : severity);
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   114
	DEBUG(grf, export_severity) ("[%s][%s] %s", _cur_grffile->filename, severitystr[severity], buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   117
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   118
#define check_length(real, wanted, where) \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   119
do { \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   120
	if (real < wanted) { \
1439
c4b08bda7a43 (svn r1943) Show the sprite ID in the check_length() error message. Also show the correct sprite ID in the spriteskip notice.
pasky
parents: 1329
diff changeset
   121
		grfmsg(GMS_ERROR, "%s/%d: Invalid special sprite length %d (expected %d)!", \
c4b08bda7a43 (svn r1943) Show the sprite ID in the check_length() error message. Also show the correct sprite ID in the spriteskip notice.
pasky
parents: 1329
diff changeset
   122
		       where, _cur_spriteid - _cur_grffile->sprite_offset, real, wanted); \
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   123
		return; \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   124
	} \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   125
} while (0)
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   126
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   127
500
ef288590e096 (svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents: 490
diff changeset
   128
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
   129
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	return *(*buf)++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
static uint16 grf_load_word(byte **buf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
	uint16 val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
	byte *p = *buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
	val = p[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
	val |= p[1] << 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
	*buf = p + 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
	return val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
2324
117bd73a0731 (svn r2850) [newgrf] Patch from peter1139
miham
parents: 2204
diff changeset
   143
static uint32 grf_load_dword(byte **buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
	uint32 val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
	byte *p = *buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
	val = p[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
	val |= p[1] << 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
	val |= p[2] << 16;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
	val |= p[3] << 24;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
	*buf = p + 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
	return val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   155
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   156
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
   157
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   158
	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
   159
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   160
	for (file = _first_grffile; file != NULL; file = file->next) {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   161
		if (file->grfid == grfid) break;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   162
	}
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
   163
	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
   164
}
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
   165
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   166
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
   167
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   168
	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
   169
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   170
	for (file = _first_grffile; file != NULL; file = file->next) {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   171
		if (strcmp(file->filename, filename) == 0) break;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   172
	}
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
   173
	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
   174
}
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
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
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   177
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
   178
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
   179
#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
   180
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
static void dewagonize(int condition, int engine)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	EngineInfo *ei = &_engine_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   186
	if (condition != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
		ei->unk2 &= ~0x80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
		rvi->flags &= ~2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
		ei->unk2 |= 0x80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
		rvi->flags |= 2;
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   195
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
   196
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
	EngineInfo *ei = &_engine_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
	byte *buf = *bufp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
	int i;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   201
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
	switch (prop) {
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   204
		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
   205
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
				uint8 tracktype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
				ei[i].railtype_climates &= 0xf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
				ei[i].railtype_climates |= tracktype << 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   211
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   212
		case 0x08: { /* AI passenger service */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
			/* 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
   214
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
				grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   217
			ret = true;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   218
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   219
		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
   220
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
				uint16 speed = grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
				rvi[i].max_speed = speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
				dewagonize(speed, engine + i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   226
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   227
		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
   228
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
				uint16 power = grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   231
				if (rvi[i].flags & RVI_MULTIHEAD)
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   232
					power /= 2;
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   233
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
				rvi[i].power = power;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
				dewagonize(power, engine + i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   237
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   238
		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
   239
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
				uint8 runcostfact = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
				rvi[i].running_cost_base = runcostfact;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
				dewagonize(runcostfact, engine + i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   245
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   246
		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
   247
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
				uint32 base = grf_load_dword(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
				switch (base) {
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   251
				case 0x4C30:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
					rvi[i].engclass = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
					break;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   254
				case 0x4C36:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
					rvi[i].engclass = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
					break;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   257
				case 0x4C3C:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
					rvi[i].engclass = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
				dewagonize(base, engine + i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   263
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   264
		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
   265
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   268
				if (spriteid == 0xFD && rvi[i].image_index != 0xFD)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
					_engine_original_sprites[engine + i] = rvi[i].image_index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
				rvi[i].image_index = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   272
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   273
		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
   274
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
				uint8 dual = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   277
				if (dual != 0) {
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   278
					if (!(rvi[i].flags & RVI_MULTIHEAD)) // adjust power if needed
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   279
						rvi[i].power /= 2;
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   280
					rvi[i].flags |= RVI_MULTIHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
				} else {
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   282
					if (rvi[i].flags & RVI_MULTIHEAD) // adjust power if needed
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   283
						rvi[i].power *= 2;
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   284
					rvi[i].flags &= ~RVI_MULTIHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   287
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   288
		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
   289
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
				uint8 capacity = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
				rvi[i].capacity = capacity;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   294
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   295
		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
   296
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
				uint8 ctype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
				rvi[i].cargo_type = ctype;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   301
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   302
		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
   303
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
				uint8 weight = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
				rvi[i].weight = weight;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   308
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   309
		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
   310
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
				uint8 cfactor = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
				rvi[i].base_cost = cfactor;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   315
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   316
		case 0x18: { /* AI rank */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
			/* 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
   318
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
				grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   321
			ret = true;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   322
		} break;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   323
		case 0x19: { /* Engine traction type */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
			/* TODO: What do the individual numbers mean?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
			 * XXX: And in what base are they, in fact? --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
   326
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
				uint8 traction = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
				int engclass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
				if (traction <= 0x07)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
					engclass = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
				else if (traction <= 0x27)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
					engclass = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
				else if (traction <= 0x31)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
					engclass = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
				else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
				rvi[i].engclass = engclass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   341
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   342
		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
   343
			FOR_EACH_OBJECT {
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   344
				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
   345
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   346
				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
   347
			}
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   348
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   349
		case 0x1D: { /* Refit cargo */
440
778ed2e8de1c (svn r649) Support for custom rail vehicle refit bitmasks. (pasky)
miham
parents: 439
diff changeset
   350
			FOR_EACH_OBJECT {
778ed2e8de1c (svn r649) Support for custom rail vehicle refit bitmasks. (pasky)
miham
parents: 439
diff changeset
   351
				uint32 refit_mask = grf_load_dword(&buf);
778ed2e8de1c (svn r649) Support for custom rail vehicle refit bitmasks. (pasky)
miham
parents: 439
diff changeset
   352
778ed2e8de1c (svn r649) Support for custom rail vehicle refit bitmasks. (pasky)
miham
parents: 439
diff changeset
   353
				_engine_refit_masks[engine + i] = refit_mask;
778ed2e8de1c (svn r649) Support for custom rail vehicle refit bitmasks. (pasky)
miham
parents: 439
diff changeset
   354
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   355
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   356
		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
   357
			FOR_EACH_OBJECT {
398f156479c8 (svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents: 1894
diff changeset
   358
				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
   359
1895
398f156479c8 (svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents: 1894
diff changeset
   360
				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
   361
			}
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   362
		} break;
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   363
		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
   364
			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
   365
				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
   366
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   367
				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
   368
			}
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   369
		} break;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   370
		case 0x22: { /* Visual effect */
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   371
			// 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
   372
			FOR_EACH_OBJECT {
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   373
				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
   374
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   375
				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
   376
			}
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   377
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   378
		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
   379
			FOR_EACH_OBJECT {
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   380
				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
   381
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   382
				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
   383
			}
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   384
		} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
		/* TODO */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
		/* 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
   387
		case 0x1A:	/* Sort order */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   388
		case 0x1C:	/* Refit cost */
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   389
		case 0x1F:	/* Tractive effort */
1871
1e74cb21d312 (svn r2377) - Fix: [newgrf] Ignore action 0 prop 0x20 (air drag)
orudge
parents: 1862
diff changeset
   390
		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
   391
		case 0x24:	/* High byte of vehicle weight */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   392
		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
   393
		case 0x26:	/* Retire vehicle early */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   394
			{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
			/* 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
   396
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
				grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   399
			ret = true;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   400
		}	break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
		default:
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   402
			ret = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   408
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
   409
{
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   410
	RoadVehicleInfo *rvi = &_road_vehicle_info[engine];
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   411
	byte *buf = *bufp;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   412
	int i;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   413
	bool ret = false;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   414
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   415
	switch (prop) {
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   416
		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
   417
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   418
				uint8 speed = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   419
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   420
				rvi[i].max_speed = speed; // ?? units
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   421
			}
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
   422
		} break;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   423
		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
   424
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   425
				uint8 runcost = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   426
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   427
				rvi[i].running_cost = runcost;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   428
			}
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
   429
		} break;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   430
		case 0x0A: { /* Running cost base */
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   431
			/* 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
   432
			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
   433
				grf_load_dword(&buf);
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   434
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   435
			ret = true;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   436
		} break;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   437
		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
   438
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   439
				uint8 spriteid = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   440
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   441
				if (spriteid == 0xFF)
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   442
					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
   443
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   444
				// This is currently not used but there's no reason
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   445
				// in not having it here for the future.
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   446
				if (spriteid == 0xFD && rvi[i].image_index != 0xFD)
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   447
					_engine_original_sprites[ROAD_ENGINES_INDEX + engine + i] = rvi[i].image_index;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   448
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   449
				rvi[i].image_index = spriteid;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   450
			}
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
   451
		} break;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   452
		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
   453
			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
   454
				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
   455
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   456
				rvi[i].capacity = capacity;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   457
			}
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
   458
		} break;
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   459
		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
   460
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   461
				uint8 cargo = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   462
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   463
				rvi[i].cargo_type = cargo;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   464
			}
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
   465
		} break;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   466
		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
   467
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   468
				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
   469
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   470
				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
   471
			}
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
   472
		} break;
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   473
		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
   474
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   475
				uint8 sfx = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   476
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   477
				rvi[i].sfx = sfx;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   478
			}
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
		} break;
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   480
		case 0x13:      /* Power in 10hp */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   481
		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
   482
		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
   483
			/* 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
   484
			 * 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
   485
			 * 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
   486
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   487
				grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   488
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   489
			ret = true;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   490
			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
   491
		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
   492
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   493
				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
   494
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   495
				_engine_refit_masks[ROAD_ENGINES_INDEX + engine + i] = refit_mask;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   496
			}
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
   497
		} break;
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   498
		case 0x17:      /* Callback */
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   499
		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
   500
		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
   501
		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
   502
		case 0x1B:      /* Retire vehicle early */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   503
			{
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   504
			/* 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
   505
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   506
				grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   507
			}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   508
			ret = true;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   509
			break;
1873
c8637fc2977b (svn r2379) - Fix: [newgrf] Note to self, check thoroughly before committing!
orudge
parents: 1872
diff changeset
   510
		}
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   511
		default:
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   512
			ret = true;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   513
	}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   514
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   515
	*bufp = buf;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   516
	return ret;
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
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   519
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
   520
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
	ShipVehicleInfo *svi = &_ship_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
	byte *buf = *bufp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
	int i;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   524
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
	//printf("e %x prop %x?\n", engine, prop);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
	switch (prop) {
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   528
		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
   529
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   532
				if (spriteid == 0xFF)
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   533
					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
   534
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
				// This is currently not used but there's no reason
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
				// in not having it here for the future.
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   537
				if (spriteid == 0xFD && svi[i].image_index != 0xFD)
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   538
					_engine_original_sprites[SHIP_ENGINES_INDEX + engine + i] = svi[i].image_index;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   539
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
				svi[i].image_index = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   542
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   543
		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
   544
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
				uint8 refittable = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
				svi[i].refittable = refittable;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   549
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   550
		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
   551
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
				uint8 cost_factor = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
				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
   555
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   556
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   557
		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
   558
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
				uint8 speed = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
				svi[i].max_speed = speed; // ?? units
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   563
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   564
		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
   565
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
				uint8 cargo = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
				// XXX: Need to consult this with patchman yet.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
#if 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
				// Documentation claims this is already the
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
				// per-landscape cargo type id, but newships.grf
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
				// assume otherwise.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
				cargo = local_cargo_id_ctype[cargo];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
				svi[i].cargo_type = cargo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   577
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   578
		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
   579
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
				uint16 capacity = grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
				svi[i].capacity = capacity;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   584
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   585
		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
   586
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
				uint8 runcost = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
				svi[i].running_cost = runcost;
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
		} break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   592
		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
   593
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
				uint8 sfx = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
				svi[i].sfx = sfx;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   598
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   599
		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
   600
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
				uint32 refit_mask = grf_load_dword(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
				_engine_refit_masks[SHIP_ENGINES_INDEX + engine + i] = refit_mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   605
		}	break;
1872
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   606
		case 0x12: /* Callback */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   607
		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
   608
		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
   609
		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
   610
		case 0x16: /* Retire vehicle early */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   611
		{
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   612
			/* TODO */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   613
			FOR_EACH_OBJECT {
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   614
				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
   615
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   616
			ret = true;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   617
		}	break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
		default:
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   619
			ret = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
	return ret;
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
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
   626
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
   627
{
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
   628
	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
   629
	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
   630
	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
   631
	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
   632
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
   633
	//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
   634
	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
   635
		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
   636
			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
   637
				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
   638
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
   639
				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
   640
					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
   641
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
   642
				// This is currently not used but there's no reason
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
   643
				// in not having it here for the future.
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
   644
				if (spriteid == 0xFD && avi[i].image_index != 0xFD)
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
   645
					_engine_original_sprites[AIRCRAFT_ENGINES_INDEX + engine + i] = avi[i].image_index;
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
   646
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
   647
				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
   648
			}
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
   649
		}	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
   650
		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
   651
			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
   652
				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
   653
				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
   654
				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
   655
			}
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
   656
		}	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
   657
		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
   658
			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
   659
				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
   660
				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
   661
				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
   662
			}
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
   663
		}	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
   664
		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
   665
			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
   666
				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
   667
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
   668
				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
   669
			}
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
   670
		}	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
   671
		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
   672
			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
   673
				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
   674
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
   675
				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
   676
			}
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
   677
		}	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
   678
		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
   679
			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
   680
				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
   681
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
   682
				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
   683
			}
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
   684
		} 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
   685
		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
   686
			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
   687
				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
   688
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
   689
				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
   690
			}
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
   691
		} 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
   692
		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
   693
			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
   694
				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
   695
922
fc040662bd43 (svn r1410) Replaced all occurences of 'passanger' by 'passenger' in the code
celestar
parents: 542
diff changeset
   696
				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
   697
			}
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
		}	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
   699
		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
   700
			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
   701
				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
   702
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
				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
   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
		}	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
   706
		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
   707
			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
   708
				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
   709
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
				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
   711
			}
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
		}	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
   713
		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
   714
			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
   715
				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
   716
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
				_engine_refit_masks[AIRCRAFT_ENGINES_INDEX + engine + i] = refit_mask;
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;
1872
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   720
		case 0x14: /* Callback */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   721
		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
   722
		case 0x16: /* Retire vehicle early */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   723
		{
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   724
			/* TODO */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   725
			FOR_EACH_OBJECT {
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   726
				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
   727
			}
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
   728
			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
   729
		}	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
   730
		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
   731
			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
   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
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
	*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
   735
	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
   736
}
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
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   738
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
   739
{
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   740
	byte *buf = *bufp;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   741
	int i;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   742
	int ret = 0;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   743
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   744
	/* 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
   745
	 * just waypoints for now. */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   746
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   747
	//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
   748
	switch (prop) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   749
		case 0x08:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   750
		{	/* 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
   751
			FOR_EACH_OBJECT {
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   752
				StationSpec *stat = &_cur_grffile->stations[stid + i];
438
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   753
				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
   754
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   755
				/* classid, for a change, is always little-endian */
438
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   756
				classid = *(buf++) << 24;
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   757
				classid |= *(buf++) << 16;
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   758
				classid |= *(buf++) << 8;
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   759
				classid |= *(buf++);
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   760
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   761
				switch (classid) {
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   762
					case 'DFLT':
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   763
						stat->sclass = STAT_CLASS_DFLT;
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   764
						break;
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   765
					case 'WAYP':
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   766
						stat->sclass = STAT_CLASS_WAYP;
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   767
						break;
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   768
					default:
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   769
						/* TODO: No support for custom
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   770
						 * classes for now, so stuff
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   771
						 * everything to the single
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   772
						 * default one. --pasky */
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   773
						stat->sclass = STAT_CLASS_DFLT;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   774
						//stat->sclass = STAT_CLASS_CUSTOM;
438
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   775
						break;
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
   776
				}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   777
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   778
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   779
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   780
		case 0x09:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   781
		{	/* 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
   782
			FOR_EACH_OBJECT {
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   783
				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
   784
				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
   785
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
   786
				stat->tiles = grf_load_byte(&buf);
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
   787
				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
   788
					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
   789
					int seq_count = 0;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   790
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   791
					if (t >= 8) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   792
						grfmsg(GMS_WARN, "StationChangeInfo: Sprite %d>=8, skipping.", t);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   793
						grf_load_dword(&buf); // at least something
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   794
						continue;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   795
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   796
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   797
					dts->ground_sprite = grf_load_dword(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   798
					if (!dts->ground_sprite) {
536
aef4753985d3 (svn r907) Sprinkle holy ANSI water:
tron
parents: 500
diff changeset
   799
						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
   800
						dts->seq = &empty;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   801
						continue;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   802
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   803
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   804
					dts->seq = NULL;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   805
					while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   806
						DrawTileSeqStruct *dtss;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   807
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   808
						// 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
   809
						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
   810
						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
   811
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   812
						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
   813
						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
   814
						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
   815
						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
   816
						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
   817
						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
   818
						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
   819
						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
   820
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   821
				}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   822
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   823
			break;
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
		case 0x0a:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   826
		{	/* 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
   827
			FOR_EACH_OBJECT {
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   828
				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
   829
				byte srcid = grf_load_byte(&buf);
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   830
				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
   831
				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
   832
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
   833
				stat->tiles = srcstat->tiles;
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
   834
				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
   835
					DrawTileSprites *dts = &stat->renderdata[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
   836
					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
   837
					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
   838
					int seq_count = 0;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   839
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   840
					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
   841
					if (!dts->ground_sprite) {
536
aef4753985d3 (svn r907) Sprinkle holy ANSI water:
tron
parents: 500
diff changeset
   842
						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
   843
						dts->seq = &empty;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   844
						continue;
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
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   847
					dts->seq = NULL;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   848
					while (1) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   849
						DrawTileSeqStruct *dtss;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   850
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   851
						// 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
   852
						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
   853
						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
   854
						*dtss = *sdtss;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   855
						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
   856
						sdtss++;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   857
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   858
				}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   859
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   860
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   861
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   862
		case 0x0b:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   863
		{	/* Callback */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   864
			/* 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
   865
			FOR_EACH_OBJECT {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   866
				grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   867
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   868
			ret = 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   869
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   870
		}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   871
		case 0x0C:
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   872
		{	/* 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
   873
			FOR_EACH_OBJECT {
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   874
				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
   875
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   876
				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
   877
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   878
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   879
		}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   880
		case 0x0D:
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   881
		{	/* 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
   882
			FOR_EACH_OBJECT {
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   883
				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
   884
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   885
				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
   886
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   887
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   888
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   889
		case 0x0e:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   890
		{	/* 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
   891
			FOR_EACH_OBJECT {
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   892
				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
   893
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   894
				while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   895
					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
   896
					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
   897
					StationLayout layout;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   898
					int l, p;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   899
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   900
					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
   901
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   902
					//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
   903
					if (length > stat->lengths) {
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   904
						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
   905
						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
   906
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   907
						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
   908
						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
   909
						       (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
   910
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   911
						stat->lengths = length;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   912
					}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   913
					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
   914
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   915
					//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
   916
					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
   917
						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
   918
						                               number * sizeof(**stat->layouts));
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   919
						// 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
   920
						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
   921
						       (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
   922
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   923
						stat->platforms[l] = number;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   924
					}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   925
542
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
   926
					p = 0;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   927
					layout = malloc(length * number);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   928
					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
   929
						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
   930
							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
   931
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   932
					l--;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   933
					p--;
542
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
   934
					assert(p >= 0);
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   935
					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
   936
					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
   937
				}
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
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   940
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   941
		case 0x0f:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   942
		{	/* Copy custom layout */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   943
			/* 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
   944
			FOR_EACH_OBJECT {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   945
				grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   946
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   947
			ret = 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   948
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   949
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   950
		case 0x10:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   951
		{	/* Little/lots cargo threshold */
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   952
			/* 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
   953
			FOR_EACH_OBJECT {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   954
				grf_load_word(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   955
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   956
			ret = 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   957
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   958
		}
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
   959
		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
   960
		{	/* 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
   961
			/* 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
   962
			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
   963
				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
   964
			}
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
   965
			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
   966
			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
   967
		}
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
   968
		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
   969
		{	/* 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
   970
			/* 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
   971
			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
   972
				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
   973
			}
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
   974
			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
   975
			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
   976
		}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   977
		default:
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   978
			ret = 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   979
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   980
	}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   981
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   982
	*bufp = buf;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   983
	return ret;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   984
}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   985
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   986
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   987
/* Action 0x00 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
static void VehicleChangeInfo(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
	byte *bufend = buf + len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
	/* <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
   994
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
	 * 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
   996
	 *                 4 for defining new train station sets
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
	 * 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
   998
	 * B num-info      how many vehicles/stations to change
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
	 * 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
  1000
	 *                 greater than one, this one and the following
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
	 *                 vehicles/stations will be changed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
	 * 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
  1003
	 * 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
  1004
	/* TODO: Bridges, town houses. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1006
	static const VCI_Handler handler[7] = {
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
  1007
		/* GSF_TRAIN */    RailVehicleChangeInfo,
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
  1008
		/* GSF_ROAD */     RoadVehicleChangeInfo,
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
  1009
		/* 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
  1010
		/* GSF_AIRCRAFT */ AircraftVehicleChangeInfo,
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1011
		/* GSF_STATION */  StationChangeInfo,
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1012
		/* GSF_BRIDGE */   NULL,
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1013
		/* GSF_TOWNHOUSE */NULL,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
	};
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1015
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1016
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1017
	uint8 numprops;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1018
	uint8 numinfo;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1019
	byte engine;
542
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
  1020
	EngineInfo *ei = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
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
  1022
	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
  1023
		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
  1024
		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
  1025
	}
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
  1026
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1027
	check_length(len, 6, "VehicleChangeInfo");
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1028
	feature = buf[1];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1029
	numprops = buf[2];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1030
	numinfo = buf[3];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1031
	engine = buf[4];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  1032
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
  1033
	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
  1034
	               feature, numprops, engine, numinfo);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
  1035
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1036
	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
  1037
		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
  1038
		return;
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1039
	}
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1040
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1041
	if (feature != GSF_STATION)
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1042
		ei = &_engine_info[engine + _vehshifts[feature]];
542
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
  1043
	/* XXX - Should there not be a check to see if 'ei' is NULL
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
  1044
	    when it is used in the switch below?? -- TrueLight */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1045
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1046
	buf += 5;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1047
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1048
	while (numprops-- && buf < bufend) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1049
		uint8 prop = grf_load_byte(&buf);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1050
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
  1051
		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
  1052
			// stations don't share those common properties
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1053
			goto run_handler;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1054
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1055
		switch (prop) {
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1056
		case 0x00: { /* Introduction date */
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
  1057
			FOR_EACH_OBJECT {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1058
				uint16 date = grf_load_word(&buf);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1059
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1060
				ei[i].base_intro = date;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1062
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1063
		case 0x02: { /* Decay 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
  1064
			FOR_EACH_OBJECT {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1065
				uint8 decay = grf_load_byte(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1067
				ei[i].unk2 &= 0x80;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1068
				ei[i].unk2 |= decay & 0x7f;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1070
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1071
		case 0x03: { /* Vehicle life */
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
  1072
			FOR_EACH_OBJECT {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1073
				uint8 life = grf_load_byte(&buf);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1074
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1075
				ei[i].lifelength = life;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1077
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1078
		case 0x04: { /* Model life */
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
  1079
			FOR_EACH_OBJECT {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1080
				uint8 life = grf_load_byte(&buf);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1081
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1082
				ei[i].base_life = life;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1083
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1084
		}	break;
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1085
		case 0x06: { /* Climates available */
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
  1086
			FOR_EACH_OBJECT {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1087
				uint8 climates = grf_load_byte(&buf);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1088
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1089
				ei[i].railtype_climates &= 0xf0;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1090
				ei[i].railtype_climates |= climates;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1091
			}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1092
		}	break;
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
  1093
		case 0x07: { /* Loading speed */
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1094
			/* TODO */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1095
			/* Hyronymus explained me what does
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1096
			 * this mean and insists on having a
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1097
			 * credit ;-). --pasky */
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1098
			/* TODO: This needs to be supported by
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1099
			 * LoadUnloadVehicle() first. */
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
  1100
			FOR_EACH_OBJECT {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1101
				grf_load_byte(&buf);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1102
			}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1103
			goto ignoring;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1104
		}
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1105
		default: {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1106
run_handler:
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1107
			if (handler[feature](engine, numinfo, prop, &buf, bufend - buf)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
ignoring:
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1109
				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
  1110
			}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1111
			break;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1112
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
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
  1117
#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
  1118
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1119
/**
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1120
 * Creates a spritegroup representing a callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1121
 * @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
  1122
 * @return A spritegroup representing that callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1123
 */
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1124
SpriteGroup NewCallBackResult(uint16 value)
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1125
{
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1126
	SpriteGroup group;
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1127
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1128
	group.type = SGT_CALLBACK;
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1129
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1130
	// 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
  1131
	// 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
  1132
	if ((value >> 8) == 0xFF)
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1133
		value &= 0xFF;
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1134
	else
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1135
		value &= ~0x8000;
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1136
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1137
	group.g.callback.result = value;
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1138
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1139
	return group;
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1140
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1142
/* 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
  1143
static void NewSpriteSet(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
	/* <01> <feature> <num-sets> <num-ent>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
	 * B feature       feature to define sprites for
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
	 *                 0, 1, 2, 3: veh-type, 4: train stations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
	 * B num-sets      number of sprite sets
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
	 * B num-ent       how many entries per sprite set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
	 *                 For vehicles, this is the number of different
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
	 *                         vehicle directions in each sprite set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
	 *                         Set num-dirs=8, unless your sprites are symmetric.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
	 *                         In that case, use num-dirs=4.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
	 *                 For stations, must be 12 (hex) for the eighteen
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
	 *                         different sprites that make up a station */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
	/* TODO: No stations support. */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1158
	uint8 feature;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1160
	check_length(len, 4, "NewSpriteSet");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1161
	feature = buf[1];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1163
	_cur_grffile->spriteset_start = _cur_spriteid + 1;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1164
	_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
  1165
	_cur_grffile->spriteset_numsets = buf[2];
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1166
	_cur_grffile->spriteset_numents = buf[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1169
/* 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
  1170
static void NewSpriteGroup(byte *buf, int len)
0
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
	byte *bufend = buf + len;
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
	/* <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
  1175
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
	 * B feature       see action 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
	 * B set-id        ID of this particular definition
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
	 * B type/num-entries
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
	 *                 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
  1180
	 *                 list definition, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
	 *                 otherwise it specifies a number of entries, the exact
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
	 *                 meaning depends on the feature
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
	 * 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
  1184
	/* TODO: No 0x80-types (ugh). */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
	/* 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
  1186
	 * 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
  1187
	 * when. --pasky */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1188
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1189
	uint8 setid;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1190
	/* 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
  1191
	uint8 numloaded;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1192
	uint8 numloading;
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1193
	SpriteGroup *group;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1194
	RealSpriteGroup *rg;
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1195
	byte *loaded_ptr;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1196
	byte *loading_ptr;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1197
	int i;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  1198
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1199
	check_length(len, 5, "NewSpriteGroup");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1200
	feature = buf[1];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1201
	setid = buf[2];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1202
	numloaded = buf[3];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1203
	numloading = buf[4];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1204
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
  1205
	if (numloaded == 0x81 || numloaded == 0x82) {
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1206
		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
  1207
		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
  1208
		int i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
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
  1210
		// 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
  1211
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
  1212
		/* 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
  1213
		 * 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
  1214
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
  1215
		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
  1216
		check_length(len, 6, "NewSpriteGroup 0x81/0x82");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1217
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1218
		if (setid >= _cur_grffile->spritegroups_count) {
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1219
			_cur_grffile->spritegroups_count = setid + 1;
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1220
			_cur_grffile->spritegroups = realloc(_cur_grffile->spritegroups, _cur_grffile->spritegroups_count * sizeof(*_cur_grffile->spritegroups));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
		}
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
  1222
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
  1223
		group = &_cur_grffile->spritegroups[setid];
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1224
		memset(group, 0, 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
  1225
		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
  1226
		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
  1227
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
  1228
		/* 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
  1229
		 * 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
  1230
		 * 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
  1231
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
  1232
		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
  1233
		dg->variable = 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
  1234
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
  1235
		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
  1236
		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
  1237
		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
  1238
		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
  1239
		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
  1240
			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
  1241
			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
  1242
		}
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
  1243
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1244
		/* (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
  1245
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
  1246
		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
  1247
		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
  1248
		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
  1249
			groupid = grf_load_word(&buf);
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1250
			if (groupid & 0x8000) {
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1251
				dg->ranges[i].group = NewCallBackResult(groupid);
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1252
			} else if (groupid >= _cur_grffile->spritegroups_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
  1253
				/* This doesn't exist for us. */
441
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  1254
				grf_load_word(&buf); // skip range
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
  1255
				i--; dg->num_ranges--;
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
  1256
				continue;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1257
			} else {
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
  1258
			/* XXX: If multiple surreal sets attach a surreal
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
  1259
			 * set this way, we are in trouble. */
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1260
				dg->ranges[i].group = _cur_grffile->spritegroups[groupid];
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1261
			}
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1262
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
  1263
			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
  1264
			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
  1265
		}
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
  1266
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
  1267
		groupid = grf_load_word(&buf);
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1268
		if (groupid & 0x8000) {
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1269
			dg->default_group = malloc(sizeof(*dg->default_group));
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1270
			*dg->default_group = NewCallBackResult(groupid);
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1271
		} else if (groupid >= _cur_grffile->spritegroups_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
  1272
			/* This spritegroup stinks. */
441
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  1273
			free(dg->ranges), dg->ranges = NULL;
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
  1274
			grfmsg(GMS_WARN, "NewSpriteGroup(%02x:0x%x): Default groupid %04x is cargo callback or unknown, ignoring spritegroup.", setid, numloaded, groupid);
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
  1275
			return;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1276
		} else {
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1277
			dg->default_group = malloc(sizeof(*dg->default_group));
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1278
			memcpy(dg->default_group, &_cur_grffile->spritegroups[groupid], sizeof(*dg->default_group));
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
  1279
		}
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
  1280
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1281
		return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
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
  1283
	} else if (numloaded == 0x80 || numloaded == 0x83) {
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1284
		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
  1285
		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
  1286
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
  1287
		/* 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
  1288
		 * 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
  1289
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
  1290
		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
  1291
		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
  1292
		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
  1293
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
  1294
		if (setid >= _cur_grffile->spritegroups_count) {
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
  1295
			_cur_grffile->spritegroups_count = setid + 1;
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1296
			_cur_grffile->spritegroups = realloc(_cur_grffile->spritegroups, _cur_grffile->spritegroups_count * sizeof(*_cur_grffile->spritegroups));
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
  1297
		}
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
  1298
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
  1299
		group = &_cur_grffile->spritegroups[setid];
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
  1300
		memset(group, 0, sizeof(*group));
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
  1301
		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
  1302
		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
  1303
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
  1304
		/* 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
  1305
		 * 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
  1306
		 * 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
  1307
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
  1308
		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
  1309
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
  1310
		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
  1311
		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
  1312
		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
  1313
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
  1314
		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
  1315
		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
  1316
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
  1317
		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
  1318
		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
  1319
			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
  1320
5aa84112454c (svn r658) Ignore callbackish randomized spritegroups - they would just crash us (pasky)
tron
parents: 445
diff changeset
  1321
			if (groupid & 0x8000 || groupid >= _cur_grffile->spritegroups_count) {
5aa84112454c (svn r658) Ignore callbackish randomized spritegroups - they would just crash us (pasky)
tron
parents: 445
diff changeset
  1322
				/* This doesn't exist for us. */
5aa84112454c (svn r658) Ignore callbackish randomized spritegroups - they would just crash us (pasky)
tron
parents: 445
diff changeset
  1323
				i--;
5aa84112454c (svn r658) Ignore callbackish randomized spritegroups - they would just crash us (pasky)
tron
parents: 445
diff changeset
  1324
				rg->num_groups--;
5aa84112454c (svn r658) Ignore callbackish randomized spritegroups - they would just crash us (pasky)
tron
parents: 445
diff changeset
  1325
				continue;
5aa84112454c (svn r658) Ignore callbackish randomized spritegroups - they would just crash us (pasky)
tron
parents: 445
diff changeset
  1326
			}
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
  1327
			/* XXX: If multiple surreal sets attach a surreal
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
  1328
			 * set this way, we are in trouble. */
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
  1329
			rg->groups[i] = _cur_grffile->spritegroups[groupid];
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
  1330
		}
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
  1331
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1332
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1333
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1334
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1335
	if (!_cur_grffile->spriteset_start) {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1336
		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
  1337
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1338
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1339
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1340
	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
  1341
		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
  1342
		// 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
  1343
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1344
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1345
	check_length(bufend - buf, 5, "NewSpriteGroup");
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1346
	buf += 5;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1347
	check_length(bufend - buf, 2 * numloaded, "NewSpriteGroup");
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1348
	loaded_ptr = buf;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1349
	loading_ptr = buf + 2 * numloaded;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1350
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1351
	if (numloaded > 16) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1352
		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
  1353
		numloaded = 16;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1354
	}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1355
	if (numloading > 16) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1356
		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
  1357
		numloading = 16;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1358
	}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1359
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1360
	if (setid >= _cur_grffile->spritegroups_count) {
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1361
		_cur_grffile->spritegroups_count = setid + 1;
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1362
		_cur_grffile->spritegroups = realloc(_cur_grffile->spritegroups, _cur_grffile->spritegroups_count * sizeof(*_cur_grffile->spritegroups));
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1363
	}
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1364
	group = &_cur_grffile->spritegroups[setid];
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1365
	memset(group, 0, 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
  1366
	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
  1367
	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
  1368
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
  1369
	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
  1370
	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
  1371
	rg->loading_count = numloading;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1372
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1373
	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
  1374
			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
  1375
			_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
  1376
			_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
  1377
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1378
	for (i = 0; i < numloaded; i++) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1379
		uint16 spriteset_id = grf_load_word(&loaded_ptr);
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
  1380
		rg->loaded[i] = _cur_grffile->spriteset_start + spriteset_id * _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
  1381
		DEBUG(grf, 8) ("NewSpriteGroup: + rg->loaded[%i]  = %u (subset %u)", i, rg->loaded[i], spriteset_id);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1382
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1383
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1384
	for (i = 0; i < numloading; i++) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1385
		uint16 spriteset_id = grf_load_word(&loading_ptr);
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
  1386
		rg->loading[i] = _cur_grffile->spriteset_start + spriteset_id * _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
  1387
		DEBUG(grf, 8) ("NewSpriteGroup: + rg->loading[%i] = %u (subset %u)", i, rg->loading[i], spriteset_id);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1391
/* 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
  1392
static void NewVehicle_SpriteGroupMapping(byte *buf, int len)
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
	/* <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
  1395
	 * id-list	:= [<id>] [id-list]
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1396
	 * cargo-list	:= <cargo-type> <cid> [cargo-list]
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
	 * B feature       see action 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
	 * 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
  1400
	 *                 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
  1401
	 * 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
  1402
	 * 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
  1403
	 *                 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
  1404
	 * 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
  1405
	 * 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
  1406
	 * 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
  1407
	/* TODO: Bridges, town houses. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
	/* 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
  1409
	 * 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
  1410
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1411
	static byte *last_engines;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1412
	static int last_engines_count;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1413
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1414
	uint8 idcount;
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1415
	bool wagover;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1416
	uint8 cidcount;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1417
	int c, i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1419
	check_length(len, 7, "VehicleMapSpriteGroup");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1420
	feature = buf[1];
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1421
	idcount = buf[2] & 0x7F;
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1422
	wagover = (buf[2] & 0x80) == 0x80;
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1423
	check_length(len, 3 + idcount, "VehicleMapSpriteGroup");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1424
	cidcount = buf[3 + idcount];
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1425
	check_length(len, 4 + idcount + cidcount * 3, "VehicleMapSpriteGroup");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1426
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1427
	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
  1428
			feature, idcount, cidcount, wagover);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1429
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1430
	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
  1431
		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
  1432
		return;
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1433
	}
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1434
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1435
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
  1436
	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
  1437
		// 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
  1438
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
  1439
		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
  1440
			uint8 stid = buf[3 + i];
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1441
			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
  1442
			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
  1443
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
  1444
			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
  1445
				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
  1446
				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
  1447
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
  1448
				if (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
  1449
					grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x, skipping.",
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
  1450
					       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
  1451
					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
  1452
				}
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
  1453
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
  1454
				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
  1455
					/* 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
  1456
					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
  1457
				}
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
  1458
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
  1459
				stat->spritegroup[1] = _cur_grffile->spritegroups[groupid];
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
  1460
			}
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
  1461
		}
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
  1462
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
  1463
		{
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
  1464
			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
  1465
			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
  1466
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1467
			if (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
  1468
				grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x, skipping.",
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1469
				       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
  1470
				return;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1471
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1472
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
  1473
			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
  1474
				uint8 stid = buf[3 + i];
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  1475
				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
  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
				stat->spritegroup[0] = _cur_grffile->spritegroups[groupid];
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
  1478
				stat->grfid = _cur_grffile->grfid;
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
  1479
				SetCustomStation(stid, stat);
438
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 420
diff changeset
  1480
				stat->sclass = STAT_CLASS_NONE;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1481
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1482
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1483
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1484
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1485
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1486
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1487
	/* 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
  1488
	 * 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
  1489
	 * now.  --octo */
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1490
	if (idcount == 0) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1491
		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
  1492
		return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1493
	}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1494
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1495
	// FIXME: Tropicset contains things like:
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1496
	// 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
  1497
	// what should we exactly do with that? --pasky
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1498
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1499
	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
  1500
		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
  1501
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1502
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1503
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1504
	if (!wagover && last_engines_count != idcount) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1505
		last_engines = realloc(last_engines, idcount);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1506
		last_engines_count = idcount;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1507
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1508
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1509
	if (wagover) {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1510
		if (last_engines_count == 0) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1511
			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
  1512
			return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1513
		}
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1514
		DEBUG(grf, 6) ("VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons.",
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1515
				last_engines_count, idcount);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1516
	}
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
  1517
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1518
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1519
	for (i = 0; i < idcount; i++) {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1520
		uint8 engine_id = buf[3 + i];
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1521
		uint8 engine = engine_id + _vehshifts[feature];
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1522
		byte *bp = &buf[4 + idcount];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1523
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1524
		if (engine_id > _vehcounts[feature]) {
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1525
			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
  1526
					engine_id, feature);
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1527
			return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1528
		}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1529
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1530
		DEBUG(grf, 7) ("VehicleMapSpriteGroup: [%d] Engine %d...", i, engine);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1531
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1532
		for (c = 0; c < cidcount; c++) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1533
			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
  1534
			uint16 groupid = grf_load_word(&bp);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1535
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1536
			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
  1537
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1538
			if (groupid >= _cur_grffile->spritegroups_count) {
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1539
				grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x, skipping.", groupid, _cur_grffile->spritegroups_count);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1540
				return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1541
			}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1542
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
  1543
			if (ctype == GC_INVALID) ctype = GC_PURCHASE;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1544
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1545
			if (wagover) {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1546
				// TODO: No multiple cargo types per vehicle yet. --pasky
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1547
				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
  1548
			} else {
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1549
				SetCustomEngineSprites(engine, ctype, &_cur_grffile->spritegroups[groupid]);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1550
				last_engines[i] = engine;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1551
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1553
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1554
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1555
	{
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1556
		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
  1557
		uint16 groupid = grf_load_word(&bp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1558
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1559
		DEBUG(grf, 8) ("-- Default group id %x", groupid);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1560
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1561
		for (i = 0; i < idcount; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1562
			uint8 engine = buf[3 + i] + _vehshifts[feature];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1564
			// Don't tell me you don't love duplicated code!
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1565
			if (groupid >= _cur_grffile->spritegroups_count) {
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1566
				grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x, skipping.", groupid, _cur_grffile->spritegroups_count);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1567
				return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1568
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1570
			if (wagover) {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1571
				// TODO: No multiple cargo types per vehicle yet. --pasky
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1572
				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
  1573
			} else {
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
  1574
				SetCustomEngineSprites(engine, GC_DEFAULT, &_cur_grffile->spritegroups[groupid]);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1575
				last_engines[i] = engine;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1576
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1578
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1579
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1580
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1581
/* Action 0x04 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1582
static void VehicleNewName(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1583
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1584
	/* <04> <veh-type> <language-id> <num-veh> <offset> <data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1585
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1586
	 * B veh-type      see action 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1587
	 * 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
  1588
	 * B num-veh       number of vehicles which are getting a new name
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1589
	 * B offset        number of the first vehicle that gets a new name
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1590
	 * 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
  1591
	 *                 which the next name begins. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1592
	/* 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
  1593
	 * 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
  1594
	 * (completely new scenarios changing all graphics and logically also
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1595
	 * 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
  1596
	 * 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
  1597
	/* TODO: Support for custom station class/type names. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1598
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1599
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1600
	uint8 lang;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1601
	uint8 id;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1602
	uint8 endid;
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  1603
	const char* name;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1604
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1605
	check_length(len, 6, "VehicleNewName");
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1606
	feature = buf[1];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1607
	lang = buf[2];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1608
	id = buf[4] + _vehshifts[feature];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1609
	endid = id + buf[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1610
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1611
	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
  1612
	               id, endid, feature, lang);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1613
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1614
	if (lang & 0x80) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1615
		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
  1616
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1617
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1618
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1619
	if (!(lang & 3)) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1620
		/* XXX: If non-English name, silently skip it. */
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1621
		DEBUG(grf, 7) ("VehicleNewName: Skipping non-English name.");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1622
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1623
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1624
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  1625
	name = (const char*)(buf + 5);
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  1626
	len -= 5;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1627
	for (; id < endid && len > 0; id++) {
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  1628
		int ofs = strlen(name) + 1;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1629
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1630
		if (ofs < 128) {
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  1631
			DEBUG(grf, 8) ("VehicleNewName: %d <- %s", id, name);
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  1632
			SetCustomEngineName(id, name);
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1633
		} else {
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1634
			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
  1635
		}
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  1636
		name += ofs;
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  1637
		len -= ofs;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1638
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1639
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1641
/* Action 0x05 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1642
static void GraphicsNew(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1643
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
	/* <05> <graphics-type> <num-sprites> <other data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1646
	 * B graphics-type What set of graphics the sprites define.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1647
	 * 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
  1648
	 * V other data    Graphics type specific data.  Currently unused. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1649
	/* TODO */
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1650
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1651
	uint8 type;
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1652
	uint8 num;
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1653
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1654
	check_length(len, 2, "GraphicsNew");
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1655
	type = buf[0];
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1656
	num = buf[1];
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1657
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1658
	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
  1659
	       type, num);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1660
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1661
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1662
/* Action 0x06 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1663
static void CfgApply(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1664
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1665
	/* <06> <param-num> <param-size> <offset> ... <FF>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1666
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1667
	 * 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
  1668
	 *                 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
  1669
	 * 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
  1670
	 *                 bytes of the following parameter are used.  In that
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1671
	 *                 case, nothing is applied unless *all* parameters
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1672
	 *                 were specified.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1673
	 * 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
  1674
	 *                 to place where parameter is to be stored. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1675
	/* TODO */
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1676
	grfmsg(GMS_NOTICE, "CfgApply: Ignoring (not implemented).\n");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1677
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1678
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1679
/* Action 0x07 */
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1680
/* Action 0x09 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1681
static void SkipIf(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1682
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1683
	/* <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
  1684
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1685
	 * B param-num
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1686
	 * B param-size
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1687
	 * B condition-type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1688
	 * V value
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1689
	 * B num-sprites */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1690
	/* TODO: More params. More condition types. */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1691
	uint8 param;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1692
	uint8 paramsize;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1693
	uint8 condtype;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1694
	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
  1695
	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
  1696
	uint32 cond_val = 0;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1697
	bool result;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1698
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1699
	check_length(len, 6, "SkipIf");
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1700
	param = buf[1];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1701
	paramsize = buf[2];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1702
	condtype = buf[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1703
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
  1704
	if (condtype < 2) {
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  1705
		/* 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
  1706
		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
  1707
	}
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
  1708
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
  1709
	buf += 4;
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  1710
	switch (paramsize) {
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  1711
		case 4: cond_val = grf_load_dword(&buf); break;
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  1712
		case 2: cond_val = grf_load_word(&buf);  break;
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  1713
		case 1: cond_val = grf_load_byte(&buf);  break;
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  1714
		default: break;
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  1715
	}
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
  1716
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
  1717
	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
  1718
		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
  1719
			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
  1720
			break;
401
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  1721
		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
  1722
			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
  1723
			break;
401
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  1724
		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
  1725
			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
  1726
			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
  1727
			break;
401
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  1728
		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
  1729
			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
  1730
			break;
401
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  1731
		case 0x88: {  /* see if specified GRFID is active */
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  1732
			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
  1733
		}	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
  1734
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
  1735
		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
  1736
			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
  1737
			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
  1738
			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
  1739
			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
  1740
			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
  1741
			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
  1742
		}
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
  1743
401
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  1744
		case 0x8D:    /* TTD Version, 00=DOS, 01=Windows */
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  1745
			param_val = 1;
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  1746
			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
  1747
		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
  1748
			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
  1749
			break;
401
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  1750
		/* TODO */
37143866b5df (svn r593) -newgrf: Support for two more TTD(Patch) version relate) SkipIf in-game variables (pasky).
darkvater
parents: 400
diff changeset
  1751
		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
  1752
		default:
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
  1753
			if (param >= 0x80) {
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
  1754
				/* In-game variable. */
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
  1755
				grfmsg(GMS_WARN, "Unsupported in-game variable %x. Ignoring test.", param);
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
  1756
			} 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
  1757
				/* Parameter. */
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
  1758
				param_val = _paramlist[param];
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
  1759
			}
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
  1760
			return;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1761
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1762
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
  1763
	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
  1764
	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
  1765
		case 0: result = !!(param_val & (1 << cond_val));
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1766
			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
  1767
		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
  1768
			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
  1769
		/* 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
  1770
		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
  1771
			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
  1772
		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
  1773
			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
  1774
		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
  1775
			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
  1776
		case 5: result = (param_val > cond_val);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1777
			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
  1778
		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
  1779
			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
  1780
		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
  1781
			break;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1782
		default:
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1783
			grfmsg(GMS_WARN, "Unsupported test %d. Ignoring.", condtype);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1784
			return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1785
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1786
1607
320079c7ac28 (svn r2111) So, result is bool therefore no need for this horrible == 0 thing.
pasky
parents: 1606
diff changeset
  1787
	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
  1788
		grfmsg(GMS_NOTICE, "Not skipping sprites, test was false.");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1789
		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
  1790
	}
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
  1791
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
  1792
	numsprites = grf_load_byte(&buf);
1439
c4b08bda7a43 (svn r1943) Show the sprite ID in the check_length() error message. Also show the correct sprite ID in the spriteskip notice.
pasky
parents: 1329
diff changeset
  1793
	grfmsg(GMS_NOTICE, "Skipping %d->+%d sprites, test was true.", _cur_spriteid - _cur_grffile->sprite_offset, numsprites);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1794
	_skip_sprites = numsprites;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1795
	if (_skip_sprites == 0) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1796
		/* Zero means there are no sprites to skip, so
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1797
		 * we use -1 to indicate that all further
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1798
		 * sprites should be skipped. */
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1799
		_skip_sprites = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1800
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1801
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1802
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1803
static void GRFInfo(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1804
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1805
	/* <08> <version> <grf-id> <name> <info>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1806
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1807
	 * B version       newgrf version, currently 06
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1808
	 * 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
  1809
	 * S name          name of this .grf set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1810
	 * 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
  1811
	/* TODO: Check version. (We should have own versioning done somehow.) */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1812
	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
  1813
	uint32 grfid;
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  1814
	const char *name;
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  1815
	const char *info;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1816
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1817
	check_length(len, 9, "GRFInfo");
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1818
	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
  1819
	/* this is de facto big endian - grf_load_dword() unsuitable */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1820
	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
  1821
	name = (const char*)(buf + 6);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1822
	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
  1823
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
  1824
	_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
  1825
	_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
  1826
2013
1b80954e9594 (svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents: 1968
diff changeset
  1827
	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
  1828
	               _cur_grffile->filename, version, grfid, name, info);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1829
}
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
static void SpriteReplace(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1832
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1833
	/* <0A> <num-sets> <set1> [<set2> ...]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1834
	 * <set>: <num-sprites> <first-sprite>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1835
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1836
	 * 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
  1837
	 * Each set:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1838
	 * 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
  1839
	 * 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
  1840
	uint8 num_sets;
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
  1841
	int i;
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
  1842
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
  1843
	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
  1844
	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
  1845
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
  1846
	if (num_sets > 16) {
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
  1847
		grfmsg(GMS_ERROR, "SpriteReplace: Too many sets (%d), taking only the first 16!", num_sets);
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
  1848
	}
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
  1849
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
  1850
	for (i = 0; i < 16; i++) {
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
  1851
		if (i < num_sets) {
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
  1852
			uint8 num_sprites = 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
  1853
			uint16 first_sprite = grf_load_word(&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
  1854
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
  1855
			_replace_sprites_count[i] = num_sprites;
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
  1856
			_replace_sprites_offset[i] = first_sprite;
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
  1857
			grfmsg(GMS_NOTICE, "SpriteReplace: [Set %d] Changing %d sprites, beginning with %d",
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
  1858
					i, num_sprites, first_sprite);
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
  1859
		} else {
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
  1860
			_replace_sprites_count[i] = 0;
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
  1861
			_replace_sprites_offset[i] = 0;
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
  1862
		}
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
  1863
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1864
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1865
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1866
static void GRFError(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1867
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1868
	/* <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
  1869
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1870
	 * B severity      00: notice, contine loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1871
	 *                 01: warning, continue loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1872
	 *                 02: error, but continue loading grf file, and attempt
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1873
	 *                     loading grf again when loading or starting next game
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1874
	 *                 03: error, abort loading and prevent loading again in
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1875
	 *                     the future (only when restarting the patch)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1876
	 * 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
  1877
	 * B message-id    message to show, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1878
	 * 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
  1879
	 *                 not present for built-in messages.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1880
	 * 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
  1881
	 * 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
  1882
	/* 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
  1883
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1884
	static const char * const msgstr[4] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1885
		"Requires at least pseudo-TTDPatch version %s.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1886
		"This file is for %s version of TTD.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1887
		"Designed to be used with %s.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1888
		"Invalid parameter %s.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1889
	};
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1890
	uint8 severity;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1891
	uint8 msgid;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1892
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1893
	check_length(len, 6, "GRFError");
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1894
	severity = buf[1];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1895
	msgid = buf[3];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1896
441
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  1897
	// Undocumented TTDPatch feature.
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  1898
	if ((severity & 0x80) == 0 && _cur_stage == 0)
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  1899
		return;
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  1900
	severity &= 0x7F;
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  1901
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1902
	if (msgid == 0xFF) {
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1903
		grfmsg(severity, "%s", buf+4);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1904
	} else {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1905
		grfmsg(severity, msgstr[msgid], buf+4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1906
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1907
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1908
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1909
static void GRFComment(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1910
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1911
	/* <0C> [<ignored...>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1912
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1913
	 * V ignored       Anything following the 0C is ignored */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1915
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1916
/* Action 0x0D */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1917
static void ParamSet(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1918
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1919
	/* <0D> <target> <operation> <source1> <source2> [<data>]
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
	 * B target        parameter number where result is stored
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1922
	 * B operation     operation to perform, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1923
	 * B source1       first source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1924
	 * B source2       second source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
	 * 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
  1926
	 *                 if both source1 and source2 refer to actual parameters
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1927
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1928
	 * Operations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
	 * 00      Set parameter equal to source1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1930
	 * 01      Addition, source1 + source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1931
	 * 02      Subtraction, source1 - source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1932
	 * 03      Unsigned multiplication, source1 * source2 (both unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1933
	 * 04      Signed multiplication, source1 * source2 (both signed)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1934
	 * 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
  1935
	 *         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
  1936
	 *         negative, source1 is unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1937
	 * 06      Signed bit shift, source1 by source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1938
	 *         (source2 like in 05, and source1 as well)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1939
	 */
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
  1940
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
  1941
	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
  1942
	byte 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
  1943
	uint16 src1;
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
  1944
	uint16 src2;
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
  1945
	uint16 data = 0;
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
  1946
	int32 *dest;
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
  1947
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
  1948
	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
  1949
	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
  1950
	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
  1951
	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
  1952
	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
  1953
	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
  1954
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
  1955
	if (len >= 8)
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
  1956
		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
  1957
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
  1958
	/* 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
  1959
	 * 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
  1960
	 * 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
  1961
	 * - 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
  1962
	 * - 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
  1963
	 *   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
  1964
	if (oper & 0x80) {
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
  1965
		if (_param_max < 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
  1966
			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
  1967
		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
  1968
			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
  1969
	}
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
  1970
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
  1971
	/* 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
  1972
	 * 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
  1973
	 * 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
  1974
	 * 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
  1975
	 * 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
  1976
	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
  1977
		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
  1978
	} 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
  1979
		src1 = _param_max >= src1 ? _paramlist[src1] : 0;
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
  1980
	}
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
  1981
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
  1982
	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
  1983
		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
  1984
	} 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
  1985
		src2 = _param_max >= src2 ? _paramlist[src2] : 0;
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
  1986
	}
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
  1987
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
  1988
	/* 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
  1989
	 * 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
  1990
	 * 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
  1991
	 * 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
  1992
	 * 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
  1993
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
  1994
	/* TODO: The target operand can also refer to the special variables
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
  1995
	 * from action 7, but at the moment the only variable that is valid to
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
  1996
	 * write is 8E. */
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
  1997
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
  1998
	if (target == 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
  1999
		dest = &_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
  2000
	} else {
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
  2001
		if (_param_max < target)
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
  2002
			_param_max = target;
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
		dest = &_paramlist[target];
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
	}
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
  2005
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
  2006
	/* FIXME: No checking for overflows. */
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
  2007
	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
  2008
		case 0x00:
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
  2009
			*dest = 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
  2010
			break;
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
  2011
		case 0x01:
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
  2012
			*dest = 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
  2013
			break;
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
  2014
		case 0x02:
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
  2015
			*dest = 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
  2016
			break;
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
  2017
		case 0x03:
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
  2018
			*dest = ((uint32) src1) * ((uint32) 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
  2019
			break;
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
  2020
		case 0x04:
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
  2021
			*dest = ((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
  2022
			break;
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
  2023
		case 0x05:
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
  2024
			if (src2 & 0x8000) /* src2 is "negative" */
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
  2025
				*dest = src1 >> -((int16) 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
  2026
			else
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
  2027
				*dest = 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
  2028
			break;
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
  2029
		case 0x06:
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
  2030
			if (src2 & 0x8000) /* src2 is "negative" */
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
  2031
				*dest = ((int16) src1) >> -((int16) 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
  2032
			else
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
  2033
				*dest = ((int16) 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
  2034
			break;
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
  2035
		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
  2036
			grfmsg(GMS_ERROR, "ParamSet: Unknown operation %d, skipping.", 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
  2037
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2038
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2039
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2040
static void GRFInhibit(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2041
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2042
	/* <0E> <num> <grfids...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2043
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2044
	 * B num           Number of GRFIDs that follow
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2045
	 * 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
  2046
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
  2047
	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
  2048
	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
  2049
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
  2050
	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
  2051
	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
  2052
	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
  2053
	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
  2054
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
  2055
	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
  2056
		uint32 grfid = grf_load_dword(&buf);
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  2057
		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
  2058
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
  2059
		/* 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
  2060
		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
  2061
			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
  2062
			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
  2063
		}
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
  2064
	}
0
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
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
  2067
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
  2068
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
  2069
{
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
  2070
	/* 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
  2071
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
  2072
	_ttdpatch_flags[0] = (1 << 0x1B); /* multihead */
441
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2073
	_ttdpatch_flags[1] = (1 << 0x08)  /* mammothtrains */
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2074
	                   | (1 << 0x0B)  /* subsidiaries */
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2075
	                   | (1 << 0x14)  /* bridgespeedlimits */
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2076
	                   | (1 << 0x16)  /* eternalgame */
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2077
	                   | (1 << 0x17)  /* newtrains */
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2078
	                   | (1 << 0x18)  /* newrvs */
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2079
	                   | (1 << 0x19)  /* newships */
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2080
	                   | (1 << 0x1A)  /* newplanes */
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
  2081
			               | (1 << 0x1B); /* signalsontrafficside */
441
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2082
	                   /* 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
  2083
	                    * 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
  2084
	                    * 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
  2085
	                    * 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
  2086
			               //| (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
  2087
441
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2088
	_ttdpatch_flags[2] = (1 << 0x0D)  /* buildonslopes */
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2089
	                   | (1 << 0x16)  /* canals */
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2090
	                   | (1 << 0x17); /* newstartyear */
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
  2091
}
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
  2092
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2093
void InitNewGRFFile(const char *filename, int sprite_offset)
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2094
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  2095
	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
  2096
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
  2097
	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
  2098
	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
  2099
		/* 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
  2100
		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
  2101
		_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
  2102
		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
  2103
	}
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
  2104
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  2105
	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
  2106
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
  2107
	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
  2108
		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
  2109
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
  2110
	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
  2111
	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
  2112
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
  2113
	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
  2114
		_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
  2115
		_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
  2116
	} 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
  2117
		_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
  2118
		_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
  2119
	}
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
  2120
}
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
  2121
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
  2122
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2123
/* 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
  2124
 * 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
  2125
 * partial implementation yet). */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2126
/* 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
  2127
 * 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
  2128
 * better make this more robust in the future. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2129
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2130
void DecodeSpecialSprite(const char *filename, int num, int spriteid, int stage)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2131
{
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  2132
#define NUM_ACTIONS 0xF
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2133
	static const SpecialSpriteHandler handlers[NUM_ACTIONS] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2134
		/* 0x0 */ VehicleChangeInfo,
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  2135
		/* 0x1 */ NewSpriteSet,
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  2136
		/* 0x2 */ NewSpriteGroup,
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  2137
		/* 0x3 */ NewVehicle_SpriteGroupMapping,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2138
		/* 0x4 */ VehicleNewName,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2139
		/* 0x5 */ GraphicsNew,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2140
		/* 0x6 */ CfgApply,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2141
		/* 0x7 */ SkipIf,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2142
		/* 0x8 */ GRFInfo,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2143
		/* 0x9 */ SkipIf,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2144
		/* 0xa */ SpriteReplace,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2145
		/* 0xb */ GRFError,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2146
		/* 0xc */ GRFComment,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2147
		/* 0xd */ ParamSet,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2148
		/* 0xe */ GRFInhibit,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2149
	};
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2150
	static bool initialized = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2151
	byte action;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2152
	byte *buf = malloc(num);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2153
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2154
	if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory");
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2155
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2156
	if (!initialized) {
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
  2157
		InitializeGRFSpecial();
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2158
		initialized = true;
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
  2159
	}
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
  2160
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2161
	_cur_stage = stage;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2162
	_cur_spriteid = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2163
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2164
	FioReadBlock(buf, num);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2165
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2166
	action = buf[0];
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2167
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  2168
	/* 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
  2169
	 * 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
  2170
	 * 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
  2171
	 * "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
  2172
	 * 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
  2173
	 * 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
  2174
	 * 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
  2175
	 * 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
  2176
	 * --pasky */
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2177
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2178
	if (stage == 0) {
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2179
		switch (action) {
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2180
			case 0x00:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2181
			case 0x01:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2182
			case 0x02:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2183
			case 0x03:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2184
			case 0x04:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2185
			case 0x05:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2186
			case 0x07:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2187
				/* During initialization, these actions are ignored. */
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2188
				DEBUG (grf, 7) (
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2189
					"DecodeSpecialSprite: Action: %x, Stage 0, Skipped", action);
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2190
				break;
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2191
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2192
			default:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2193
				if (action < NUM_ACTIONS) {
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2194
					DEBUG (grf, 7) ("DecodeSpecialSprite: Action: %x, Stage 0", action);
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2195
 					handlers[action](buf, num);
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2196
				} else {
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2197
					grfmsg(GMS_WARN,
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2198
						"Unknown special sprite action %x, skipping.", action);
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2199
				}
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2200
		}
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2201
	} else if (stage == 1) {
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2202
		/* A .grf file is activated only if it was active when the game was
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2203
		 * started.  If a game is loaded, only its active .grfs will be
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2204
		 * reactivated, unless "loadallgraphics on" is used.  A .grf file is
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2205
		 * considered active if its action 8 has been processed, i.e. its
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2206
		 * action 8 hasn't been skipped using an action 7.
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2207
		 *
441
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2208
		 * During activation, only actions 0, 1, 2, 3, 4, 5, 7, 8, 9, 0A and 0B are
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2209
		 * carried out.  All others are ignored, because they only need to be
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2210
		 * processed once at initialization.  */
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2211
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2212
		if (_cur_grffile == NULL || strcmp(_cur_grffile->filename, filename) != 0)
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2213
			_cur_grffile = GetFileByFilename(filename);
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2214
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2215
		if (_cur_grffile == NULL)
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2216
			error("File ``%s'' lost in cache.\n", filename);
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2217
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2218
		if (_cur_grffile->flags & 0x0001) {
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2219
			switch (action) {
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2220
				case 0x00:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2221
				case 0x01:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2222
				case 0x02:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2223
				case 0x03:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2224
				case 0x04:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2225
				case 0x05:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2226
				case 0x07:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2227
				case 0x08:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2228
				case 0x09:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2229
				case 0x0A:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2230
				case 0x0B:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2231
					DEBUG (grf, 7) ("DecodeSpecialSprite: Action: %x, Stage 1", action);
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2232
					handlers[action](buf, num);
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2233
					break;
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2234
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2235
				default:
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2236
					if (action < NUM_ACTIONS) {
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2237
						DEBUG (grf, 7) (
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2238
							"DecodeSpecialSprite: Action: %x, Stage 1, Skipped", action);
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2239
					} else {
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2240
						grfmsg(GMS_WARN,
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2241
							"Unknown special sprite action %x, skipping.", action);
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2242
					}
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2243
					break;
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2244
			}
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2245
		} else {
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2246
			DEBUG (grf, 7) (
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2247
				"DecodeSpecialSprite: Action: %x, Stage 1, Not activated", action);
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2248
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2249
	} else {
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  2250
		error("Invalid stage %d", stage);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2251
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2252
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2253
	free(buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2254
#undef NUM_ACTIONS
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2255
}