author | celestar |
Sat, 13 Nov 2004 12:21:32 +0000 | |
changeset 372 | ec1e802872c7 |
parent 369 | 3742b39b6cca |
child 373 | 9eda1aad5f04 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
||
3 |
#include <stdarg.h> |
|
4 |
||
5 |
#include "ttd.h" |
|
6 |
#include "gfx.h" |
|
7 |
#include "fileio.h" |
|
8 |
#include "engine.h" |
|
9 |
||
10 |
/* TTDPatch extended GRF format codec |
|
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 | 14 |
* Contains portions of documentation by TTDPatch team. |
15 |
* Thanks especially to Josef Drexler for the documentation as well as a lot |
|
16 |
* of help at #tycoon. Also thanks to Michael Blunck for is GRF files which |
|
17 |
* served as subject to the initial testing of this codec. */ |
|
18 |
||
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 | 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 | 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 | 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 | 42 |
typedef void (*SpecialSpriteHandler)(byte *buf, int len); |
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 | 51 |
static const int _vehshifts[4] = { |
52 |
0, |
|
53 |
ROAD_ENGINES_INDEX, |
|
54 |
SHIP_ENGINES_INDEX, |
|
55 |
AIRCRAFT_ENGINES_INDEX, |
|
56 |
}; |
|
57 |
||
58 |
||
59 |
enum grfmsg_severity { |
|
60 |
GMS_NOTICE, |
|
61 |
GMS_WARN, |
|
62 |
GMS_ERROR, |
|
63 |
GMS_FATAL, |
|
64 |
}; |
|
65 |
||
66 |
static void CDECL grfmsg(enum grfmsg_severity severity, const char *str, ...) |
|
67 |
{ |
|
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 | 71 |
va_list va; |
72 |
||
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 | 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 | 79 |
} |
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 | 93 |
return *(*buf)++; |
94 |
} |
|
95 |
||
96 |
static uint16 grf_load_word(byte **buf) |
|
97 |
{ |
|
98 |
uint16 val; |
|
99 |
byte *p = *buf; |
|
100 |
val = p[0]; |
|
101 |
val |= p[1] << 8; |
|
102 |
*buf = p + 2; |
|
103 |
return val; |
|
104 |
} |
|
105 |
||
106 |
static uint16 grf_load_dword(byte **buf) |
|
107 |
{ |
|
108 |
uint32 val; |
|
109 |
byte *p = *buf; |
|
110 |
val = p[0]; |
|
111 |
val |= p[1] << 8; |
|
112 |
val |= p[2] << 16; |
|
113 |
val |= p[3] << 24; |
|
114 |
*buf = p + 4; |
|
115 |
return val; |
|
116 |
} |
|
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 | 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 | 145 |
|
146 |
static void dewagonize(int condition, int engine) |
|
147 |
{ |
|
148 |
EngineInfo *ei = &_engine_info[engine]; |
|
149 |
RailVehicleInfo *rvi = &_rail_vehicle_info[engine]; |
|
150 |
||
372
ec1e802872c7
(svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents:
369
diff
changeset
|
151 |
if (condition != 0) { |
0 | 152 |
ei->unk2 &= ~0x80; |
153 |
rvi->flags &= ~2; |
|
154 |
} else { |
|
155 |
ei->unk2 |= 0x80; |
|
156 |
rvi->flags |= 2; |
|
157 |
} |
|
158 |
} |
|
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 | 161 |
{ |
162 |
EngineInfo *ei = &_engine_info[engine]; |
|
163 |
RailVehicleInfo *rvi = &_rail_vehicle_info[engine]; |
|
164 |
byte *buf = *bufp; |
|
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 | 167 |
|
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 | 171 |
uint8 tracktype = grf_load_byte(&buf); |
172 |
||
173 |
ei[i].railtype_climates &= 0xf; |
|
174 |
ei[i].railtype_climates |= tracktype << 4; |
|
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 | 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 | 180 |
grf_load_byte(&buf); |
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 | 186 |
uint16 speed = grf_load_word(&buf); |
187 |
||
188 |
rvi[i].max_speed = speed; |
|
189 |
dewagonize(speed, engine + i); |
|
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 | 194 |
uint16 power = grf_load_word(&buf); |
195 |
||
196 |
rvi[i].power = power; |
|
197 |
dewagonize(power, engine + i); |
|
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 | 202 |
uint8 runcostfact = grf_load_byte(&buf); |
203 |
||
204 |
rvi[i].running_cost_base = runcostfact; |
|
205 |
dewagonize(runcostfact, engine + i); |
|
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 | 210 |
uint32 base = grf_load_dword(&buf); |
211 |
||
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 | 214 |
rvi[i].engclass = 0; |
215 |
break; |
|
360
aeeee342efe0
(svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents:
359
diff
changeset
|
216 |
case 0x4C36: |
0 | 217 |
rvi[i].engclass = 1; |
218 |
break; |
|
360
aeeee342efe0
(svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents:
359
diff
changeset
|
219 |
case 0x4C3C: |
0 | 220 |
rvi[i].engclass = 2; |
221 |
break; |
|
222 |
} |
|
223 |
dewagonize(base, engine + i); |
|
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 | 228 |
uint8 spriteid = grf_load_byte(&buf); |
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 | 231 |
_engine_original_sprites[engine + i] = rvi[i].image_index; |
232 |
rvi[i].image_index = spriteid; |
|
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 | 237 |
uint8 dual = grf_load_byte(&buf); |
238 |
||
372
ec1e802872c7
(svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents:
369
diff
changeset
|
239 |
if (dual != 0) { |
0 | 240 |
rvi[i].flags |= 1; |
241 |
} else { |
|
242 |
rvi[i].flags &= ~1; |
|
243 |
} |
|
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 | 248 |
uint8 capacity = grf_load_byte(&buf); |
249 |
||
250 |
rvi[i].capacity = capacity; |
|
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 | 255 |
uint8 ctype = grf_load_byte(&buf); |
256 |
||
257 |
rvi[i].cargo_type = ctype; |
|
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 | 262 |
uint8 weight = grf_load_byte(&buf); |
263 |
||
264 |
rvi[i].weight = weight; |
|
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 | 269 |
uint8 cfactor = grf_load_byte(&buf); |
270 |
||
271 |
rvi[i].base_cost = cfactor; |
|
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 | 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 | 277 |
grf_load_byte(&buf); |
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 | 282 |
/* TODO: What do the individual numbers mean? |
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 | 285 |
uint8 traction = grf_load_byte(&buf); |
286 |
int engclass; |
|
287 |
||
288 |
if (traction <= 0x07) |
|
289 |
engclass = 0; |
|
290 |
else if (traction <= 0x27) |
|
291 |
engclass = 1; |
|
292 |
else if (traction <= 0x31) |
|
293 |
engclass = 2; |
|
294 |
else |
|
295 |
break; |
|
296 |
||
297 |
rvi[i].engclass = engclass; |
|
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 | 301 |
/* TODO */ |
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 | 305 |
grf_load_word(&buf); |
306 |
} |
|
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 | 310 |
grf_load_byte(&buf); |
311 |
} |
|
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 | 317 |
case 0x21: /* Shorter tenders */ |
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 | 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 | 322 |
grf_load_byte(&buf); |
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 | 326 |
default: |
360
aeeee342efe0
(svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents:
359
diff
changeset
|
327 |
ret = true; |
0 | 328 |
} |
329 |
*bufp = buf; |
|
330 |
return ret; |
|
331 |
} |
|
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 | 334 |
{ |
335 |
ShipVehicleInfo *svi = &_ship_vehicle_info[engine]; |
|
336 |
byte *buf = *bufp; |
|
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 | 339 |
|
340 |
//printf("e %x prop %x?\n", engine, prop); |
|
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 | 344 |
uint8 spriteid = grf_load_byte(&buf); |
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 | 348 |
|
349 |
// This is currently not used but there's no reason |
|
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 | 354 |
svi[i].image_index = spriteid; |
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 | 359 |
uint8 refittable = grf_load_byte(&buf); |
360 |
||
361 |
svi[i].refittable = refittable; |
|
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 | 366 |
uint8 cost_factor = grf_load_byte(&buf); |
367 |
||
368 |
svi[i].base_cost = cost_factor; // ?? is it base_cost? |
|
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 | 373 |
uint8 speed = grf_load_byte(&buf); |
374 |
||
375 |
svi[i].max_speed = speed; // ?? units |
|
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 | 380 |
uint8 cargo = grf_load_byte(&buf); |
381 |
||
382 |
// XXX: Need to consult this with patchman yet. |
|
383 |
#if 0 |
|
384 |
// Documentation claims this is already the |
|
385 |
// per-landscape cargo type id, but newships.grf |
|
386 |
// assume otherwise. |
|
387 |
cargo = local_cargo_id_ctype[cargo]; |
|
388 |
#endif |
|
389 |
svi[i].cargo_type = cargo; |
|
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 | 394 |
uint16 capacity = grf_load_word(&buf); |
395 |
||
396 |
svi[i].capacity = capacity; |
|
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 | 401 |
uint8 runcost = grf_load_byte(&buf); |
402 |
||
403 |
svi[i].running_cost = runcost; |
|
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 | 408 |
uint8 sfx = grf_load_byte(&buf); |
409 |
||
410 |
svi[i].sfx = sfx; |
|
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 | 415 |
uint32 refit_mask = grf_load_dword(&buf); |
416 |
||
417 |
_engine_refit_masks[SHIP_ENGINES_INDEX + engine + i] = refit_mask; |
|
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 | 423 |
default: |
360
aeeee342efe0
(svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents:
359
diff
changeset
|
424 |
ret = true; |
0 | 425 |
} |
426 |
||
427 |
*bufp = buf; |
|
428 |
return ret; |
|
429 |
} |
|
430 |
||
431 |
#undef shift_buf |
|
432 |
||
356
9f69aeb8e617
(svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents:
193
diff
changeset
|
433 |
/* Action 0x00 */ |
0 | 434 |
static void VehicleChangeInfo(byte *buf, int len) |
435 |
{ |
|
436 |
byte *bufend = buf + len; |
|
437 |
int i; |
|
438 |
||
439 |
/* <00> <feature> <num-props> <num-info> <id> (<property <new-info>)... |
|
440 |
* |
|
441 |
* B feature 0, 1, 2 or 3 for trains, road vehicles, ships or planes |
|
442 |
* 4 for defining new train station sets |
|
443 |
* B num-props how many properties to change per vehicle/station |
|
444 |
* B num-info how many vehicles/stations to change |
|
445 |
* B id ID of first vehicle/station to change, if num-info is |
|
446 |
* greater than one, this one and the following |
|
447 |
* vehicles/stations will be changed |
|
448 |
* B property what property to change, depends on the feature |
|
449 |
* V new-info new bytes of info (variable size; depends on properties) */ |
|
450 |
/* TODO: Only trains and ships are supported for now. */ |
|
451 |
||
452 |
static const VCI_Handler handler[5] = { |
|
453 |
RailVehicleChangeInfo, |
|
454 |
NULL, |
|
455 |
ShipVehicleChangeInfo, |
|
456 |
NULL, |
|
457 |
NULL, |
|
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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 541 |
} |
542 |
} |
|
543 |
#undef shift_buf |
|
544 |
} |
|
545 |
||
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 | 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 | 550 |
* contributing to the global confusion. |
551 |
* |
|
552 |
* A sprite set contains all sprites of a given vehicle carrying given cargo at |
|
553 |
* a given *stage* - that is usually its load stage. Ie. you can have a |
|
554 |
* spriteset for an empty wagon, wagon full of coal, half-filled wagon etc. |
|
555 |
* Each spriteset contains eight sprites (one per direction) or four sprites if |
|
556 |
* the vehicle is symmetric. */ |
|
557 |
||
558 |
static int _spriteset_start; |
|
559 |
static int _spriteset_numsets; |
|
560 |
static int _spriteset_numents; |
|
561 |
static int _spriteset_feature; |
|
562 |
||
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 | 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 | 568 |
{ |
569 |
/* <01> <feature> <num-sets> <num-ent> |
|
570 |
* |
|
571 |
* B feature feature to define sprites for |
|
572 |
* 0, 1, 2, 3: veh-type, 4: train stations |
|
573 |
* B num-sets number of sprite sets |
|
574 |
* B num-ent how many entries per sprite set |
|
575 |
* For vehicles, this is the number of different |
|
576 |
* vehicle directions in each sprite set |
|
577 |
* Set num-dirs=8, unless your sprites are symmetric. |
|
578 |
* In that case, use num-dirs=4. |
|
579 |
* For stations, must be 12 (hex) for the eighteen |
|
580 |
* different sprites that make up a station */ |
|
581 |
/* TODO: No stations support. */ |
|
357
5a92ba8a59e6
(svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents:
356
diff
changeset
|
582 |
uint8 feature; |
0 | 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 | 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 | 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 | 597 |
} |
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 | 601 |
{ |
602 |
byte *bufend = buf + len; |
|
603 |
||
604 |
/* <02> <feature> <set-id> <type/num-entries> <feature-specific-data...> |
|
605 |
* |
|
606 |
* B feature see action 1 |
|
607 |
* B set-id ID of this particular definition |
|
608 |
* B type/num-entries |
|
609 |
* if 80 or greater, this is a randomized or variational |
|
610 |
* list definition, see below |
|
611 |
* otherwise it specifies a number of entries, the exact |
|
612 |
* meaning depends on the feature |
|
613 |
* V feature-specific-data (huge mess, don't even look it up --pasky) */ |
|
614 |
/* TODO: Only trains supported now. No 0x80-types (ugh). */ |
|
615 |
/* TODO: Also, empty sprites aren't handled for now. Need to investigate |
|
616 |
* the "opacity" rules for these, that is which sprite to fall back to |
|
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 | 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 | 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 | 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 | 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 | 658 |
if (setid >= _spritesset_count) { |
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 | 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 | 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 | 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 | 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 | 722 |
} |
723 |
} |
|
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 | 727 |
{ |
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 | 731 |
* |
732 |
* B feature see action 0 |
|
733 |
* B n-id bits 0-6: how many IDs this definition applies to |
|
734 |
* bit 7: if set, this is a wagon override definition (see below) |
|
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 | 737 |
* can be zero, in that case the def-cid is used always |
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 | 741 |
/* TODO: Only trains supported now. */ |
742 |
/* TODO: Multiple cargo support could be useful even for trains/cars - |
|
743 |
* cargo id 0xff is used for showing images in the build train list. */ |
|
744 |
||
745 |
static byte *last_engines; |
|
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 | 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 | 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 | 829 |
} |
357
5a92ba8a59e6
(svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents:
356
diff
changeset
|
830 |
} |
0 | 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 | 835 |
|
836 |
for (i = 0; i < idcount; i++) { |
|
837 |
uint8 engine = buf[3 + i] + _vehshifts[feature]; |
|
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 | 843 |
} |
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 | 851 |
} |
852 |
} |
|
853 |
} |
|
854 |
} |
|
855 |
||
356
9f69aeb8e617
(svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents:
193
diff
changeset
|
856 |
/* Action 0x04 */ |
0 | 857 |
static void VehicleNewName(byte *buf, int len) |
858 |
{ |
|
859 |
/* <04> <veh-type> <language-id> <num-veh> <offset> <data...> |
|
860 |
* |
|
861 |
* B veh-type see action 0 |
|
862 |
* B language-id language ID with bit 7 cleared (see below) |
|
863 |
* B num-veh number of vehicles which are getting a new name |
|
864 |
* B offset number of the first vehicle that gets a new name |
|
865 |
* S data new texts, each of them zero-terminated, after |
|
866 |
* which the next name begins. */ |
|
867 |
/* TODO: No support for changing non-vehicle text. Perhaps we shouldn't |
|
868 |
* implement it at all, but it could be useful for some "modpacks" |
|
869 |
* (completely new scenarios changing all graphics and logically also |
|
870 |
* factory names etc). We should then also support all languages (by |
|
871 |
* name), not only the original four ones. --pasky */ |
|
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 | 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 | 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 | 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 | 901 |
} |
902 |
} |
|
903 |
||
356
9f69aeb8e617
(svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents:
193
diff
changeset
|
904 |
/* Action 0x05 */ |
0 | 905 |
static void GraphicsNew(byte *buf, int len) |
906 |
{ |
|
907 |
/* <05> <graphics-type> <num-sprites> <other data...> |
|
908 |
* |
|
909 |
* B graphics-type What set of graphics the sprites define. |
|
910 |
* B num-sprites How many sprites are in this set? |
|
911 |
* V other data Graphics type specific data. Currently unused. */ |
|
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 | 923 |
} |
924 |
||
356
9f69aeb8e617
(svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents:
193
diff
changeset
|
925 |
/* Action 0x06 */ |
0 | 926 |
static void CfgApply(byte *buf, int len) |
927 |
{ |
|
928 |
/* <06> <param-num> <param-size> <offset> ... <FF> |
|
929 |
* |
|
930 |
* B param-num Number of parameter to substitute (First = "zero") |
|
931 |
* Ignored if that parameter was not specified in newgrf.cfg |
|
932 |
* B param-size How many bytes to replace. If larger than 4, the |
|
933 |
* bytes of the following parameter are used. In that |
|
934 |
* case, nothing is applied unless *all* parameters |
|
935 |
* were specified. |
|
936 |
* B offset Offset into data from beginning of next sprite |
|
937 |
* to place where parameter is to be stored. */ |
|
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 | 940 |
} |
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 | 944 |
static void SkipIf(byte *buf, int len) |
945 |
{ |
|
946 |
/* <07/09> <param-num> <param-size> <condition-type> <value> <num-sprites> |
|
947 |
* |
|
948 |
* B param-num |
|
949 |
* B param-size |
|
950 |
* B condition-type |
|
951 |
* V value |
|
952 |
* B num-sprites */ |
|
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 | 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 | 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 | 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 | 1047 |
} |
1048 |
} |
|
1049 |
||
1050 |
static void GRFInfo(byte *buf, int len) |
|
1051 |
{ |
|
1052 |
/* <08> <version> <grf-id> <name> <info> |
|
1053 |
* |
|
1054 |
* B version newgrf version, currently 06 |
|
1055 |
* 4*B grf-id globally unique ID of this .grf file |
|
1056 |
* S name name of this .grf set |
|
1057 |
* S info string describing the set, and e.g. author and copyright */ |
|
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 | 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 | 1076 |
} |
1077 |
||
1078 |
static void SpriteReplace(byte *buf, int len) |
|
1079 |
{ |
|
1080 |
/* <0A> <num-sets> <set1> [<set2> ...] |
|
1081 |
* <set>: <num-sprites> <first-sprite> |
|
1082 |
* |
|
1083 |
* B num-sets How many sets of sprites to replace. |
|
1084 |
* Each set: |
|
1085 |
* B num-sprites How many sprites are in this set |
|
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 | 1111 |
} |
1112 |
||
1113 |
static void GRFError(byte *buf, int len) |
|
1114 |
{ |
|
1115 |
/* <0B> <severity> <language-id> <message-id> [<message...> 00] [<data...>] 00 [<parnum>] |
|
1116 |
* |
|
1117 |
* B severity 00: notice, contine loading grf file |
|
1118 |
* 01: warning, continue loading grf file |
|
1119 |
* 02: error, but continue loading grf file, and attempt |
|
1120 |
* loading grf again when loading or starting next game |
|
1121 |
* 03: error, abort loading and prevent loading again in |
|
1122 |
* the future (only when restarting the patch) |
|
1123 |
* B language-id see action 4, use 1F for built-in error messages |
|
1124 |
* B message-id message to show, see below |
|
1125 |
* S message for custom messages (message-id FF), text of the message |
|
1126 |
* not present for built-in messages. |
|
1127 |
* V data additional data for built-in (or custom) messages |
|
1128 |
* B parnum see action 6, only used with built-in message 03 */ |
|
1129 |
/* TODO: For now we just show the message, sometimes incomplete and never translated. */ |
|
1130 |
||
1131 |
static const char * const msgstr[4] = { |
|
1132 |
"Requires at least pseudo-TTDPatch version %s.", |
|
1133 |
"This file is for %s version of TTD.", |
|
1134 |
"Designed to be used with %s.", |
|
1135 |
"Invalid parameter %s.", |
|
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 | 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 | 1148 |
} |
1149 |
} |
|
1150 |
||
1151 |
static void GRFComment(byte *buf, int len) |
|
1152 |
{ |
|
1153 |
/* <0C> [<ignored...>] |
|
1154 |
* |
|
1155 |
* V ignored Anything following the 0C is ignored */ |
|
1156 |
} |
|
1157 |
||
356
9f69aeb8e617
(svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents:
193
diff
changeset
|
1158 |
/* Action 0x0D */ |
0 | 1159 |
static void ParamSet(byte *buf, int len) |
1160 |
{ |
|
1161 |
/* <0D> <target> <operation> <source1> <source2> [<data>] |
|
1162 |
* |
|
1163 |
* B target parameter number where result is stored |
|
1164 |
* B operation operation to perform, see below |
|
1165 |
* B source1 first source operand |
|
1166 |
* B source2 second source operand |
|
1167 |
* D data data to use in the calculation, not necessary |
|
1168 |
* if both source1 and source2 refer to actual parameters |
|
1169 |
* |
|
1170 |
* Operations |
|
1171 |
* 00 Set parameter equal to source1 |
|
1172 |
* 01 Addition, source1 + source2 |
|
1173 |
* 02 Subtraction, source1 - source2 |
|
1174 |
* 03 Unsigned multiplication, source1 * source2 (both unsigned) |
|
1175 |
* 04 Signed multiplication, source1 * source2 (both signed) |
|
1176 |
* 05 Unsigned bit shift, source1 by source2 (source2 taken to be a |
|
1177 |
* signed quantity; left shift if positive and right shift if |
|
1178 |
* negative, source1 is unsigned) |
|
1179 |
* 06 Signed bit shift, source1 by source2 |
|
1180 |
* (source2 like in 05, and source1 as well) |
|
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 | 1273 |
} |
1274 |
||
1275 |
static void GRFInhibit(byte *buf, int len) |
|
1276 |
{ |
|
1277 |
/* <0E> <num> <grfids...> |
|
1278 |
* |
|
1279 |
* B num Number of GRFIDs that follow |
|
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 | 1300 |
} |
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 | 1346 |
/* Here we perform initial decoding of some special sprites (as are they |
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 | 1349 |
/* XXX: We consider GRF files trusted. It would be trivial to exploit OTTD by |
1350 |
* a crafted invalid GRF file. We should tell that to the user somehow, or |
|
1351 |
* better make this more robust in the future. */ |
|
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 | 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 | 1356 |
static const SpecialSpriteHandler handlers[NUM_ACTIONS] = { |
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 | 1361 |
/* 0x4 */ VehicleNewName, |
1362 |
/* 0x5 */ GraphicsNew, |
|
1363 |
/* 0x6 */ CfgApply, |
|
1364 |
/* 0x7 */ SkipIf, |
|
1365 |
/* 0x8 */ GRFInfo, |
|
1366 |
/* 0x9 */ SkipIf, |
|
1367 |
/* 0xa */ SpriteReplace, |
|
1368 |
/* 0xb */ GRFError, |
|
1369 |
/* 0xc */ GRFComment, |
|
1370 |
/* 0xd */ ParamSet, |
|
1371 |
/* 0xe */ GRFInhibit, |
|
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 | 1374 |
byte action; |
1375 |
byte *buf = malloc(num); |
|
1376 |
int i; |
|
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 | 1386 |
_cur_spriteid = spriteid; |
1387 |
||
1388 |
for (i = 0; i != num; i++) |
|
1389 |
buf[i] = FioReadByte(); |
|
1390 |
||
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 | 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 | 1449 |
} |
1450 |
||
1451 |
free(buf); |
|
1452 |
#undef NUM_ACTIONS |
|
1453 |
} |