grfspecial.c
author celestar
Sat, 13 Nov 2004 12:21:32 +0000
changeset 372 ec1e802872c7
parent 369 3742b39b6cca
child 373 9eda1aad5f04
permissions -rw-r--r--
(svn r560) -newgrf: General cleanup of the code (pasky & octo)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     1
#include "stdafx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include <stdarg.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 "ttd.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "fileio.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "engine.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
/* TTDPatch extended GRF format codec
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
 * (c) Petr Baudis 2004 (GPL'd)
356
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
    12
 * Changes by Florian octo Forster are (c) by the OpenTTD development team.
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
    13
 *
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
 * Contains portions of documentation by TTDPatch team.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
 * 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
    16
 * 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
    17
 * 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
    18
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
extern int _skip_sprites;
361
95307fb1c3f8 (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
    20
extern int _replace_sprites_count[16];
95307fb1c3f8 (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
    21
extern int _replace_sprites_offset[16];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
366
05c09e262c8e (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
    23
struct GRFFile {
05c09e262c8e (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
    24
	char *filename;
05c09e262c8e (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
    25
	uint32 grfid;
05c09e262c8e (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
    26
	uint16 flags;
05c09e262c8e (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
    27
	uint16 sprite_offset;
05c09e262c8e (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
    28
	struct GRFFile *next;
05c09e262c8e (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
    29
};
05c09e262c8e (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
    30
05c09e262c8e (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
    31
static struct GRFFile *_cur_grffile, *_first_grffile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
static int _cur_spriteid;
368
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
    33
static int _cur_stage;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
362
4bb825210268 (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
    35
static int32 _paramlist[0x7f];
4bb825210268 (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
    36
static int _param_max;
4bb825210268 (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
    37
363
2a01c271fe2d (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
    38
/* 32 * 8 = 256 flags. Apparently TTDPatch uses this many.. */
2a01c271fe2d (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
    39
static uint32 _ttdpatch_flags[8];
2a01c271fe2d (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
    40
2a01c271fe2d (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
    41
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
typedef void (*SpecialSpriteHandler)(byte *buf, int len);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    44
static const int _vehcounts[4] = {
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    45
	NUM_TRAIN_ENGINES,
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    46
	NUM_ROAD_ENGINES,
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    47
	NUM_SHIP_ENGINES,
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    48
	NUM_AIRCRAFT_ENGINES
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    49
};
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    50
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
static const int _vehshifts[4] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
	0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
	ROAD_ENGINES_INDEX,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
	SHIP_ENGINES_INDEX,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
	AIRCRAFT_ENGINES_INDEX,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
enum grfmsg_severity {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
	GMS_NOTICE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
	GMS_WARN,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
	GMS_ERROR,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
	GMS_FATAL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
static void CDECL grfmsg(enum grfmsg_severity severity, const char *str, ...)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
	static const char * const severitystr[4] = { "Notice", "Warning", "Error", "Fatal" };
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    69
	int export_severity = 0;
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 51
diff changeset
    70
	char buf[1024];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
	va_list va;
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
	va_start(va, str);
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 51
diff changeset
    74
	vsprintf(buf, str, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
	va_end(va);
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    76
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    77
	export_severity = 2 - (severity == GMS_FATAL ? 2 : severity);
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
    78
	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
    79
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
    81
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
    82
#define check_length(real, wanted, where) \
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
    83
do { \
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
    84
	if (real < wanted) { \
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
    85
		grfmsg(GMS_ERROR, "%s: Invalid special sprite length %d (expected %d)!", where, real, wanted); \
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
    86
		return; \
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
    87
	} \
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
    88
} while (0)
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
    89
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
    90
368
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
    91
static byte INLINE grf_load_byte(byte **buf)
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
    92
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
	return *(*buf)++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
static uint16 grf_load_word(byte **buf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
	uint16 val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
	byte *p = *buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
	val = p[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
	val |= p[1] << 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
	*buf = p + 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
	return val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
static uint16 grf_load_dword(byte **buf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
	uint32 val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
	byte *p = *buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
	val = p[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
	val |= p[1] << 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
	val |= p[2] << 16;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
	val |= p[3] << 24;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
	*buf = p + 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
	return val;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   118
366
05c09e262c8e (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
   119
static struct GRFFile *GetFileByGRFID(uint32 grfid)
05c09e262c8e (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
   120
{
05c09e262c8e (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
   121
	struct GRFFile *file;
05c09e262c8e (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
   122
05c09e262c8e (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
   123
	file = _first_grffile;
05c09e262c8e (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
   124
	while ((file != NULL) && (file->grfid != grfid))
05c09e262c8e (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
   125
		file = file->next;
05c09e262c8e (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
   126
05c09e262c8e (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
   127
	return file;
05c09e262c8e (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
   128
}
05c09e262c8e (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
   129
368
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
   130
static struct GRFFile *GetFileByFilename(const char *filename)
366
05c09e262c8e (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
   131
{
05c09e262c8e (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
   132
	struct GRFFile *file;
05c09e262c8e (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
   133
05c09e262c8e (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
   134
	file = _first_grffile;
05c09e262c8e (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
   135
	while ((file != NULL) && strcmp(file->filename, filename))
368
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
   136
		file = file->next;
366
05c09e262c8e (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
   137
05c09e262c8e (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
   138
	return file;
05c09e262c8e (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
   139
}
05c09e262c8e (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
   140
05c09e262c8e (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
   141
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   142
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
   143
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   144
#define FOR_EACH_ENGINE for (i = 0; i < numinfo; i++)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
static void dewagonize(int condition, int engine)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
	EngineInfo *ei = &_engine_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   151
	if (condition != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
		ei->unk2 &= ~0x80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
		rvi->flags &= ~2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
		ei->unk2 |= 0x80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
		rvi->flags |= 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   160
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
   161
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
	EngineInfo *ei = &_engine_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
	byte *buf = *bufp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
	int i;
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   166
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
	switch (prop) {
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   169
		case 0x05: {	/* Track type */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   170
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
				uint8 tracktype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
				ei[i].railtype_climates &= 0xf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
				ei[i].railtype_climates |= tracktype << 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   176
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   177
		case 0x08: {	/* AI passenger service */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
			/* TODO */
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   179
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
				grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   182
			ret = true;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   183
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   184
		case 0x09: {	/* Speed */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   185
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
				uint16 speed = grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
				rvi[i].max_speed = speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
				dewagonize(speed, engine + i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   191
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   192
		case 0x0B: {	/* Power */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   193
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
				uint16 power = grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
				rvi[i].power = power;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
				dewagonize(power, engine + i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   199
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   200
		case 0x0D: {	/* Running cost factor */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   201
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
				uint8 runcostfact = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
				rvi[i].running_cost_base = runcostfact;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
				dewagonize(runcostfact, engine + i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   207
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   208
		case 0x0E: {	/* Running cost base */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   209
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
				uint32 base = grf_load_dword(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
				switch (base) {
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   213
				case 0x4C30:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
					rvi[i].engclass = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
					break;
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   216
				case 0x4C36:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
					rvi[i].engclass = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
					break;
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   219
				case 0x4C3C:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
					rvi[i].engclass = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
					break;
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
				dewagonize(base, engine + i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   225
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   226
		case 0x12: {	/* Sprite ID */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   227
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   230
				if (spriteid == 0xFD && rvi[i].image_index != 0xFD)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
					_engine_original_sprites[engine + i] = rvi[i].image_index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
				rvi[i].image_index = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   234
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   235
		case 0x13: {	/* Dual-headed */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   236
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
				uint8 dual = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   239
				if (dual != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
					rvi[i].flags |= 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
					rvi[i].flags &= ~1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   245
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   246
		case 0x14: {	/* Cargo capacity */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   247
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
				uint8 capacity = grf_load_byte(&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
				rvi[i].capacity = capacity;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   252
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   253
		case 0x15: {	/* Cargo type */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   254
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
				uint8 ctype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
				rvi[i].cargo_type = ctype;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   259
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   260
		case 0x16: {	/* Weight */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   261
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
				uint8 weight = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
				rvi[i].weight = weight;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   266
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   267
		case 0x17: {	/* Cost factor */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   268
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
				uint8 cfactor = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
				rvi[i].base_cost = cfactor;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   273
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   274
		case 0x18: {	/* AI rank */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
			/* TODO: _railveh_score should be merged to _rail_vehicle_info. */
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   276
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
				grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   279
			ret = true;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   280
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   281
		case 0x19: { /* Engine traction type */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
			/* TODO: What do the individual numbers mean?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
			 * XXX: And in what base are they, in fact? --pasky */
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   284
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
				uint8 traction = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
				int engclass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
				if (traction <= 0x07)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
					engclass = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
				else if (traction <= 0x27)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
					engclass = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
				else if (traction <= 0x31)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
					engclass = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
				else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
				rvi[i].engclass = engclass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   299
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   300
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
		/* TODO */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
		/* Fall-through for unimplemented four bytes long properties. */
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   303
		case 0x1D:	/* Refit cargo */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   304
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
				grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
		/* Fall-through for unimplemented two bytes long properties. */
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   308
		case 0x1B:	/* Powered wagons power bonus */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   309
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
				grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
		/* Fall-through for unimplemented one byte long properties. */
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   313
		case 0x1A:	/* Sort order */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   314
		case 0x1C:	/* Refit cost */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   315
		case 0x1E:	/* Callback */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   316
		case 0x1F:	/* Tractive effort */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
		case 0x21:	/* Shorter tenders */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
		case 0x22:	/* Visual */
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   319
		case 0x23: {/* Powered wagons weight bonus */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
			/* TODO */
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   321
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
				grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   324
			ret = true;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   325
		}	break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
		default:
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   327
			ret = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   333
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
   334
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
	ShipVehicleInfo *svi = &_ship_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
	byte *buf = *bufp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
	int i;
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   338
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
	//printf("e %x prop %x?\n", engine, prop);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
	switch (prop) {
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   342
		case 0x08: {	/* Sprite ID */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   343
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   346
				if (spriteid == 0xFF)
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   347
					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
   348
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
				// 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
   350
				// in not having it here for the future.
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   351
				if (spriteid == 0xFD && svi[i].image_index != 0xFD)
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   352
					_engine_original_sprites[SHIP_ENGINES_INDEX + engine + i] = svi[i].image_index;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   353
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
				svi[i].image_index = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   356
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   357
		case 0x09: {	/* Refittable */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   358
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
				uint8 refittable = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
				svi[i].refittable = refittable;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   363
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   364
		case 0x0A: {	/* Cost factor */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   365
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
				uint8 cost_factor = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
				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
   369
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   370
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   371
		case 0x0B: {	/* Speed */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   372
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
				uint8 speed = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
				svi[i].max_speed = speed; // ?? units
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   377
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   378
		case 0x0C: { /* Cargo type */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   379
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
				uint8 cargo = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
				// XXX: Need to consult this with patchman yet.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
#if 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
				// Documentation claims this is already the
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
				// per-landscape cargo type id, but newships.grf
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
				// assume otherwise.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
				cargo = local_cargo_id_ctype[cargo];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
				svi[i].cargo_type = cargo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   391
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   392
		case 0x0D: {	/* Cargo capacity */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   393
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
				uint16 capacity = grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
				svi[i].capacity = capacity;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   398
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   399
		case 0x0F: {	/* Running cost factor */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   400
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
				uint8 runcost = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
				svi[i].running_cost = runcost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   405
		} break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   406
		case 0x10: {	/* SFX */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   407
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
				uint8 sfx = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
				svi[i].sfx = sfx;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   412
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   413
		case 0x11: {	/* Cargos available for refitting */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   414
			FOR_EACH_ENGINE {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
				uint32 refit_mask = grf_load_dword(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
				_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
   418
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   419
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   420
		case 0x12: { /* Callback TODO */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   421
			ret = true;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   422
		}	break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
		default:
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   424
			ret = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
#undef shift_buf
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
356
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   433
/* Action 0x00 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
static void VehicleChangeInfo(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
	byte *bufend = buf + len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
	/* <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
   440
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
	 * 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
   442
	 *                 4 for defining new train station sets
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
	 * 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
   444
	 * B num-info      how many vehicles/stations to change
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
	 * 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
   446
	 *                 greater than one, this one and the following
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
	 *                 vehicles/stations will be changed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
	 * 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
   449
	 * V new-info      new bytes of info (variable size; depends on properties) */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
	/* TODO: Only trains and ships are supported for now. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
	static const VCI_Handler handler[5] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
		RailVehicleChangeInfo,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
		NULL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
		ShipVehicleChangeInfo,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
		NULL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
		NULL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
	};
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   459
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   460
	uint8 feature;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   461
	uint8 numprops;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   462
	uint8 numinfo;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   463
	byte engine;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   464
	EngineInfo *ei;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   466
	check_length(len, 6, "VehicleChangeInfo");
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   467
	feature = buf[1];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   468
	numprops = buf[2];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   469
	numinfo = buf[3];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   470
	engine = buf[4];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
   471
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   472
	if (feature != 0 && feature != 2) {
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   473
		grfmsg(GMS_WARN, "VehicleChangeInfo: Unsupported vehicle type %x, skipping.", feature);
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   474
		return;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   475
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
   476
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   477
	ei = &_engine_info[engine + _vehshifts[feature]];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   478
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   479
	buf += 5;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   480
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   481
	while (numprops-- && buf < bufend) {
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   482
		uint8 prop = grf_load_byte(&buf);
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   483
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   484
		switch (prop) {
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   485
		case 0x00: { /* Introduction date */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   486
			FOR_EACH_ENGINE {
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   487
				uint16 date = grf_load_word(&buf);
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   488
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   489
				ei[i].base_intro = date;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   491
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   492
		case 0x02: { /* Decay speed */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   493
			FOR_EACH_ENGINE {
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   494
				uint8 decay = grf_load_byte(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   496
				ei[i].unk2 &= 0x80;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   497
				ei[i].unk2 |= decay & 0x7f;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   499
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   500
		case 0x03: { /* Vehicle life */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   501
			FOR_EACH_ENGINE {
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   502
				uint8 life = grf_load_byte(&buf);
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   503
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   504
				ei[i].lifelength = life;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   506
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   507
		case 0x04: { /* Model life */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   508
			FOR_EACH_ENGINE {
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   509
				uint8 life = grf_load_byte(&buf);
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   510
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   511
				ei[i].base_life = life;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   512
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   513
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   514
		case 0x06: { /* Climates available */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   515
			FOR_EACH_ENGINE {
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   516
				uint8 climates = grf_load_byte(&buf);
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   517
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   518
				ei[i].railtype_climates &= 0xf0;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   519
				ei[i].railtype_climates |= climates;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   520
			}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   521
		}	break;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   522
		case 0x07: { /* Loading spee */
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   523
			/* TODO */
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   524
			/* Hyronymus explained me what does
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   525
			 * this mean and insists on having a
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   526
			 * credit ;-). --pasky */
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   527
			/* TODO: This needs to be supported by
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   528
			 * LoadUnloadVehicle() first. */
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   529
			FOR_EACH_ENGINE {
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   530
				grf_load_byte(&buf);
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   531
			}
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   532
			goto ignoring;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   533
		}
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   534
		default: {
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   535
			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
   536
ignoring:
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   537
				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
   538
			}
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   539
			break;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   540
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
#undef shift_buf
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   547
/* A sprite group contains all sprites of a given vehicle (or multiple
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
 * vehicles) when carrying given cargo. It consists of several sprite sets.
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   549
 * Group ids are refered as "cargo id"s by TTDPatch documentation,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
 * contributing to the global confusion.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
 * A sprite set contains all sprites of a given vehicle carrying given cargo at
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
 * a given *stage* - that is usually its load stage. Ie. you can have a
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
 * spriteset for an empty wagon, wagon full of coal, half-filled wagon etc.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
 * Each spriteset contains eight sprites (one per direction) or four sprites if
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
 * the vehicle is symmetric. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
static int _spriteset_start;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
static int _spriteset_numsets;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
static int _spriteset_numents;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
static int _spriteset_feature;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
static int _spritesset_count;
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   564
static struct SpriteGroup *_spritesset;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
356
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   566
/* Action 0x01 */
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   567
static void NewSpriteSet(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
	/* <01> <feature> <num-sets> <num-ent>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
	 * B feature       feature to define sprites for
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
	 *                 0, 1, 2, 3: veh-type, 4: train stations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
	 * B num-sets      number of sprite sets
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
	 * B num-ent       how many entries per sprite set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
	 *                 For vehicles, this is the number of different
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
	 *                         vehicle directions in each sprite set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
	 *                         Set num-dirs=8, unless your sprites are symmetric.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
	 *                         In that case, use num-dirs=4.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
	 *                 For stations, must be 12 (hex) for the eighteen
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
	 *                         different sprites that make up a station */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
	/* TODO: No stations support. */
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   582
	uint8 feature;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   584
	check_length(len, 4, "NewSpriteSet");
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   585
	feature = buf[1];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   587
	if (feature == 4) {
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   588
		_spriteset_start = 0;
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   589
		grfmsg(GMS_WARN, "NewSpriteSet: Stations unsupported, skipping.");
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   590
		return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
	}
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   592
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   593
	_spriteset_start = _cur_spriteid + 1;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   594
	_spriteset_feature = feature;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   595
	_spriteset_numsets = buf[2];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   596
	_spriteset_numents = buf[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
356
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   599
/* Action 0x02 */
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   600
static void NewSpriteGroup(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
	byte *bufend = buf + len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
	/* <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
   605
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
	 * B feature       see action 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
	 * B set-id        ID of this particular definition
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
	 * B type/num-entries
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
	 *                 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
   610
	 *                 list definition, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
	 *                 otherwise it specifies a number of entries, the exact
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
	 *                 meaning depends on the feature
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
	 * V feature-specific-data (huge mess, don't even look it up --pasky) */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
	/* TODO: Only trains supported now. No 0x80-types (ugh). */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
	/* 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
   616
	 * 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
   617
	 * when. --pasky */
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   618
	uint8 feature;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   619
	uint8 setid;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   620
	uint8 numloaded;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   621
	uint8 numloading;
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   622
	struct SpriteGroup *group;
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   623
	byte *loaded_ptr;
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   624
	byte *loading_ptr;
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   625
	int i;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
   626
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   627
	check_length(len, 5, "NewSpriteGroup");
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   628
	feature = buf[1];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   629
	setid = buf[2];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   630
	numloaded = buf[3];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   631
	numloading = buf[4];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   633
	if (feature == 4) {
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   634
		grfmsg(GMS_WARN, "NewSpriteGroup: Stations unsupported, skipping.");
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   635
		return;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   636
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   638
	if (numloaded == 0x81) {
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   639
		// XXX: This is _VERY_ ad hoc just to handle Dm3. And that is
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   640
		// a semi-futile ask because the great Patchman himself says
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   641
		// this is just buggy. It dereferences last (first) byte of
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   642
		// a schedule list pointer of the vehicle and if it's 0xff
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   643
		// it uses group 01, otherwise it uses group 00. Now
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   644
		// if _you_ understand _that_... We just assume it is never
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   645
		// 0xff and therefore go for group 00. --pasky
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   646
		uint8 var = buf[4];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   647
		//uint8 shiftnum = buf[5];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   648
		//uint8 andmask = buf[6];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   649
		uint8 nvar = buf[7];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   650
		//uint32 val;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   651
		uint16 def;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   653
		grfmsg(GMS_WARN, "NewSpriteGroup(0x81): Unsupported variable %x. Using default cid.", var);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   655
		//val = (0xff << shiftnum) & andmask;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   656
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   657
		//Go for the default.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
		if (setid >= _spritesset_count) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
			_spritesset_count = setid + 1;
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   660
			_spritesset = realloc(_spritesset, _spritesset_count * sizeof(struct SpriteGroup));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
		}
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   662
		buf += 8 + nvar * 4;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   663
		def = grf_load_word(&buf);
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   664
		_spritesset[setid] = _spritesset[def];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   665
		return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   667
	} else if (numloaded & 0x80) {
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   668
		grfmsg(GMS_WARN, "NewSpriteGroup(0x%x): Unsupported special group.", numloaded);
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   669
		return;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   670
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   672
	if (!_spriteset_start) {
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   673
		grfmsg(GMS_ERROR, "NewSpriteGroup: No sprite set to work on! Skipping.");
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   674
		return;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   675
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   677
	if (_spriteset_feature != feature) {
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   678
		grfmsg(GMS_ERROR, "NewSpriteGroup: Group feature %x doesn't match set feature %x! Skipping.", feature, _spriteset_feature);
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   679
		return;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   680
	}
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   681
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   682
	check_length(bufend - buf, 5, "NewSpriteGroup");
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   683
	buf += 5;
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   684
	check_length(bufend - buf, 2 * numloaded, "NewSpriteGroup");
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   685
	loaded_ptr = buf;
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   686
	loading_ptr = buf + 2 * numloaded;
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   687
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   688
	if (numloaded > 16) {
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   689
		grfmsg(GMS_WARN, "NewSpriteGroup: More than 16 sprites in group %x, skipping the rest.", setid);
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   690
		numloaded = 16;
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   691
	}
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   692
	if (numloading > 16) {
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   693
		grfmsg(GMS_WARN, "NewSpriteGroup: More than 16 sprites in group %x, skipping the rest.", setid);
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   694
		numloading = 16;
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   695
	}
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   696
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   697
	if (setid >= _spritesset_count) {
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   698
		_spritesset_count = setid + 1;
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   699
		_spritesset = realloc(_spritesset, _spritesset_count * sizeof(struct SpriteGroup));
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   700
	}
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   701
	group = &_spritesset[setid];
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   702
	memset(group, 0, sizeof(struct SpriteGroup));
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   703
	group->sprites_per_set = _spriteset_numents;
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   704
	group->loaded_count  = numloaded;
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   705
	group->loading_count = numloading;
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   706
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   707
	DEBUG(grf, 7) ("NewSpriteGroup: New SpriteGroup 0x%02hhx, %u views, %u loaded, %u loading, sprites %u - %u",
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   708
			setid, group->sprites_per_set, group->loaded_count, group->loading_count,
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   709
			_spriteset_start - _cur_grffile->sprite_offset,
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   710
			_spriteset_start + (_spriteset_numents * (numloaded + numloading)) - _cur_grffile->sprite_offset);
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   711
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   712
	for (i = 0; i < numloaded; i++) {
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   713
		uint16 spriteset_id = grf_load_word(&loaded_ptr);
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   714
		group->loaded[i] = _spriteset_start + spriteset_id * _spriteset_numents;
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   715
		DEBUG(grf, 8) ("NewSpriteGroup: + group->loaded[%i]  = %u (subset %u)", i, group->loaded[i], spriteset_id);
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   716
	}
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   717
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   718
	for (i = 0; i < numloading; i++) {
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   719
		uint16 spriteset_id = grf_load_word(&loading_ptr);
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   720
		group->loading[i] = _spriteset_start + spriteset_id * _spriteset_numents;
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   721
		DEBUG(grf, 8) ("NewSpriteGroup: + group->loading[%i] = %u (subset %u)", i, group->loading[i], spriteset_id);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
356
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   725
/* Action 0x03 */
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   726
static void NewVehicle_SpriteGroupMapping(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
	/* <03> <feature> <n-id> <ids>... <num-cid> [<cargo-type> <cid>]... <def-cid>
356
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   729
	 * id-list	:= [<id>] [id-list]
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   730
	 * cargo-list	:= <cargo-type> <cid> [cargo-list]
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
	 * B feature       see action 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
	 * 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
   734
	 *                 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
   735
	 * B ids           the IDs for which this definition applies
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   736
	 * 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
   737
	 *                 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
   738
	 * B cargo-type    type of this cargo type (e.g. mail=2, wood=7, see below)
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   739
	 * W cid           cargo ID (sprite group ID) for this type of cargo
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   740
	 * W def-cid       default cargo ID (sprite group ID) */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   741
	/* TODO: Only trains supported now. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
	/* 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
   743
	 * 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
   744
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
	static byte *last_engines;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
	static int last_engines_count;
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   747
	uint8 feature;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   748
	uint8 idcount;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   749
	int wagover;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   750
	uint8 cidcount;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   751
	int c, i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   753
	check_length(len, 7, "VehicleMapSpriteGroup");
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   754
	feature = buf[1];
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   755
	idcount = buf[2] & 0x7F;
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   756
	wagover = buf[2] & 0x80;
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   757
	check_length(len, 3 + idcount, "VehicleMapSpriteGroup");
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   758
	cidcount = buf[3 + idcount];
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   759
	check_length(len, 4 + idcount + cidcount * 3, "VehicleMapSpriteGroup");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   761
	if (feature == 4) {
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   762
		grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Stations unsupported, skipping.");
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   763
		return;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   764
	}
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   765
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   766
	/* If ``n-id'' (or ``idcount'') is zero, this is a ``feature
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   767
	 * callback''. I have no idea how this works, so we will ignore it for
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   768
	 * now.  --octo */
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   769
	if (idcount == 0) {
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   770
		grfmsg(GMS_NOTICE, "NewMapping: Feature callbacks not implemented yet.");
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   771
		return;
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   772
	}
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   773
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   774
	// FIXME: Tropicset contains things like:
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   775
	// 03 00 01 19 01 00 00 00 00 - this is missing one 00 at the end,
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   776
	// what should we exactly do with that? --pasky
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   777
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   778
	if (!_spriteset_start || !_spritesset) {
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   779
		grfmsg(GMS_WARN, "VehicleMapSpriteGroup: No sprite set to work on! Skipping.");
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   780
		return;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   781
	}
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   782
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   783
	if (!wagover && last_engines_count != idcount) {
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   784
		last_engines = realloc(last_engines, idcount);
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   785
		last_engines_count = idcount;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   786
	}
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   787
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   788
	if (wagover != 0) {
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   789
		if (last_engines_count == 0) {
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   790
			grfmsg(GMS_ERROR, "VehicleMapSpriteGroup: WagonOverride: No engine to do override with.");
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   791
			return;
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   792
		} else {
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   793
			DEBUG(grf, 4) ("VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons.",
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   794
					last_engines_count, idcount);
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   795
		}
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   796
	}
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   797
	
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   798
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   799
	for (i = 0; i < idcount; i++) {
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   800
		uint8 engine_id = buf[3 + i];
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   801
		uint8 engine = engine_id + _vehshifts[feature];
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   802
		byte *bp = &buf[4 + idcount];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   803
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   804
		if (engine_id > _vehcounts[feature]) {
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   805
			grfmsg(GMS_ERROR, "Id %u for feature %x is out of bounds.",
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   806
					engine_id, feature);
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   807
			return;
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   808
		}
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   809
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   810
		for (c = 0; c < cidcount; c++) {
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   811
			uint8 ctype = grf_load_byte(&bp);
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   812
			uint16 groupid = grf_load_word(&bp);
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   813
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   814
			if (groupid >= _spritesset_count) {
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   815
				grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x, skipping.", groupid, _spritesset_count);
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   816
				return;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   817
			}
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   818
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   819
			if (ctype == 0xFF)
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   820
				ctype = CID_PURCHASE;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   821
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   822
			if (wagover != 0) {
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   823
				// TODO: No multiple cargo types per vehicle yet. --pasky
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   824
				SetWagonOverrideSprites(engine, &_spritesset[groupid], last_engines, last_engines_count);
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   825
			} else {
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   826
				SetCustomEngineSprites(engine, ctype, &_spritesset[groupid]);
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   827
				last_engines[i] = engine;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   828
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
		}
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   830
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   832
	{
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   833
		byte *bp = buf + 4 + idcount + cidcount * 3;
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   834
		uint16 groupid = grf_load_word(&bp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
		for (i = 0; i < idcount; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   837
			uint8 engine = buf[3 + i] + _vehshifts[feature];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   839
			// Don't tell me you don't love duplicated code!
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   840
			if (groupid >= _spritesset_count) {
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   841
				grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x, skipping.", groupid, _spritesset_count);
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   842
				return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   845
			if (wagover != 0) {
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   846
				// TODO: No multiple cargo types per vehicle yet. --pasky
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   847
				SetWagonOverrideSprites(engine, &_spritesset[groupid], last_engines, last_engines_count);
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   848
			} else {
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
   849
				SetCustomEngineSprites(engine, CID_DEFAULT, &_spritesset[groupid]);
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   850
				last_engines[i] = engine;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
356
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   856
/* Action 0x04 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
static void VehicleNewName(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
	/* <04> <veh-type> <language-id> <num-veh> <offset> <data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
	 * B veh-type      see action 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
	 * 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
   863
	 * 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
   864
	 * 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
   865
	 * 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
   866
	 *                 which the next name begins. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
	/* 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
   868
	 * 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
   869
	 * (completely new scenarios changing all graphics and logically also
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
	 * 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
   871
	 * name), not only the original four ones. --pasky */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   873
	uint8 feature;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   874
	uint8 lang;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   875
	uint8 id;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   876
	uint8 endid;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   878
	check_length(len, 6, "VehicleNewName");
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   879
	feature = buf[1];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   880
	lang = buf[2];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   881
	id = buf[4] + _vehshifts[feature];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   882
	endid = id + buf[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   884
	if (lang & 0x80) {
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   885
		grfmsg(GMS_WARN, "VehicleNewName: No support for changing in-game texts. Skipping.");
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   886
		return;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   887
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   889
	if (!(lang & 3)) {
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   890
		/* XXX: If non-English name, silently skip it. */
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   891
		return;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   892
	}
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   893
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   894
	buf += 5, len -= 5;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   895
	for (; id < endid && len > 0; id++) {
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   896
		int ofs = strlen(buf) + 1;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   897
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   898
		if (ofs < 128)
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   899
			SetCustomEngineName(id, buf);
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   900
		buf += ofs, len -= ofs;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
356
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   904
/* Action 0x05 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
static void GraphicsNew(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
	/* <05> <graphics-type> <num-sprites> <other data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
	 * 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
   910
	 * 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
   911
	 * V other data    Graphics type specific data.  Currently unused. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
	/* TODO */
356
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   913
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   914
	uint8 type;
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   915
	uint8 num;
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   916
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   917
	check_length(len, 2, "GraphicsNew");
356
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   918
	type = buf[0];
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   919
	num = buf[1];
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   920
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   921
	grfmsg(GMS_NOTICE, "GraphicsNew: Custom graphics (type %x) sprite block of length %d (unimplemented, ignoring).\n",
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   922
	       type, num);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
356
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   925
/* Action 0x06 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
static void CfgApply(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
	/* <06> <param-num> <param-size> <offset> ... <FF>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
	 * 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
   931
	 *                 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
   932
	 * 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
   933
	 *                 bytes of the following parameter are used.  In that
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
	 *                 case, nothing is applied unless *all* parameters
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
	 *                 were specified.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
	 * 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
   937
	 *                 to place where parameter is to be stored. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
	/* TODO */
356
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   939
	grfmsg(GMS_NOTICE, "CfgApply: Ignoring (not implemented).\n");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
356
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   942
/* Action 0x07 */
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
   943
/* Action 0x09 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
static void SkipIf(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
	/* <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
   947
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
	 * B param-num
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
	 * B param-size
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
	 * B condition-type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
	 * V value
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
	 * B num-sprites */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
	/* TODO: More params. More condition types. */
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   954
	uint8 param;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   955
	uint8 paramsize;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   956
	uint8 condtype;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   957
	uint8 numsprites;
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   958
	int param_val = 0, cond_val = 0;
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   959
	bool result;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   961
	check_length(len, 6, "SkipIf");
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   962
	param = buf[1];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   963
	paramsize = buf[2];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   964
	condtype = buf[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
359
5232542d89bc (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
   966
	if (condtype < 2) {
5232542d89bc (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
   967
		/* Always 1 for bit tests, the given value should
5232542d89bc (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
   968
		 * be ignored. */
5232542d89bc (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
   969
		paramsize = 1;
5232542d89bc (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
   970
	}
5232542d89bc (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
   971
5232542d89bc (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
   972
	buf += 4;
5232542d89bc (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
   973
	if (paramsize == 4)
5232542d89bc (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
   974
		cond_val = grf_load_dword(&buf);
5232542d89bc (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
   975
	else if (paramsize == 2)
5232542d89bc (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
   976
		cond_val = grf_load_word(&buf);
5232542d89bc (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
   977
	else if (paramsize == 1)
5232542d89bc (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
   978
		cond_val = grf_load_byte(&buf);
5232542d89bc (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
   979
5232542d89bc (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
   980
	switch (param) {
5232542d89bc (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
   981
		case 0x83:
5232542d89bc (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
   982
			param_val = _opt.landscape;
5232542d89bc (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
   983
			break;
5232542d89bc (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
   984
		case 0x84:
368
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
   985
			param_val = _cur_stage;
359
5232542d89bc (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
   986
			break;
363
2a01c271fe2d (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
   987
		case 0x85:
2a01c271fe2d (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
   988
			param_val = _ttdpatch_flags[cond_val / 0x20];
2a01c271fe2d (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
   989
			cond_val %= 0x20;
2a01c271fe2d (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
   990
			break;
359
5232542d89bc (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
   991
		case 0x86:
5232542d89bc (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
   992
			param_val = _opt.road_side << 4;
5232542d89bc (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
   993
			break;
366
05c09e262c8e (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
   994
		case 0x88: {
05c09e262c8e (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
   995
			struct GRFFile *file;
05c09e262c8e (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
   996
05c09e262c8e (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
   997
			file = GetFileByGRFID(cond_val);
05c09e262c8e (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
   998
			param_val = (file != NULL);
05c09e262c8e (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
   999
		}	break;
359
5232542d89bc (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
  1000
		default:
362
4bb825210268 (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
  1001
			if (param >= 0x80) {
4bb825210268 (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
  1002
				/* In-game variable. */
4bb825210268 (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
  1003
				grfmsg(GMS_WARN, "Unsupported in-game variable %x. Ignoring test.", param);
4bb825210268 (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
  1004
			} else {
4bb825210268 (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
  1005
				/* Parameter. */
4bb825210268 (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
  1006
				param_val = _paramlist[param];
4bb825210268 (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
  1007
			}
359
5232542d89bc (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
  1008
			return;
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1009
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1011
	switch (condtype) {
359
5232542d89bc (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
  1012
		case 0: result = (param_val & (1 << cond_val));
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1013
			break;
359
5232542d89bc (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
  1014
		case 1: result = !(param_val & (1 << cond_val));
5232542d89bc (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
  1015
			break;
5232542d89bc (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
  1016
		/* TODO: For the following, make it to work with paramsize>1. */
5232542d89bc (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
  1017
		case 2: result = (param_val == cond_val);
5232542d89bc (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
  1018
			break;
5232542d89bc (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
  1019
		case 3: result = (param_val != cond_val);
5232542d89bc (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
  1020
			break;
5232542d89bc (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
  1021
		case 4: result = (param_val < cond_val);
5232542d89bc (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
  1022
			break;
5232542d89bc (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
  1023
		case 5: result = (param_val > cond_val);
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1024
			break;
366
05c09e262c8e (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
  1025
		case 6: result = param_val; /* GRFID is active (only for param-num=88) */
05c09e262c8e (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
  1026
			break;
05c09e262c8e (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
  1027
		case 7: result = !param_val; /* GRFID is not active (only for param-num=88) */
05c09e262c8e (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
  1028
			break;
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1029
		default:
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1030
			grfmsg(GMS_WARN, "Unsupported test %d. Ignoring.", condtype);
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1031
			return;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1032
	}
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1033
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1034
	if (result == 0) {
359
5232542d89bc (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
  1035
		grfmsg(GMS_NOTICE, "Not skipping sprites, test was false.");
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1036
		return;
359
5232542d89bc (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
  1037
	}
5232542d89bc (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
  1038
5232542d89bc (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
  1039
	numsprites = grf_load_byte(&buf);
5232542d89bc (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
  1040
	grfmsg(GMS_NOTICE, "Skipping %d sprites, test was true.", numsprites);
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1041
	_skip_sprites = numsprites;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1042
	if (_skip_sprites == 0) {
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1043
		/* Zero means there are no sprites to skip, so
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1044
		 * we use -1 to indicate that all further
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1045
		 * sprites should be skipped. */
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1046
		_skip_sprites = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
static void GRFInfo(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
	/* <08> <version> <grf-id> <name> <info>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
	 * B version       newgrf version, currently 06
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1055
	 * 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
  1056
	 * S name          name of this .grf set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
	 * 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
  1058
	/* TODO: Check version. (We should have own versioning done somehow.) */
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1059
	uint8 version;
366
05c09e262c8e (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
  1060
	uint32 grfid;
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1061
	char *name;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1062
	char *info;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1064
	check_length(len, 9, "GRFInfo");
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1065
	version = buf[1];
366
05c09e262c8e (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
  1066
	/* this is de facto big endian - grf_load_dword() unsuitable */
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1067
	grfid = buf[2] << 24 | buf[3] << 16 | buf[4] << 8 | buf[5];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1068
	name = buf + 6;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1069
	info = name + strlen(name) + 1;
366
05c09e262c8e (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
  1070
05c09e262c8e (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
  1071
	_cur_grffile->grfid = grfid;
05c09e262c8e (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
  1072
	_cur_grffile->flags |= 0x0001; /* set active flag */
05c09e262c8e (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
  1073
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1074
	DEBUG(grf, 1) ("[%s] Loaded GRFv%d set %08lx - %s:\n%s\n",
366
05c09e262c8e (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
  1075
	               _cur_grffile->filename, version, grfid, name, info);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1078
static void SpriteReplace(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1080
	/* <0A> <num-sets> <set1> [<set2> ...]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
	 * <set>: <num-sprites> <first-sprite>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1082
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
	 * 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
  1084
	 * Each set:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
	 * 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
  1086
	 * W first-sprite  First sprite number to replace */
361
95307fb1c3f8 (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
  1087
	uint8 num_sets;
95307fb1c3f8 (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
  1088
	int i;
95307fb1c3f8 (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
  1089
95307fb1c3f8 (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
  1090
	buf++; /* skip action byte */
95307fb1c3f8 (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
  1091
	num_sets = grf_load_byte(&buf);
95307fb1c3f8 (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
  1092
95307fb1c3f8 (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
  1093
	if (num_sets > 16) {
95307fb1c3f8 (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
  1094
		grfmsg(GMS_ERROR, "SpriteReplace: Too many sets (%d), taking only the first 16!", num_sets);
95307fb1c3f8 (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
  1095
	}
95307fb1c3f8 (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
  1096
	
95307fb1c3f8 (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
  1097
	for (i = 0; i < 16; i++) {
95307fb1c3f8 (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
  1098
		if (i < num_sets) {
95307fb1c3f8 (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
  1099
			uint8 num_sprites = grf_load_byte(&buf);
95307fb1c3f8 (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
  1100
			uint16 first_sprite = grf_load_word(&buf);
95307fb1c3f8 (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
  1101
95307fb1c3f8 (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
  1102
			_replace_sprites_count[i] = num_sprites;
95307fb1c3f8 (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
  1103
			_replace_sprites_offset[i] = first_sprite;
95307fb1c3f8 (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
  1104
			grfmsg(GMS_NOTICE, "SpriteReplace: [Set %d] Changing %d sprites, beginning with %d",
95307fb1c3f8 (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
  1105
					i, num_sprites, first_sprite);
95307fb1c3f8 (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
  1106
		} else {
95307fb1c3f8 (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
  1107
			_replace_sprites_count[i] = 0;
95307fb1c3f8 (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
  1108
			_replace_sprites_offset[i] = 0;
95307fb1c3f8 (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
  1109
		}
95307fb1c3f8 (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
  1110
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
static void GRFError(byte *buf, int len)
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
	/* <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
  1116
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
	 * B severity      00: notice, contine loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
	 *                 01: warning, continue loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
	 *                 02: error, but continue loading grf file, and attempt
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
	 *                     loading grf again when loading or starting next game
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
	 *                 03: error, abort loading and prevent loading again in
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
	 *                     the future (only when restarting the patch)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
	 * 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
  1124
	 * B message-id    message to show, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
	 * 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
  1126
	 *                 not present for built-in messages.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
	 * 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
  1128
	 * 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
  1129
	/* 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
  1130
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
	static const char * const msgstr[4] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
		"Requires at least pseudo-TTDPatch version %s.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
		"This file is for %s version of TTD.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
		"Designed to be used with %s.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
		"Invalid parameter %s.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
	};
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1137
	uint8 severity;
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1138
	uint8 msgid;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1140
	check_length(len, 6, "GRFError");
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1141
	severity = buf[1];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1142
	msgid = buf[3];
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1143
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1144
	if (msgid == 0xFF) {
357
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1145
		grfmsg(severity, "%s", buf+4);
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1146
	} else {
5a92ba8a59e6 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1147
		grfmsg(severity, msgstr[msgid], buf+4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
static void GRFComment(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
	/* <0C> [<ignored...>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
	 * V ignored       Anything following the 0C is ignored */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
356
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1158
/* Action 0x0D */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
static void ParamSet(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
	/* <0D> <target> <operation> <source1> <source2> [<data>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1163
	 * B target        parameter number where result is stored
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
	 * B operation     operation to perform, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
	 * B source1       first source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
	 * B source2       second source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
	 * 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
  1168
	 *                 if both source1 and source2 refer to actual parameters
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1169
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
	 * Operations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
	 * 00      Set parameter equal to source1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
	 * 01      Addition, source1 + source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
	 * 02      Subtraction, source1 - source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
	 * 03      Unsigned multiplication, source1 * source2 (both unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
	 * 04      Signed multiplication, source1 * source2 (both signed)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
	 * 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
  1177
	 *         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
  1178
	 *         negative, source1 is unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
	 * 06      Signed bit shift, source1 by source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
	 *         (source2 like in 05, and source1 as well)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
	 */
362
4bb825210268 (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
  1182
4bb825210268 (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
  1183
	byte target;
4bb825210268 (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
  1184
	byte oper;
4bb825210268 (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
  1185
	uint16 src1;
4bb825210268 (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
  1186
	uint16 src2;
4bb825210268 (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
  1187
	uint16 data = 0;
4bb825210268 (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
  1188
4bb825210268 (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
  1189
	check_length(len, 5, "ParamSet");
4bb825210268 (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
  1190
	target = grf_load_byte(&buf);
4bb825210268 (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
  1191
	oper = grf_load_byte(&buf);
4bb825210268 (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
  1192
	src1 = grf_load_byte(&buf);
4bb825210268 (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
  1193
	src2 = grf_load_byte(&buf);
4bb825210268 (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
  1194
4bb825210268 (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
  1195
	if (len >= 8)
4bb825210268 (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
  1196
		data = grf_load_dword(&buf);
4bb825210268 (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
  1197
	
4bb825210268 (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
  1198
	/* You can add 80 to the operation to make it apply only if the target
4bb825210268 (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
  1199
	 * is not defined yet.  In this respect, a parameter is taken to be
4bb825210268 (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
  1200
	 * defined if any of the following applies:
4bb825210268 (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
  1201
	 * - it has been set to any value in the newgrf(w).cfg parameter list
4bb825210268 (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
  1202
	 * - it OR A PARAMETER WITH HIGHER NUMBER has been set to any value by
4bb825210268 (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
  1203
	 *   an earlier action D */
4bb825210268 (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
  1204
	if (oper & 0x80) {
4bb825210268 (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
  1205
		if (_param_max < target)
4bb825210268 (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
  1206
			oper &= 0x7F;
4bb825210268 (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
  1207
		else
4bb825210268 (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
  1208
			return;
4bb825210268 (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
  1209
	}
4bb825210268 (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
  1210
4bb825210268 (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
  1211
	/* The source1 and source2 operands refer to the grf parameter number
4bb825210268 (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
  1212
	 * like in action 6 and 7.  In addition, they can refer to the special
4bb825210268 (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
  1213
	 * variables available in action 7, or they can be FF to use the value
4bb825210268 (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
  1214
	 * of <data>.  If referring to parameters that are undefined, a value
4bb825210268 (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
  1215
	 * of 0 is used instead.  */
4bb825210268 (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
  1216
	if (src1 == 0xFF) {
4bb825210268 (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
  1217
		src1 = data;
4bb825210268 (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
  1218
	} else {
4bb825210268 (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
  1219
		src1 = _param_max >= src1 ? _paramlist[src1] : 0;
4bb825210268 (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
  1220
	}
4bb825210268 (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
  1221
4bb825210268 (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
  1222
	if (src2 == 0xFF) {
4bb825210268 (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
  1223
		src2 = data;
4bb825210268 (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
  1224
	} else {
4bb825210268 (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
  1225
		src2 = _param_max >= src2 ? _paramlist[src2] : 0;
4bb825210268 (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
  1226
	}
4bb825210268 (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
  1227
4bb825210268 (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
  1228
	/* TODO: You can access the parameters of another GRF file by using
4bb825210268 (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
  1229
	 * source2=FE, source1=the other GRF's parameter number and data=GRF
4bb825210268 (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
  1230
	 * ID.  This is only valid with operation 00 (set).  If the GRF ID
4bb825210268 (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
  1231
	 * cannot be found, a value of 0 is used for the parameter value
4bb825210268 (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
  1232
	 * instead. */
4bb825210268 (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
  1233
4bb825210268 (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
  1234
	/* TODO: The target operand can also refer to the special variables
4bb825210268 (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
  1235
	 * from action 7, but at the moment the only variable that is valid to
4bb825210268 (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
  1236
	 * write is 8E. */
4bb825210268 (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
  1237
4bb825210268 (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
  1238
	if (_param_max < target)
4bb825210268 (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
  1239
		_param_max = target;
4bb825210268 (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
  1240
4bb825210268 (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
  1241
	/* FIXME: No checking for overflows. */
4bb825210268 (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
  1242
	switch (oper) {
4bb825210268 (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
  1243
		case 0x00:
4bb825210268 (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
  1244
			_paramlist[target] = src1;
4bb825210268 (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
  1245
			break;
4bb825210268 (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
  1246
		case 0x01:
4bb825210268 (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
  1247
			_paramlist[target] = src1 + src2;
4bb825210268 (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
  1248
			break;
4bb825210268 (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
  1249
		case 0x02:
4bb825210268 (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
  1250
			_paramlist[target] = src1 - src2;
4bb825210268 (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
  1251
			break;
4bb825210268 (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
  1252
		case 0x03:
4bb825210268 (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
  1253
			_paramlist[target] = ((uint32) src1) * ((uint32) src2);
4bb825210268 (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
  1254
			break;
4bb825210268 (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
  1255
		case 0x04:
4bb825210268 (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
  1256
			_paramlist[target] = ((int32) src1) * ((int32) src2);
4bb825210268 (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
  1257
			break;
4bb825210268 (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
  1258
		case 0x05:
4bb825210268 (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
  1259
			if (src2 & 0x8000) /* src2 is "negative" */
4bb825210268 (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
  1260
				_paramlist[target] = src1 >> -((int16) src2);
4bb825210268 (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
  1261
			else
4bb825210268 (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
  1262
				_paramlist[target] = src1 << src2;
4bb825210268 (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
  1263
			break;
4bb825210268 (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
  1264
		case 0x06:
4bb825210268 (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
  1265
			if (src2 & 0x8000) /* src2 is "negative" */
4bb825210268 (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
  1266
				_paramlist[target] = ((int16) src1) >> -((int16) src2);
4bb825210268 (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
  1267
			else
4bb825210268 (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
  1268
				_paramlist[target] = ((int16) src1) << src2;
4bb825210268 (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
  1269
			break;
4bb825210268 (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
  1270
		default:
4bb825210268 (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
  1271
			grfmsg(GMS_ERROR, "ParamSet: Unknown operation %d, skipping.", oper);
4bb825210268 (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
  1272
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
static void GRFInhibit(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
	/* <0E> <num> <grfids...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1279
	 * B num           Number of GRFIDs that follow
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
	 * D grfids        GRFIDs of the files to deactivate */
367
99ab435a0484 (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
  1281
	/* XXX: Should we handle forward deactivations? */
99ab435a0484 (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
  1282
99ab435a0484 (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
  1283
	byte num;
99ab435a0484 (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
  1284
	int i;
99ab435a0484 (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
  1285
	
99ab435a0484 (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
  1286
	check_length(len, 1, "GRFInhibit");
99ab435a0484 (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
  1287
	num = grf_load_byte(&buf); len--;
99ab435a0484 (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
  1288
	check_length(len, 4 * num, "GRFInhibit");
99ab435a0484 (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
  1289
99ab435a0484 (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
  1290
	for (i = 0; i < num; i++) {
99ab435a0484 (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
  1291
		uint32 grfid = grf_load_dword(&buf);
99ab435a0484 (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
  1292
		struct GRFFile *file = GetFileByGRFID(grfid);
99ab435a0484 (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
  1293
99ab435a0484 (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
  1294
		/* Unset activation flag */
99ab435a0484 (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
  1295
		if (file != NULL) {
99ab435a0484 (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
  1296
			grfmsg(GMS_NOTICE, "GRFInhibit: Deactivating file ``%s''", file->filename);
99ab435a0484 (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
  1297
			file->flags &= 0xFFFE;
99ab435a0484 (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
  1298
		}
99ab435a0484 (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
  1299
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1301
363
2a01c271fe2d (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
  1302
2a01c271fe2d (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
  1303
static void InitializeGRFSpecial(void)
2a01c271fe2d (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
  1304
{
2a01c271fe2d (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
  1305
	/* FIXME: We should rather reflect reality in _ttdpatch_flags[]. */
2a01c271fe2d (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
  1306
2a01c271fe2d (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
  1307
	_ttdpatch_flags[1] = (1 << 0x08)	/* mammothtrains */
2a01c271fe2d (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
  1308
		| (1 << 0x0B)			/* subsidiaries */
2a01c271fe2d (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
  1309
		| (1 << 0x14)			/* bridgespeedlimits */
2a01c271fe2d (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
  1310
		| (1 << 0x16)			/* eternalgame */
2a01c271fe2d (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
  1311
		| (1 << 0x17)			/* newtrains */
2a01c271fe2d (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
  1312
		| (1 << 0x18)			/* newrvs */
2a01c271fe2d (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
  1313
		| (1 << 0x19)			/* newships */
2a01c271fe2d (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
  1314
		| (1 << 0x1A);		/* newplanes */
2a01c271fe2d (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
  1315
2a01c271fe2d (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
  1316
	_ttdpatch_flags[2] = (1 << 0x0D)	/* signalsontrafficside */
2a01c271fe2d (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
  1317
		| (1 << 0x16)			/* canals */
2a01c271fe2d (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
  1318
		| (1 << 0x17);		/* newstartyear */
2a01c271fe2d (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
  1319
}
2a01c271fe2d (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
  1320
368
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1321
void InitNewGRFFile(const char *filename, int sprite_offset)
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1322
{
366
05c09e262c8e (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
  1323
	struct GRFFile *newfile;
05c09e262c8e (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
  1324
05c09e262c8e (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
  1325
	newfile = malloc(sizeof(struct GRFFile));
05c09e262c8e (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
  1326
05c09e262c8e (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
  1327
	if (newfile == NULL)
05c09e262c8e (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
  1328
		error ("Out of memory");
05c09e262c8e (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
  1329
05c09e262c8e (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
  1330
	newfile->filename = strdup(filename);
05c09e262c8e (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
  1331
	newfile->grfid = 0;
05c09e262c8e (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
  1332
	newfile->flags = 0x0000;
05c09e262c8e (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
  1333
	newfile->sprite_offset = sprite_offset;
05c09e262c8e (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
  1334
	newfile->next = NULL;
05c09e262c8e (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
  1335
05c09e262c8e (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
  1336
	if (_first_grffile == NULL) {
05c09e262c8e (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
  1337
		_cur_grffile = newfile;
05c09e262c8e (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
  1338
		_first_grffile = newfile;
05c09e262c8e (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
  1339
	} else {
05c09e262c8e (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
  1340
		_cur_grffile->next = newfile;
05c09e262c8e (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
  1341
		_cur_grffile = newfile;
05c09e262c8e (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
  1342
	}
05c09e262c8e (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
  1343
}
05c09e262c8e (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
  1344
363
2a01c271fe2d (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
  1345
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1346
/* 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
  1347
 * described at http://www.ttdpatch.net/src/newgrf.txt, but this is only a very
368
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1348
 * partial implementation yet). */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1349
/* 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
  1350
 * 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
  1351
 * better make this more robust in the future. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
368
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1353
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
  1354
{
360
aeeee342efe0 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1355
#define NUM_ACTIONS 0xF
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1356
	static const SpecialSpriteHandler handlers[NUM_ACTIONS] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
		/* 0x0 */ VehicleChangeInfo,
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1358
		/* 0x1 */ NewSpriteSet,
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1359
		/* 0x2 */ NewSpriteGroup,
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1360
		/* 0x3 */ NewVehicle_SpriteGroupMapping,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
		/* 0x4 */ VehicleNewName,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
		/* 0x5 */ GraphicsNew,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1363
		/* 0x6 */ CfgApply,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1364
		/* 0x7 */ SkipIf,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
		/* 0x8 */ GRFInfo,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
		/* 0x9 */ SkipIf,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
		/* 0xa */ SpriteReplace,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1368
		/* 0xb */ GRFError,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1369
		/* 0xc */ GRFComment,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
		/* 0xd */ ParamSet,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
		/* 0xe */ GRFInhibit,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
	};
363
2a01c271fe2d (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
  1373
	static int initialized;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1374
	byte action;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1375
	byte *buf = malloc(num);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1376
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
356
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1378
	if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory");
9f69aeb8e617 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1379
372
ec1e802872c7 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1380
	if (initialized == 0) {
363
2a01c271fe2d (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
  1381
		InitializeGRFSpecial();
2a01c271fe2d (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
  1382
		initialized = 1;
2a01c271fe2d (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
  1383
	}
2a01c271fe2d (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
  1384
368
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1385
	_cur_stage = stage;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1386
	_cur_spriteid = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
	for (i = 0; i != num; i++)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
		buf[i] = FioReadByte();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
	action = buf[0];
368
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1392
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1393
	/* XXX: Action 0x03 is temporarily processed together with actions 0x01
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1394
	 * and 0x02 before it is fixed to be reentrant (probably storing the
369
3742b39b6cca (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1395
	 * group information in {struct GRFFile}). --pasky */
368
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1396
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1397
	if (stage == 0) {
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1398
		/* During initialization, actions 0, 3, 4, 5 and 7 are ignored. */
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1399
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1400
		if ((action == 0x00) /*|| (action == 0x03)*/ || (action == 0x04)
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1401
		    || (action == 0x05) || (action == 0x07)) {
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1402
			DEBUG (grf, 5) ("DecodeSpecialSprite: Action: %x, Stage 0, Skipped", action);
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1403
			/* Do nothing. */
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1404
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1405
		} else if (action < NUM_ACTIONS) {
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1406
			DEBUG (grf, 5) ("DecodeSpecialSprite: Action: %x, Stage 0", action);
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1407
 			handlers[action](buf, num);
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1408
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1409
		} else {
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1410
			grfmsg(GMS_WARN, "Unknown special sprite action %x, skipping.", action);
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1411
		}
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1412
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1413
	} else if (stage == 1) {
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1414
		/* A .grf file is activated only if it was active when the game was
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1415
		 * started.  If a game is loaded, only its active .grfs will be
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1416
		 * reactivated, unless "loadallgraphics on" is used.  A .grf file is
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1417
		 * considered active if its action 8 has been processed, i.e. its
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1418
		 * action 8 hasn't been skipped using an action 7.
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1419
		 *
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1420
		 * During activation, only actions 0, 3, 4, 5, 7, 8, 9 and 0A are
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1421
		 * carried out.  All others are ignored, because they only need to be
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1422
		 * processed once at initialization.  */
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1423
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1424
		if ((_cur_grffile == NULL) || strcmp(_cur_grffile->filename, filename))
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1425
			_cur_grffile = GetFileByFilename(filename);
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1426
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1427
		if (_cur_grffile == NULL)
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1428
			error("File ``%s'' lost in cache.\n", filename);
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1429
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1430
		if (!(_cur_grffile->flags & 0x0001)) {
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1431
			DEBUG (grf, 5) ("DecodeSpecialSprite: Action: %x, Stage 1, Not activated", action);
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1432
			/* Do nothing. */
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1433
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1434
		} else if ((action == 0x00) /*|| (action == 0x03)*/ || (action == 0x04) || (action == 0x05)
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1435
		           || (action == 0x07) || (action == 0x08) || (action == 0x09) || (action == 0x0A)) {
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1436
			DEBUG (grf, 5) ("DecodeSpecialSprite: Action: %x, Stage 1", action);
367
99ab435a0484 (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
  1437
			handlers[action](buf, num);
368
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1438
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1439
		} else if (action < NUM_ACTIONS) {
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1440
			DEBUG (grf, 5) ("DecodeSpecialSprite: Action: %x, Stage 1, Skipped", action);
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1441
			/* Do nothing. */
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1442
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1443
		} else {
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1444
			grfmsg(GMS_WARN, "Unknown special sprite action %x, skipping.", action);
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1445
		}
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1446
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
	} else {
368
3ad9aa36606c (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  1448
		error("Invalid stage %d", stage);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1449
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
	free(buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
#undef NUM_ACTIONS
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
}