author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1539 | b3fce185178a |
child 1559 | c0d5d35b25db |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1197
diff
changeset
|
3 |
#include "debug.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
485
diff
changeset
|
4 |
#include "table/strings.h" |
0 | 5 |
#include "engine.h" |
6 |
#include "table/engines.h" |
|
1009
75140dc68759
(svn r1508) Remove duplicate declarations and include proper headers where necessary
tron
parents:
964
diff
changeset
|
7 |
#include "gfx.h" |
0 | 8 |
#include "player.h" |
9 |
#include "command.h" |
|
10 |
#include "vehicle.h" |
|
11 |
#include "news.h" |
|
12 |
#include "saveload.h" |
|
405
415546028e8d
(svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents:
369
diff
changeset
|
13 |
#include "sprite.h" |
0 | 14 |
|
15 |
#define UPDATE_PLAYER_RAILTYPE(e,p) if ((byte)(e->railtype + 1) > p->max_railtype) p->max_railtype = e->railtype + 1; |
|
16 |
||
17 |
enum { |
|
18 |
ENGINE_AVAILABLE = 1, |
|
19 |
ENGINE_INTRODUCING = 2, |
|
20 |
ENGINE_PREVIEWING = 4, |
|
21 |
}; |
|
22 |
||
23 |
/* This maps per-landscape cargo ids to globally unique cargo ids usable ie. in |
|
24 |
* the custom GRF files. It is basically just a transcribed table from |
|
25 |
* TTDPatch's newgrf.txt. */ |
|
26 |
byte _global_cargo_id[NUM_LANDSCAPE][NUM_CARGO] = { |
|
27 |
/* LT_NORMAL */ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12 }, |
|
28 |
/* LT_HILLY */ { 0, 1, 2, 3, 4, 5, 6, 7, 28, 11, 10, 12 }, |
|
29 |
/* LT_DESERT */ { 0, 16, 2, 3, 13, 5, 6, 7, 14, 15, 10, 12 }, |
|
30 |
/* LT_CANDY */ { 0, 17, 2, 18, 19, 20, 21, 22, 23, 24, 25, 26 }, |
|
31 |
// 27 is paper in temperate climate in TTDPatch |
|
32 |
// Following can be renumbered: |
|
33 |
// 29 is the default cargo for the purpose of spritesets |
|
34 |
// 30 is the purchase list image (the equivalent of 0xff) for the purpose of spritesets |
|
35 |
}; |
|
36 |
||
37 |
/* These two arrays provide a reverse mapping. */ |
|
38 |
byte _local_cargo_id_ctype[NUM_CID] = { |
|
39 |
CT_PASSENGERS, CT_COAL, CT_MAIL, CT_OIL, CT_LIVESTOCK, CT_GOODS, CT_GRAIN, CT_WOOD, // 0-7 |
|
40 |
CT_IRON_ORE, CT_STEEL, CT_VALUABLES, CT_PAPER, CT_FOOD, CT_FRUIT, CT_COPPER_ORE, CT_WATER, // 8-15 |
|
41 |
CT_RUBBER, CT_SUGAR, CT_TOYS, CT_BATTERIES, CT_CANDY, CT_TOFFEE, CT_COLA, CT_COTTON_CANDY, // 16-23 |
|
42 |
CT_BUBBLES, CT_PLASTIC, CT_FIZZY_DRINKS, CT_PAPER /* unsup. */, CT_HILLY_UNUSED // 24-28 |
|
43 |
}; |
|
44 |
||
45 |
/* LT'th bit is set of the particular landscape if cargo available there. |
|
46 |
* 1: LT_NORMAL, 2: LT_HILLY, 4: LT_DESERT, 8: LT_CANDY */ |
|
47 |
byte _local_cargo_id_landscape[NUM_CID] = { |
|
48 |
15, 3, 15, 7, 3, 7, 7, 7, 1, 1, 7, 2, 7, // 0-12 |
|
49 |
4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 1, 2, // 13-28 |
|
50 |
}; |
|
51 |
||
52 |
void ShowEnginePreviewWindow(int engine); |
|
53 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
54 |
void DeleteCustomEngineNames(void) |
0 | 55 |
{ |
56 |
uint i; |
|
57 |
StringID old; |
|
58 |
||
1474
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
59 |
for (i = 0; i != TOTAL_NUM_ENGINES; i++) { |
0 | 60 |
old = _engine_name_strings[i]; |
61 |
_engine_name_strings[i] = i + STR_8000_KIRBY_PAUL_TANK_STEAM; |
|
62 |
DeleteName(old); |
|
63 |
} |
|
64 |
||
65 |
_vehicle_design_names &= ~1; |
|
66 |
} |
|
67 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
68 |
void LoadCustomEngineNames(void) |
0 | 69 |
{ |
70 |
// XXX: not done */ |
|
71 |
DEBUG(misc, 1) ("LoadCustomEngineNames: not done"); |
|
72 |
} |
|
73 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
74 |
static void SetupEngineNames(void) |
0 | 75 |
{ |
1474
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
76 |
StringID *name; |
0 | 77 |
|
1474
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
78 |
for (name = _engine_name_strings; name != endof(_engine_name_strings); name++) |
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
79 |
*name = STR_SV_EMPTY; |
0 | 80 |
|
81 |
DeleteCustomEngineNames(); |
|
82 |
LoadCustomEngineNames(); |
|
83 |
} |
|
84 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
85 |
static void AdjustAvailAircraft(void) |
0 | 86 |
{ |
87 |
uint16 date = _date; |
|
88 |
byte avail = 0; |
|
89 |
if (date >= 12784) avail |= 2; // big airport |
|
90 |
if (date < 14610 || _patches.always_small_airport) avail |= 1; // small airport |
|
91 |
if (date >= 15706) avail |= 4; // enable heliport |
|
92 |
||
93 |
if (avail != _avail_aircraft) { |
|
94 |
_avail_aircraft = avail; |
|
95 |
InvalidateWindow(WC_BUILD_STATION, 0); |
|
96 |
} |
|
97 |
} |
|
98 |
||
99 |
static void CalcEngineReliability(Engine *e) |
|
100 |
{ |
|
101 |
uint age = e->age; |
|
102 |
||
103 |
if (age < e->duration_phase_1) { |
|
104 |
uint start = e->reliability_start; |
|
105 |
e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start; |
|
106 |
} else if ((age -= e->duration_phase_1) < e->duration_phase_2) { |
|
107 |
e->reliability = e->reliability_max; |
|
108 |
} else if ((age -= e->duration_phase_2) < e->duration_phase_3) { |
|
109 |
uint max = e->reliability_max; |
|
110 |
e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max; |
|
111 |
} else { |
|
292
16c136eaffcb
(svn r298) Fix: Engines from other climates do not appear any more when never_expire_vehicles is enabled
dominik
parents:
257
diff
changeset
|
112 |
// time's up for this engine |
16c136eaffcb
(svn r298) Fix: Engines from other climates do not appear any more when never_expire_vehicles is enabled
dominik
parents:
257
diff
changeset
|
113 |
// make it either available to all players (if never_expire_vehicles is enabled and if it was available earlier) |
16c136eaffcb
(svn r298) Fix: Engines from other climates do not appear any more when never_expire_vehicles is enabled
dominik
parents:
257
diff
changeset
|
114 |
// or disable this engine completely |
16c136eaffcb
(svn r298) Fix: Engines from other climates do not appear any more when never_expire_vehicles is enabled
dominik
parents:
257
diff
changeset
|
115 |
e->player_avail = (_patches.never_expire_vehicles && e->player_avail)? -1 : 0; |
0 | 116 |
e->reliability = e->reliability_final; |
117 |
} |
|
118 |
} |
|
119 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
120 |
void AddTypeToEngines(void) |
842 | 121 |
{ |
122 |
Engine *e; |
|
123 |
uint32 counter = 0; |
|
915 | 124 |
|
842 | 125 |
for(e=_engines; e != endof(_engines); e++, counter++) { |
126 |
||
127 |
e->type = VEH_Train; |
|
128 |
if (counter >= ROAD_ENGINES_INDEX) { |
|
129 |
e->type = VEH_Road; |
|
130 |
if (counter >= SHIP_ENGINES_INDEX) { |
|
131 |
e->type = VEH_Ship; |
|
132 |
if (counter >= AIRCRAFT_ENGINES_INDEX) { |
|
133 |
e->type = VEH_Aircraft; |
|
134 |
if (counter >= TOTAL_NUM_ENGINES) { |
|
135 |
e->type = VEH_Special; |
|
136 |
} |
|
137 |
} |
|
138 |
} |
|
139 |
} |
|
140 |
} |
|
141 |
} |
|
142 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
143 |
void StartupEngines(void) |
0 | 144 |
{ |
145 |
Engine *e; |
|
146 |
const EngineInfo *ei; |
|
819
c425b7e22f6a
(svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents:
740
diff
changeset
|
147 |
uint32 r, counter = 0; |
0 | 148 |
|
149 |
SetupEngineNames(); |
|
150 |
||
842 | 151 |
for(e=_engines, ei=_engine_info; e != endof(_engines); e++, ei++, counter++) { |
0 | 152 |
|
153 |
e->age = 0; |
|
154 |
e->railtype = ei->railtype_climates >> 4; |
|
155 |
e->flags = 0; |
|
156 |
e->player_avail = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
157 |
|
0 | 158 |
r = Random(); |
159 |
e->intro_date = (uint16)((r & 0x1FF) + ei->base_intro); |
|
160 |
if (e->intro_date <= _date) { |
|
161 |
e->age = (_date - e->intro_date) >> 5; |
|
162 |
e->player_avail = (byte)-1; |
|
163 |
e->flags |= ENGINE_AVAILABLE; |
|
164 |
} |
|
165 |
||
166 |
e->reliability_start = (uint16)(((r >> 16) & 0x3fff) + 0x7AE0); |
|
167 |
r = Random(); |
|
168 |
e->reliability_max = (uint16)((r & 0x3fff) + 0xbfff); |
|
169 |
e->reliability_final = (uint16)(((r>>16) & 0x3fff) + 0x3fff); |
|
170 |
||
171 |
r = Random(); |
|
172 |
e->duration_phase_1 = (uint16)((r & 0x1F) + 7); |
|
173 |
e->duration_phase_2 = (uint16)(((r >> 5) & 0xF) + ei->base_life * 12 - 96); |
|
174 |
e->duration_phase_3 = (uint16)(((r >> 9) & 0x7F) + 120); |
|
175 |
||
176 |
e->reliability_spd_dec = (ei->unk2&0x7F) << 2; |
|
177 |
||
178 |
/* my invented flag for something that is a wagon */ |
|
179 |
if (ei->unk2 & 0x80) { |
|
180 |
e->age = 0xFFFF; |
|
181 |
} else { |
|
182 |
CalcEngineReliability(e); |
|
183 |
} |
|
184 |
||
185 |
e->lifelength = ei->lifelength + _patches.extend_vehicle_life; |
|
186 |
||
187 |
// prevent certain engines from ever appearing. |
|
188 |
if (!HASBIT(ei->railtype_climates, _opt.landscape)) { |
|
189 |
e->flags |= ENGINE_AVAILABLE; |
|
190 |
e->player_avail = 0; |
|
191 |
} |
|
915 | 192 |
|
819
c425b7e22f6a
(svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents:
740
diff
changeset
|
193 |
/* This sets up type for the engine |
c425b7e22f6a
(svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents:
740
diff
changeset
|
194 |
It is needed if you want to ask the engine what type it is |
c425b7e22f6a
(svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents:
740
diff
changeset
|
195 |
It should hopefully be the same as when you ask a vehicle what it is |
c425b7e22f6a
(svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents:
740
diff
changeset
|
196 |
but using this, you can ask what type an engine number is |
c425b7e22f6a
(svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents:
740
diff
changeset
|
197 |
even if it is not a vehicle (yet)*/ |
0 | 198 |
} |
199 |
||
200 |
AdjustAvailAircraft(); |
|
201 |
} |
|
202 |
||
1474
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
203 |
uint32 _engine_refit_masks[TOTAL_NUM_ENGINES]; |
0 | 204 |
|
205 |
||
206 |
// TODO: We don't support cargo-specific wagon overrides. Pretty exotic... ;-) --pasky |
|
207 |
||
1477 | 208 |
typedef struct WagonOverride { |
0 | 209 |
byte *train_id; |
210 |
int trains; |
|
1477 | 211 |
SpriteGroup group; |
212 |
} WagonOverride; |
|
0 | 213 |
|
1477 | 214 |
typedef struct WagonOverrides { |
0 | 215 |
int overrides_count; |
1477 | 216 |
WagonOverride *overrides; |
217 |
} WagonOverrides; |
|
0 | 218 |
|
1477 | 219 |
static WagonOverrides _engine_wagon_overrides[TOTAL_NUM_ENGINES]; |
220 |
||
221 |
void SetWagonOverrideSprites(byte engine, SpriteGroup *group, byte *train_id, |
|
222 |
int trains) |
|
0 | 223 |
{ |
1477 | 224 |
WagonOverrides *wos; |
225 |
WagonOverride *wo; |
|
0 | 226 |
|
227 |
wos = &_engine_wagon_overrides[engine]; |
|
228 |
wos->overrides_count++; |
|
229 |
wos->overrides = realloc(wos->overrides, |
|
1477 | 230 |
wos->overrides_count * sizeof(*wos->overrides)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
231 |
|
0 | 232 |
wo = &wos->overrides[wos->overrides_count - 1]; |
408
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
233 |
/* FIXME: If we are replacing an override, release original SpriteGroup |
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
234 |
* to prevent leaks. But first we need to refcount the SpriteGroup. |
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
235 |
* --pasky */ |
369
3742b39b6cca
(svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents:
292
diff
changeset
|
236 |
wo->group = *group; |
0 | 237 |
wo->trains = trains; |
238 |
wo->train_id = malloc(trains); |
|
239 |
memcpy(wo->train_id, train_id, trains); |
|
240 |
} |
|
241 |
||
1477 | 242 |
static SpriteGroup *GetWagonOverrideSpriteSet(byte engine, byte overriding_engine) |
0 | 243 |
{ |
1477 | 244 |
WagonOverrides *wos = &_engine_wagon_overrides[engine]; |
0 | 245 |
int i; |
246 |
||
408
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
247 |
// XXX: This could turn out to be a timesink on profiles. We could |
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
248 |
// always just dedicate 65535 bytes for an [engine][train] trampoline |
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
249 |
// for O(1). Or O(logMlogN) and searching binary tree or smt. like |
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
250 |
// that. --pasky |
0 | 251 |
|
252 |
for (i = 0; i < wos->overrides_count; i++) { |
|
1477 | 253 |
WagonOverride *wo = &wos->overrides[i]; |
0 | 254 |
int j; |
255 |
||
256 |
for (j = 0; j < wo->trains; j++) { |
|
257 |
if (wo->train_id[j] == overriding_engine) |
|
369
3742b39b6cca
(svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents:
292
diff
changeset
|
258 |
return &wo->group; |
0 | 259 |
} |
260 |
} |
|
261 |
return NULL; |
|
262 |
} |
|
263 |
||
264 |
||
1474
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
265 |
byte _engine_original_sprites[TOTAL_NUM_ENGINES]; |
0 | 266 |
// 0 - 28 are cargos, 29 is default, 30 is the advert (purchase list) |
267 |
// (It isn't and shouldn't be like this in the GRF files since new cargo types |
|
268 |
// may appear in future - however it's more convenient to store it like this in |
|
269 |
// memory. --pasky) |
|
1477 | 270 |
static SpriteGroup _engine_custom_sprites[TOTAL_NUM_ENGINES][NUM_CID]; |
0 | 271 |
|
1477 | 272 |
void SetCustomEngineSprites(byte engine, byte cargo, SpriteGroup *group) |
0 | 273 |
{ |
408
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
274 |
/* FIXME: If we are replacing an override, release original SpriteGroup |
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
275 |
* to prevent leaks. But first we need to refcount the SpriteGroup. |
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
276 |
* --pasky */ |
369
3742b39b6cca
(svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents:
292
diff
changeset
|
277 |
_engine_custom_sprites[engine][cargo] = *group; |
0 | 278 |
} |
279 |
||
1477 | 280 |
typedef RealSpriteGroup *(*resolve_callback)(SpriteGroup *spritegroup, |
281 |
const Vehicle *veh, void *callback); /* XXX data pointer used as function pointer */ |
|
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
282 |
|
1477 | 283 |
static RealSpriteGroup* ResolveVehicleSpriteGroup(SpriteGroup *spritegroup, |
284 |
const Vehicle *veh, resolve_callback callback) |
|
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
285 |
{ |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
286 |
//debug("spgt %d", spritegroup->type); |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
287 |
switch (spritegroup->type) { |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
288 |
case SGT_REAL: |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
289 |
return &spritegroup->g.real; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
290 |
|
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
291 |
case SGT_DETERMINISTIC: { |
1477 | 292 |
DeterministicSpriteGroup *dsg = &spritegroup->g.determ; |
293 |
SpriteGroup *target; |
|
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
294 |
int value = -1; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
295 |
|
433
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
296 |
//debug("[%p] Having fun resolving variable %x", veh, dsg->variable); |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
297 |
|
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
298 |
if ((dsg->variable >> 6) == 0) { |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
299 |
/* General property */ |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
300 |
value = GetDeterministicSpriteValue(dsg->variable); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
301 |
} else { |
433
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
302 |
/* Vehicle-specific property. */ |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
303 |
|
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
304 |
if (veh == NULL) { |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
305 |
/* We are in a purchase list of something, |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
306 |
* and we are checking for something undefined. |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
307 |
* That means we should get the first target |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
308 |
* (NOT the default one). */ |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
309 |
if (dsg->num_ranges > 0) { |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
310 |
target = &dsg->ranges[0].group; |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
311 |
} else { |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
312 |
target = dsg->default_group; |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
313 |
} |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
314 |
return callback(target, NULL, callback); |
433
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
315 |
} |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
316 |
|
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
317 |
if (dsg->var_scope == VSG_SCOPE_PARENT) { |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
318 |
/* First engine in the vehicle chain */ |
433
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
319 |
if (veh->type == VEH_Train) |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
320 |
veh = GetFirstVehicleInChain(veh); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
321 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
322 |
|
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
323 |
if (dsg->variable == 0x40) { |
433
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
324 |
if (veh->type == VEH_Train) { |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
325 |
Vehicle *u = GetFirstVehicleInChain(veh); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
326 |
byte chain_before = 0, chain_after = 0; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
327 |
|
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
328 |
while (u != veh) { |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
329 |
u = u->next; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
330 |
chain_before++; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
331 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
332 |
while (u->next != NULL) { |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
333 |
u = u->next; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
334 |
chain_after++; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
335 |
}; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
336 |
|
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
337 |
value = chain_before << 16 | chain_after << 8 |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
338 |
| (chain_before + chain_after + 1); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
339 |
} else { |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
340 |
value = 1; /* 1 vehicle in the chain */ |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
341 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
342 |
|
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
343 |
} else { |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
344 |
// TTDPatch runs on little-endian arch; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
345 |
// Variable is 0x80 + offset in TTD's vehicle structure |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
346 |
switch (dsg->variable - 0x80) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
347 |
#define veh_prop(id_, value_) case (id_): value = (value_); break |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
348 |
veh_prop(0x00, veh->type); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
349 |
veh_prop(0x01, veh->subtype); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
350 |
veh_prop(0x04, veh->index); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
351 |
veh_prop(0x05, veh->index & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
352 |
/* XXX? Is THIS right? */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
353 |
veh_prop(0x0A, PackOrder(&veh->current_order)); |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
354 |
veh_prop(0x0B, PackOrder(&veh->current_order) & 0xff); |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
355 |
veh_prop(0x0C, veh->num_orders); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
356 |
veh_prop(0x0D, veh->cur_order_index); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
357 |
veh_prop(0x10, veh->load_unload_time_rem); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
358 |
veh_prop(0x11, veh->load_unload_time_rem & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
359 |
veh_prop(0x12, veh->date_of_last_service); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
360 |
veh_prop(0x13, veh->date_of_last_service & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
361 |
veh_prop(0x14, veh->service_interval); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
362 |
veh_prop(0x15, veh->service_interval & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
363 |
veh_prop(0x16, veh->last_station_visited); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
364 |
veh_prop(0x17, veh->tick_counter); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
365 |
veh_prop(0x18, veh->max_speed); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
366 |
veh_prop(0x19, veh->max_speed & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
367 |
veh_prop(0x1F, veh->direction); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
368 |
veh_prop(0x28, veh->cur_image); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
369 |
veh_prop(0x29, veh->cur_image & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
370 |
veh_prop(0x32, veh->vehstatus); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
371 |
veh_prop(0x33, veh->vehstatus); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
372 |
veh_prop(0x34, veh->cur_speed); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
373 |
veh_prop(0x35, veh->cur_speed & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
374 |
veh_prop(0x36, veh->subspeed); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
375 |
veh_prop(0x37, veh->acceleration); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
376 |
veh_prop(0x39, veh->cargo_type); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
377 |
veh_prop(0x3A, veh->cargo_cap); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
378 |
veh_prop(0x3B, veh->cargo_cap & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
379 |
veh_prop(0x3C, veh->cargo_count); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
380 |
veh_prop(0x3D, veh->cargo_count & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
381 |
veh_prop(0x3E, veh->cargo_source); // Probably useless; so what |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
382 |
veh_prop(0x3F, veh->cargo_days); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
383 |
veh_prop(0x40, veh->age); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
384 |
veh_prop(0x41, veh->age & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
385 |
veh_prop(0x42, veh->max_age); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
386 |
veh_prop(0x43, veh->max_age & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
387 |
veh_prop(0x44, veh->build_year); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
388 |
veh_prop(0x45, veh->unitnumber); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
389 |
veh_prop(0x46, veh->engine_type); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
390 |
veh_prop(0x47, veh->engine_type & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
391 |
veh_prop(0x48, veh->spritenum); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
392 |
veh_prop(0x49, veh->day_counter); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
393 |
veh_prop(0x4A, veh->breakdowns_since_last_service); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
394 |
veh_prop(0x4B, veh->breakdown_ctr); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
395 |
veh_prop(0x4C, veh->breakdown_delay); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
396 |
veh_prop(0x4D, veh->breakdown_chance); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
397 |
veh_prop(0x4E, veh->reliability); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
398 |
veh_prop(0x4F, veh->reliability & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
399 |
veh_prop(0x50, veh->reliability_spd_dec); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
400 |
veh_prop(0x51, veh->reliability_spd_dec & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
401 |
veh_prop(0x52, veh->profit_this_year); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
402 |
veh_prop(0x53, veh->profit_this_year & 0xFFFFFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
403 |
veh_prop(0x54, veh->profit_this_year & 0xFFFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
404 |
veh_prop(0x55, veh->profit_this_year & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
405 |
veh_prop(0x56, veh->profit_last_year); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
406 |
veh_prop(0x57, veh->profit_last_year & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
407 |
veh_prop(0x58, veh->profit_last_year); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
408 |
veh_prop(0x59, veh->profit_last_year & 0xFF); |
938
23cc832ac8a2
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
919
diff
changeset
|
409 |
/* veh_prop(0x5A, veh->next_in_chain_old); |
23cc832ac8a2
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
919
diff
changeset
|
410 |
veh_prop(0x5B, veh->next_in_chain_old & 0xFF);*/ |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
411 |
veh_prop(0x5C, veh->value); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
412 |
veh_prop(0x5D, veh->value & 0xFFFFFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
413 |
veh_prop(0x5E, veh->value & 0xFFFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
414 |
veh_prop(0x5F, veh->value & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
415 |
veh_prop(0x60, veh->string_id); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
416 |
veh_prop(0x61, veh->string_id & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
417 |
/* 00h..07h=sub image? 40h=in tunnel; actually some kind of status |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
418 |
* aircraft: >=13h when in flight |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
419 |
* train, ship: 80h=in depot |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
420 |
* rv: 0feh=in depot */ |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
421 |
/* TODO veh_prop(0x62, veh->???); */ |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
422 |
|
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
423 |
/* TODO: The rest is per-vehicle, I hope no GRF file looks so far. |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
424 |
* But they won't let us have an easy ride so surely *some* GRF |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
425 |
* file does. So someone needs to do this too. --pasky */ |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
426 |
|
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
427 |
#undef veh_prop |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
428 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
429 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
430 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
431 |
|
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
432 |
target = value != -1 ? EvalDeterministicSpriteGroup(dsg, value) : dsg->default_group; |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
433 |
//debug("Resolved variable %x: %d, %p", dsg->variable, value, callback); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
434 |
return callback(target, veh, callback); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
435 |
} |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
436 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
437 |
case SGT_RANDOMIZED: { |
1477 | 438 |
RandomizedSpriteGroup *rsg = &spritegroup->g.random; |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
439 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
440 |
if (veh == NULL) { |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
441 |
/* Purchase list of something. Show the first one. */ |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
442 |
assert(rsg->num_groups > 0); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
443 |
//debug("going for %p: %d", rsg->groups[0], rsg->groups[0].type); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
444 |
return callback(&rsg->groups[0], NULL, callback); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
445 |
} |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
446 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
447 |
if (rsg->var_scope == VSG_SCOPE_PARENT) { |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
448 |
/* First engine in the vehicle chain */ |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
449 |
if (veh->type == VEH_Train) |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
450 |
veh = GetFirstVehicleInChain(veh); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
451 |
} |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
452 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
453 |
return callback(EvalRandomizedSpriteGroup(rsg, veh->random_bits), veh, callback); |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
454 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
455 |
|
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
456 |
default: |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
457 |
error("I don't know how to handle such a spritegroup %d!", spritegroup->type); |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
458 |
return NULL; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
459 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
460 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
461 |
|
1477 | 462 |
static SpriteGroup *GetVehicleSpriteGroup(byte engine, const Vehicle *v) |
0 | 463 |
{ |
1477 | 464 |
SpriteGroup *group; |
414
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
465 |
uint16 overriding_engine = -1; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
466 |
byte cargo = CID_PURCHASE; |
0 | 467 |
|
414
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
468 |
if (v != NULL) { |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
469 |
overriding_engine = v->type == VEH_Train ? v->u.rail.first_engine : -1; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
470 |
cargo = _global_cargo_id[_opt.landscape][v->cargo_type]; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
471 |
} |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
472 |
|
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
473 |
group = &_engine_custom_sprites[engine][cargo]; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
474 |
|
0 | 475 |
if (overriding_engine != 0xffff) { |
1477 | 476 |
SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, overriding_engine); |
0 | 477 |
|
1477 | 478 |
if (overset != NULL) group = overset; |
0 | 479 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
480 |
|
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
481 |
return group; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
482 |
} |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
483 |
|
1475 | 484 |
int GetCustomEngineSprite(byte engine, const Vehicle *v, byte direction) |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
485 |
{ |
1477 | 486 |
SpriteGroup *group; |
487 |
RealSpriteGroup *rsg; |
|
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
488 |
byte cargo = CID_PURCHASE; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
489 |
byte loaded = 0; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
490 |
bool in_motion = 0; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
491 |
int totalsets, spriteset; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
492 |
int r; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
493 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
494 |
if (v != NULL) { |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
495 |
int capacity = v->cargo_cap; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
496 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
497 |
cargo = _global_cargo_id[_opt.landscape][v->cargo_type]; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
498 |
if (capacity == 0) capacity = 1; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
499 |
loaded = (v->cargo_count * 100) / capacity; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
500 |
in_motion = (v->cur_speed != 0); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
501 |
} |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
502 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
503 |
group = GetVehicleSpriteGroup(engine, v); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
504 |
rsg = ResolveVehicleSpriteGroup(group, v, (resolve_callback) ResolveVehicleSpriteGroup); |
408
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
505 |
|
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
506 |
if (rsg->sprites_per_set == 0 && cargo != 29) { /* XXX magic number */ |
369
3742b39b6cca
(svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents:
292
diff
changeset
|
507 |
// This group is empty but perhaps there'll be a default one. |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
508 |
rsg = ResolveVehicleSpriteGroup(&_engine_custom_sprites[engine][29], v, |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
509 |
(resolve_callback) ResolveVehicleSpriteGroup); |
0 | 510 |
} |
511 |
||
408
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
512 |
if (!rsg->sprites_per_set) { |
369
3742b39b6cca
(svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents:
292
diff
changeset
|
513 |
// This group is empty. This function users should therefore |
0 | 514 |
// look up the sprite number in _engine_original_sprites. |
515 |
return 0; |
|
516 |
} |
|
517 |
||
518 |
direction %= 8; |
|
408
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
519 |
if (rsg->sprites_per_set == 4) |
0 | 520 |
direction %= 4; |
521 |
||
408
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
522 |
totalsets = in_motion ? rsg->loaded_count : rsg->loading_count; |
0 | 523 |
|
524 |
// My aim here is to make it possible to visually determine absolutely |
|
525 |
// empty and totally full vehicles. --pasky |
|
526 |
if (loaded == 100 || totalsets == 1) { // full |
|
527 |
spriteset = totalsets - 1; |
|
528 |
} else if (loaded == 0 || totalsets == 2) { // empty |
|
529 |
spriteset = 0; |
|
530 |
} else { // something inbetween |
|
531 |
spriteset = loaded * (totalsets - 2) / 100 + 1; |
|
532 |
// correct possible rounding errors |
|
533 |
if (!spriteset) |
|
534 |
spriteset = 1; |
|
535 |
else if (spriteset == totalsets - 1) |
|
536 |
spriteset--; |
|
537 |
} |
|
538 |
||
408
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
539 |
r = (in_motion ? rsg->loaded[spriteset] : rsg->loading[spriteset]) + direction; |
0 | 540 |
return r; |
541 |
} |
|
542 |
||
543 |
||
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
544 |
// Global variables are evil, yes, but we would end up with horribly overblown |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
545 |
// calling convention otherwise and this should be 100% reentrant. |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
546 |
static byte _vsg_random_triggers; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
547 |
static byte _vsg_bits_to_reseed; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
548 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
549 |
extern int _custom_sprites_base; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
550 |
|
1477 | 551 |
static RealSpriteGroup *TriggerVehicleSpriteGroup(SpriteGroup *spritegroup, |
552 |
Vehicle *veh, resolve_callback callback) |
|
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
553 |
{ |
1477 | 554 |
if (spritegroup->type == SGT_RANDOMIZED) { |
555 |
_vsg_bits_to_reseed |= RandomizedSpriteGroupTriggeredBits( |
|
556 |
&spritegroup->g.random, |
|
557 |
_vsg_random_triggers, |
|
558 |
&veh->waiting_triggers |
|
559 |
); |
|
560 |
} |
|
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
561 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
562 |
return ResolveVehicleSpriteGroup(spritegroup, veh, callback); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
563 |
} |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
564 |
|
1477 | 565 |
static void DoTriggerVehicle(Vehicle *veh, VehicleTrigger trigger, byte base_random_bits, bool first) |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
566 |
{ |
1477 | 567 |
RealSpriteGroup *rsg; |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
568 |
byte new_random_bits; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
569 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
570 |
_vsg_random_triggers = trigger; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
571 |
_vsg_bits_to_reseed = 0; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
572 |
rsg = TriggerVehicleSpriteGroup(GetVehicleSpriteGroup(veh->engine_type, veh), veh, |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
573 |
(resolve_callback) TriggerVehicleSpriteGroup); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
574 |
if (rsg->sprites_per_set == 0 && veh->cargo_type != 29) { /* XXX magic number */ |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
575 |
// This group turned out to be empty but perhaps there'll be a default one. |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
576 |
rsg = TriggerVehicleSpriteGroup(&_engine_custom_sprites[veh->engine_type][29], veh, |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
577 |
(resolve_callback) TriggerVehicleSpriteGroup); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
578 |
} |
542 | 579 |
new_random_bits = Random(); |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
580 |
veh->random_bits &= ~_vsg_bits_to_reseed; |
542 | 581 |
veh->random_bits |= (first ? new_random_bits : base_random_bits) & _vsg_bits_to_reseed; |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
582 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
583 |
switch (trigger) { |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
584 |
case VEHICLE_TRIGGER_NEW_CARGO: |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
585 |
/* All vehicles in chain get ANY_NEW_CARGO trigger now. |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
586 |
* So we call it for the first one and they will recurse. */ |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
587 |
/* Indexing part of vehicle random bits needs to be |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
588 |
* same for all triggered vehicles in the chain (to get |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
589 |
* all the random-cargo wagons carry the same cargo, |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
590 |
* i.e.), so we give them all the NEW_CARGO triggered |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
591 |
* vehicle's portion of random bits. */ |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
592 |
assert(first); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
593 |
DoTriggerVehicle(GetFirstVehicleInChain(veh), VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits, false); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
594 |
break; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
595 |
case VEHICLE_TRIGGER_DEPOT: |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
596 |
/* We now trigger the next vehicle in chain recursively. |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
597 |
* The random bits portions may be different for each |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
598 |
* vehicle in chain. */ |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
599 |
if (veh->next != NULL) |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
600 |
DoTriggerVehicle(veh->next, trigger, 0, true); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
601 |
break; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
602 |
case VEHICLE_TRIGGER_EMPTY: |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
603 |
/* We now trigger the next vehicle in chain |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
604 |
* recursively. The random bits portions must be same |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
605 |
* for each vehicle in chain, so we give them all |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
606 |
* first chained vehicle's portion of random bits. */ |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
607 |
if (veh->next != NULL) |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
608 |
DoTriggerVehicle(veh->next, trigger, first ? new_random_bits : base_random_bits, false); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
609 |
break; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
610 |
case VEHICLE_TRIGGER_ANY_NEW_CARGO: |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
611 |
/* Now pass the trigger recursively to the next vehicle |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
612 |
* in chain. */ |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
613 |
assert(!first); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
614 |
if (veh->next != NULL) |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
615 |
DoTriggerVehicle(veh->next, VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits, false); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
616 |
break; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
617 |
} |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
618 |
} |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
619 |
|
1477 | 620 |
void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger) |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
621 |
{ |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
622 |
DoTriggerVehicle(veh, trigger, 0, true); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
623 |
} |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
624 |
|
1474
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
625 |
static char *_engine_custom_names[TOTAL_NUM_ENGINES]; |
0 | 626 |
|
1329 | 627 |
void SetCustomEngineName(int engine, const char *name) |
0 | 628 |
{ |
629 |
_engine_custom_names[engine] = strdup(name); |
|
630 |
} |
|
631 |
||
1474
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
632 |
void UnInitNewgrEngines(void) |
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
633 |
{ |
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
634 |
char **i; |
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
635 |
for (i = _engine_custom_names; i != endof(_engine_custom_names); i++) { |
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
636 |
free(*i); |
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
637 |
*i = NULL; |
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
638 |
} |
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
639 |
} |
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
640 |
|
0 | 641 |
StringID GetCustomEngineName(int engine) |
642 |
{ |
|
643 |
if (!_engine_custom_names[engine]) |
|
644 |
return _engine_name_strings[engine]; |
|
485
7a7484b85037
(svn r767) Introduce USERSTRING_LEN (128) and try to make sure we don't overflow it anywhere (as long as we keep USERSTRING_LEN above 7 or so).
pasky
parents:
445
diff
changeset
|
645 |
strncpy(_userstring, _engine_custom_names[engine], USERSTRING_LEN); |
7a7484b85037
(svn r767) Introduce USERSTRING_LEN (128) and try to make sure we don't overflow it anywhere (as long as we keep USERSTRING_LEN above 7 or so).
pasky
parents:
445
diff
changeset
|
646 |
_userstring[USERSTRING_LEN - 1] = '\0'; |
0 | 647 |
return STR_SPEC_USERSTRING; |
648 |
} |
|
649 |
||
650 |
||
651 |
void AcceptEnginePreview(Engine *e, int player) |
|
652 |
{ |
|
653 |
Player *p; |
|
654 |
||
655 |
SETBIT(e->player_avail, player); |
|
656 |
||
657 |
p = DEREF_PLAYER(player); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
658 |
|
0 | 659 |
UPDATE_PLAYER_RAILTYPE(e,p); |
660 |
||
661 |
e->preview_player = 0xFF; |
|
662 |
InvalidateWindowClasses(WC_BUILD_VEHICLE); |
|
1096
87415b0c6fdb
(svn r1597) fix: autoreplace vehicle lists are now redrawn when a new vehicle becomes available (thanks LordOfThePigs for pointing this one out)
bjarni
parents:
1093
diff
changeset
|
663 |
InvalidateWindowClasses(WC_REPLACE_VEHICLE); |
0 | 664 |
} |
665 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
666 |
void EnginesDailyLoop(void) |
0 | 667 |
{ |
668 |
Engine *e; |
|
669 |
int i,num; |
|
670 |
Player *p; |
|
671 |
uint mask; |
|
672 |
int32 best_hist; |
|
673 |
int best_player; |
|
674 |
||
675 |
if (_cur_year >= 130) |
|
676 |
return; |
|
677 |
||
678 |
for(e=_engines,i=0; i!=TOTAL_NUM_ENGINES; e++,i++) { |
|
679 |
if (e->flags & ENGINE_INTRODUCING) { |
|
680 |
if (e->flags & ENGINE_PREVIEWING) { |
|
740
ab84ecdf86a2
(svn r1196) -Fix: Preview Vehicle had a small glitch. Fixed now.
truelight
parents:
555
diff
changeset
|
681 |
if (e->preview_player != 0xFF && !--e->preview_wait) { |
0 | 682 |
e->flags &= ~ENGINE_PREVIEWING; |
683 |
DeleteWindowById(WC_ENGINE_PREVIEW, i); |
|
684 |
e->preview_player++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
685 |
} |
0 | 686 |
} else if (e->preview_player != 0xFF) { |
687 |
num = e->preview_player; |
|
688 |
mask = 0; |
|
689 |
do { |
|
690 |
best_hist = -1; |
|
691 |
best_player = -1; |
|
692 |
FOR_ALL_PLAYERS(p) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
693 |
if (p->is_active && p->block_preview == 0 && !HASBIT(mask,p->index) && |
0 | 694 |
p->old_economy[0].performance_history > best_hist) { |
695 |
best_hist = p->old_economy[0].performance_history; |
|
696 |
best_player = p->index; |
|
697 |
} |
|
698 |
} |
|
699 |
if (best_player == -1) { |
|
700 |
e->preview_player = 0xFF; |
|
701 |
goto next_engine; |
|
702 |
} |
|
703 |
mask |= (1 << best_player); |
|
704 |
} while (--num != 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
705 |
|
0 | 706 |
if (!IS_HUMAN_PLAYER(best_player)) { |
707 |
/* TTDBUG: TTD has a bug here */ |
|
708 |
AcceptEnginePreview(e, best_player); |
|
709 |
} else { |
|
710 |
e->flags |= ENGINE_PREVIEWING; |
|
711 |
e->preview_wait = 20; |
|
712 |
if (IS_INTERACTIVE_PLAYER(best_player)) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
713 |
ShowEnginePreviewWindow(i); |
0 | 714 |
} |
715 |
} |
|
716 |
} |
|
717 |
} |
|
718 |
next_engine:; |
|
719 |
} |
|
720 |
} |
|
721 |
||
722 |
int32 CmdWantEnginePreview(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
723 |
{ |
|
724 |
if (flags & DC_EXEC) { |
|
725 |
AcceptEnginePreview(&_engines[p1], _current_player); |
|
726 |
} |
|
727 |
return 0; |
|
728 |
} |
|
729 |
||
257
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
730 |
// Determine if an engine type is a wagon (and not a loco) |
964
fe9e7b220b9f
(svn r1456) Simplify isWagon(), make it static and give it a canonical name (IsWagon)
tron
parents:
938
diff
changeset
|
731 |
static bool IsWagon(byte index) |
257
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
732 |
{ |
964
fe9e7b220b9f
(svn r1456) Simplify isWagon(), make it static and give it a canonical name (IsWagon)
tron
parents:
938
diff
changeset
|
733 |
return index < NUM_TRAIN_ENGINES && RailVehInfo(index)->flags & RVI_WAGON; |
257
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
734 |
} |
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
735 |
|
410 | 736 |
static void NewVehicleAvailable(Engine *e) |
0 | 737 |
{ |
738 |
Vehicle *v; |
|
739 |
Player *p; |
|
740 |
int index = e - _engines; |
|
741 |
||
742 |
// In case the player didn't build the vehicle during the intro period, |
|
743 |
// prevent that player from getting future intro periods for a while. |
|
744 |
if (e->flags&ENGINE_INTRODUCING) { |
|
745 |
FOR_ALL_PLAYERS(p) { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
746 |
uint block_preview = p->block_preview; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
747 |
|
0 | 748 |
if (!HASBIT(e->player_avail,p->index)) |
749 |
continue; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
750 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
751 |
/* We assume the user did NOT build it.. prove me wrong ;) */ |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
752 |
p->block_preview = 20; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
753 |
|
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
754 |
FOR_ALL_VEHICLES(v) { |
0 | 755 |
if (v->type == VEH_Train || v->type == VEH_Road || v->type == VEH_Ship || |
756 |
(v->type == VEH_Aircraft && v->subtype <= 2)) { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
757 |
if (v->owner == p->index && v->engine_type == index) { |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
758 |
/* The user did prove me wrong, so restore old value */ |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
759 |
p->block_preview = block_preview; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
760 |
break; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
761 |
} |
0 | 762 |
} |
763 |
} |
|
764 |
} |
|
765 |
} |
|
766 |
||
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
767 |
e->flags = (e->flags & ~ENGINE_INTRODUCING) | ENGINE_AVAILABLE; |
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
768 |
InvalidateWindowClasses(WC_BUILD_VEHICLE); |
1096
87415b0c6fdb
(svn r1597) fix: autoreplace vehicle lists are now redrawn when a new vehicle becomes available (thanks LordOfThePigs for pointing this one out)
bjarni
parents:
1093
diff
changeset
|
769 |
InvalidateWindowClasses(WC_REPLACE_VEHICLE); |
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
770 |
|
0 | 771 |
// Now available for all players |
772 |
e->player_avail = (byte)-1; |
|
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
773 |
|
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
774 |
// Do not introduce new rail wagons |
964
fe9e7b220b9f
(svn r1456) Simplify isWagon(), make it static and give it a canonical name (IsWagon)
tron
parents:
938
diff
changeset
|
775 |
if (IsWagon(index)) |
257
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
776 |
return; |
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
777 |
|
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
778 |
// make maglev / monorail available |
0 | 779 |
FOR_ALL_PLAYERS(p) { |
780 |
if (p->is_active) |
|
781 |
UPDATE_PLAYER_RAILTYPE(e,p); |
|
782 |
} |
|
783 |
||
784 |
if ((byte)index < NUM_TRAIN_ENGINES) { |
|
785 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_TRAINAVAIL), 0, 0); |
|
786 |
} else if ((byte)index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) { |
|
787 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_ROADAVAIL), 0, 0); |
|
788 |
} else if ((byte)index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) { |
|
789 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_SHIPAVAIL), 0, 0); |
|
790 |
} else { |
|
791 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_AIRCRAFTAVAIL), 0, 0); |
|
792 |
} |
|
793 |
} |
|
794 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
795 |
void EnginesMonthlyLoop(void) |
0 | 796 |
{ |
797 |
Engine *e; |
|
798 |
||
799 |
if (_cur_year < 130) { |
|
800 |
for(e=_engines; e != endof(_engines); e++) { |
|
801 |
// Age the vehicle |
|
802 |
if (e->flags&ENGINE_AVAILABLE && e->age != 0xFFFF) { |
|
803 |
e->age++; |
|
804 |
CalcEngineReliability(e); |
|
805 |
} |
|
806 |
||
807 |
if (!(e->flags & ENGINE_AVAILABLE) && (uint16)(_date - min(_date, 365)) >= e->intro_date) { |
|
808 |
// Introduce it to all players |
|
809 |
NewVehicleAvailable(e); |
|
810 |
} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_INTRODUCING)) && _date >= e->intro_date) { |
|
811 |
// Introduction date has passed.. show introducing dialog to one player. |
|
812 |
e->flags |= ENGINE_INTRODUCING; |
|
257
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
813 |
|
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
814 |
// Do not introduce new rail wagons |
964
fe9e7b220b9f
(svn r1456) Simplify isWagon(), make it static and give it a canonical name (IsWagon)
tron
parents:
938
diff
changeset
|
815 |
if (!IsWagon(e - _engines)) |
257
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
816 |
e->preview_player = 1; // Give to the player with the highest rating. |
0 | 817 |
} |
818 |
} |
|
819 |
} |
|
820 |
AdjustAvailAircraft(); |
|
821 |
} |
|
822 |
||
823 |
int32 CmdRenameEngine(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
824 |
{ |
|
825 |
StringID str; |
|
826 |
||
1328
eacd8225ed42
(svn r1832) Next byte -> char iteration: custom names
tron
parents:
1299
diff
changeset
|
827 |
str = AllocateNameUnique((const char*)_decode_parameters, 0); |
0 | 828 |
if (str == 0) |
829 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
830 |
|
0 | 831 |
if (flags & DC_EXEC) { |
832 |
StringID old_str = _engine_name_strings[p1]; |
|
833 |
_engine_name_strings[p1] = str; |
|
834 |
DeleteName(old_str); |
|
835 |
_vehicle_design_names |= 3; |
|
836 |
MarkWholeScreenDirty(); |
|
837 |
} else { |
|
838 |
DeleteName(str); |
|
839 |
} |
|
840 |
||
841 |
return 0; |
|
842 |
} |
|
843 |
||
844 |
int GetPlayerMaxRailtype(int p) |
|
845 |
{ |
|
846 |
Engine *e; |
|
847 |
int rt = 0; |
|
848 |
int i; |
|
849 |
||
850 |
for(e=_engines,i=0; i!=lengthof(_engines); e++,i++) { |
|
851 |
if (!HASBIT(e->player_avail, p)) |
|
852 |
continue; |
|
853 |
||
854 |
if ((i >= 27 && i < 54) || (i >= 57 && i < 84) || (i >= 89 && i < 116)) |
|
855 |
continue; |
|
856 |
||
857 |
if (rt < e->railtype) |
|
858 |
rt = e->railtype; |
|
859 |
} |
|
860 |
||
861 |
return rt + 1; |
|
862 |
} |
|
863 |
||
864 |
||
865 |
static const byte _engine_desc[] = { |
|
866 |
SLE_VAR(Engine,intro_date, SLE_UINT16), |
|
867 |
SLE_VAR(Engine,age, SLE_UINT16), |
|
868 |
SLE_VAR(Engine,reliability, SLE_UINT16), |
|
869 |
SLE_VAR(Engine,reliability_spd_dec, SLE_UINT16), |
|
870 |
SLE_VAR(Engine,reliability_start, SLE_UINT16), |
|
871 |
SLE_VAR(Engine,reliability_max, SLE_UINT16), |
|
872 |
SLE_VAR(Engine,reliability_final, SLE_UINT16), |
|
873 |
SLE_VAR(Engine,duration_phase_1, SLE_UINT16), |
|
874 |
SLE_VAR(Engine,duration_phase_2, SLE_UINT16), |
|
875 |
SLE_VAR(Engine,duration_phase_3, SLE_UINT16), |
|
876 |
||
877 |
SLE_VAR(Engine,lifelength, SLE_UINT8), |
|
878 |
SLE_VAR(Engine,flags, SLE_UINT8), |
|
879 |
SLE_VAR(Engine,preview_player, SLE_UINT8), |
|
880 |
SLE_VAR(Engine,preview_wait, SLE_UINT8), |
|
881 |
SLE_VAR(Engine,railtype, SLE_UINT8), |
|
882 |
SLE_VAR(Engine,player_avail, SLE_UINT8), |
|
883 |
||
884 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
885 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255), |
|
886 |
||
887 |
SLE_END() |
|
888 |
}; |
|
889 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
890 |
static void Save_ENGN(void) |
0 | 891 |
{ |
892 |
Engine *e; |
|
893 |
int i; |
|
894 |
for(i=0,e=_engines; i != lengthof(_engines); i++,e++) { |
|
895 |
SlSetArrayIndex(i); |
|
896 |
SlObject(e, _engine_desc); |
|
897 |
} |
|
898 |
} |
|
899 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
900 |
static void Load_ENGN(void) |
0 | 901 |
{ |
902 |
int index; |
|
903 |
while ((index = SlIterateArray()) != -1) { |
|
904 |
SlObject(&_engines[index], _engine_desc); |
|
905 |
} |
|
906 |
} |
|
907 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
908 |
static void LoadSave_ENGS(void) |
0 | 909 |
{ |
910 |
SlArray(_engine_name_strings, lengthof(_engine_name_strings), SLE_STRINGID); |
|
911 |
} |
|
912 |
||
913 |
const ChunkHandler _engine_chunk_handlers[] = { |
|
914 |
{ 'ENGN', Save_ENGN, Load_ENGN, CH_ARRAY}, |
|
915 |
{ 'ENGS', LoadSave_ENGS, LoadSave_ENGS, CH_RIFF | CH_LAST}, |
|
916 |
}; |
|
917 |
||
1197 | 918 |
|
1196
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
919 |
/* |
1197 | 920 |
* returns true if an engine is valid, of the specified type, and buildable by |
921 |
* the current player, false otherwise |
|
1196
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
922 |
* |
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
923 |
* engine = index of the engine to check |
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
924 |
* type = the type the engine should be of (VEH_xxx) |
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
925 |
*/ |
1197 | 926 |
bool IsEngineBuildable(uint engine, byte type) |
927 |
{ |
|
928 |
const Engine *e; |
|
1196
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
929 |
|
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
930 |
// check if it's an engine that is in the engine array |
1197 | 931 |
if (engine >= TOTAL_NUM_ENGINES) return false; |
1196
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
932 |
|
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
933 |
e = DEREF_ENGINE(engine); |
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
934 |
|
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
935 |
// check if it's an engine of specified type |
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
936 |
if (e->type != type) return false; |
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
937 |
|
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
938 |
// check if it's available |
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
939 |
if (!HASBIT(e->player_avail, _current_player)) return false; |
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
940 |
|
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
941 |
return true; |
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
942 |
} |