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