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