author | tron |
Sun, 14 Nov 2004 19:44:06 +0000 | |
changeset 410 | 8de2aaf20800 |
parent 337 | 66647f97e7c0 |
child 507 | 8aa8100b0b22 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
3 |
#include "vehicle.h" |
|
4 |
#include "command.h" |
|
5 |
#include "news.h" |
|
6 |
#include "gfx.h" |
|
7 |
#include "station.h" |
|
8 |
#include "town.h" |
|
9 |
#include "industry.h" |
|
10 |
#include "player.h" |
|
11 |
#include "airport_movement.h" |
|
337
66647f97e7c0
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
12 |
#include "sound.h" |
0 | 13 |
|
14 |
static void DisasterClearSquare(uint tile) |
|
15 |
{ |
|
16 |
int type; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
17 |
|
0 | 18 |
if (!EnsureNoVehicle(tile)) |
19 |
return; |
|
20 |
||
21 |
type = _map_type_and_height[tile] >> 4; |
|
22 |
||
23 |
if (type == MP_RAILWAY) { |
|
24 |
if (IS_HUMAN_PLAYER(_map_owner[tile])) |
|
25 |
DoClearSquare(tile); |
|
26 |
} else if (type == MP_HOUSE) { |
|
27 |
byte p = _current_player; |
|
28 |
_current_player = OWNER_NONE; |
|
29 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
30 |
_current_player = p; |
|
31 |
} else if (type == MP_TREES || type == MP_CLEAR) { |
|
32 |
DoClearSquare(tile); |
|
33 |
} |
|
34 |
} |
|
35 |
||
36 |
static const SpriteID _disaster_images_1[] = {0xF41,0xF41,0xF41,0xF41,0xF41,0xF41,0xF41,0xF41}; |
|
37 |
static const SpriteID _disaster_images_2[] = {0xF44,0xF44,0xF44,0xF44,0xF44,0xF44,0xF44,0xF44}; |
|
38 |
static const SpriteID _disaster_images_3[] = {0xF4E,0xF4E,0xF4E,0xF4E,0xF4E,0xF4E,0xF4E,0xF4E}; |
|
39 |
static const SpriteID _disaster_images_4[] = {0xF46,0xF46,0xF47,0xF47,0xF48,0xF48,0xF49,0xF49}; |
|
40 |
static const SpriteID _disaster_images_5[] = {0xF4A,0xF4A,0xF4B,0xF4B,0xF4C,0xF4C,0xF4D,0xF4D}; |
|
41 |
static const SpriteID _disaster_images_6[] = {0xF50,0xF50,0xF50,0xF50,0xF50,0xF50,0xF50,0xF50}; |
|
42 |
static const SpriteID _disaster_images_7[] = {0xF51,0xF51,0xF51,0xF51,0xF51,0xF51,0xF51,0xF51}; |
|
43 |
static const SpriteID _disaster_images_8[] = {0xF52,0xF52,0xF52,0xF52,0xF52,0xF52,0xF52,0xF52}; |
|
44 |
static const SpriteID _disaster_images_9[] = {0xF3E,0xF3E,0xF3E,0xF3E,0xF3E,0xF3E,0xF3E,0xF3E}; |
|
45 |
||
46 |
static const SpriteID * const _disaster_images[] = { |
|
47 |
_disaster_images_1,_disaster_images_1, |
|
48 |
_disaster_images_2,_disaster_images_2, |
|
49 |
_disaster_images_3,_disaster_images_3, |
|
50 |
_disaster_images_8,_disaster_images_8,_disaster_images_9, |
|
51 |
_disaster_images_6,_disaster_images_6, |
|
52 |
_disaster_images_7,_disaster_images_7, |
|
53 |
_disaster_images_4,_disaster_images_5, |
|
54 |
}; |
|
55 |
||
56 |
static void DisasterVehicleUpdateImage(Vehicle *v) |
|
57 |
{ |
|
58 |
int img = v->u.disaster.image_override; |
|
59 |
if (img == 0) |
|
60 |
img = _disaster_images[v->subtype][v->direction]; |
|
61 |
v->cur_image = img; |
|
62 |
} |
|
63 |
||
64 |
static void InitializeDisasterVehicle(Vehicle *v, int x, int y, byte z, byte direction, byte subtype) |
|
65 |
{ |
|
66 |
v->type = VEH_Disaster; |
|
67 |
v->x_pos = x; |
|
68 |
v->y_pos = y; |
|
69 |
v->z_pos = z; |
|
70 |
v->tile = TILE_FROM_XY(x,y); |
|
71 |
v->direction = direction; |
|
72 |
v->subtype = subtype; |
|
73 |
v->x_offs = -1; |
|
74 |
v->y_offs = -1; |
|
75 |
v->sprite_width = 2; |
|
76 |
v->sprite_height = 2; |
|
77 |
v->z_height = 5; |
|
78 |
v->owner = OWNER_NONE; |
|
79 |
v->vehstatus = VS_UNCLICKABLE; |
|
80 |
v->u.disaster.image_override = 0; |
|
81 |
v->next_order = 0; |
|
82 |
||
83 |
DisasterVehicleUpdateImage(v); |
|
84 |
VehiclePositionChanged(v); |
|
85 |
BeginVehicleMove(v); |
|
86 |
EndVehicleMove(v); |
|
87 |
} |
|
88 |
||
89 |
static void DeleteDisasterVeh(Vehicle *v) |
|
90 |
{ |
|
91 |
DeleteVehicleChain(v); |
|
92 |
} |
|
93 |
||
94 |
static void SetDisasterVehiclePos(Vehicle *v, int x, int y, byte z) |
|
95 |
{ |
|
96 |
Vehicle *u; |
|
97 |
int yt; |
|
98 |
||
99 |
BeginVehicleMove(v); |
|
100 |
v->x_pos = x; |
|
101 |
v->y_pos = y; |
|
102 |
v->z_pos = z; |
|
103 |
v->tile = TILE_FROM_XY(x,y); |
|
104 |
||
105 |
DisasterVehicleUpdateImage(v); |
|
106 |
VehiclePositionChanged(v); |
|
107 |
EndVehicleMove(v); |
|
108 |
||
109 |
if ( (u=v->next) != NULL) { |
|
110 |
BeginVehicleMove(u); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
111 |
|
0 | 112 |
u->x_pos = x; |
113 |
u->y_pos = yt = y - 1 - (max(z - GetSlopeZ(x, y-1), 0) >> 3); |
|
114 |
u->z_pos = GetSlopeZ(x,yt); |
|
115 |
u->direction = v->direction; |
|
116 |
||
117 |
DisasterVehicleUpdateImage(u); |
|
118 |
VehiclePositionChanged(u); |
|
119 |
EndVehicleMove(u); |
|
120 |
||
121 |
if ( (u=u->next) != NULL) { |
|
122 |
BeginVehicleMove(u); |
|
123 |
u->x_pos = x; |
|
124 |
u->y_pos = y; |
|
125 |
u->z_pos = z + 5; |
|
126 |
VehiclePositionChanged(u); |
|
127 |
EndVehicleMove(u); |
|
128 |
} |
|
129 |
} |
|
130 |
} |
|
131 |
||
132 |
||
133 |
static void DisasterTick_Zeppeliner(Vehicle *v) |
|
134 |
{ |
|
135 |
GetNewVehiclePosResult gp; |
|
136 |
Station *st; |
|
137 |
int x,y; |
|
138 |
byte z; |
|
139 |
uint tile; |
|
140 |
||
141 |
++v->tick_counter; |
|
142 |
||
143 |
if (v->next_order < 2) { |
|
144 |
if (v->tick_counter&1) |
|
145 |
return; |
|
146 |
||
147 |
GetNewVehiclePos(v, &gp); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
148 |
|
0 | 149 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
150 |
||
151 |
if (v->next_order == 1) { |
|
152 |
if (++v->age == 38) { |
|
153 |
v->next_order = 2; |
|
154 |
v->age = 0; |
|
155 |
} |
|
156 |
||
157 |
if ((v->tick_counter&7)==0) { |
|
158 |
CreateEffectVehicleRel(v, 0, -17, 2, EV_SMOKE_3); |
|
159 |
} |
|
160 |
} else if (v->next_order == 0) { |
|
161 |
tile = v->tile; /**/ |
|
162 |
||
163 |
if (IS_TILETYPE(tile, MP_STATION) && |
|
164 |
IS_BYTE_INSIDE(_map5[tile], 8, 0x43) && |
|
165 |
IS_HUMAN_PLAYER(_map_owner[tile])) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
166 |
|
0 | 167 |
v->next_order = 1; |
168 |
v->age = 0; |
|
169 |
||
170 |
SET_DPARAM16(0, _map2[tile]); |
|
171 |
AddNewsItem(STR_B000_ZEPPELIN_DISASTER_AT, |
|
172 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), |
|
173 |
v->index, |
|
174 |
0); |
|
175 |
} |
|
176 |
} |
|
177 |
if (v->y_pos >= (TILES_Y+9) * 16 - 1) |
|
178 |
DeleteDisasterVeh(v); |
|
179 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
180 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
181 |
|
0 | 182 |
if (v->next_order > 2) { |
183 |
if (++v->age <= 13320) |
|
184 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
185 |
|
0 | 186 |
tile = v->tile; /**/ |
187 |
||
188 |
if (IS_TILETYPE(tile, MP_STATION) && |
|
189 |
IS_BYTE_INSIDE(_map5[tile], 8, 0x43) && |
|
190 |
IS_HUMAN_PLAYER(_map_owner[tile])) { |
|
191 |
||
192 |
st = DEREF_STATION(_map2[tile]); |
|
193 |
CLRBITS(st->airport_flags, RUNWAY_IN_block); |
|
194 |
} |
|
195 |
||
196 |
SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos); |
|
197 |
DeleteDisasterVeh(v); |
|
198 |
return; |
|
199 |
} |
|
200 |
||
201 |
x = v->x_pos; |
|
202 |
y = v->y_pos; |
|
203 |
z = GetSlopeZ(x,y); |
|
204 |
if (z < v->z_pos) |
|
205 |
z = v->z_pos - 1; |
|
206 |
SetDisasterVehiclePos(v, x, y, z); |
|
207 |
||
208 |
if (++v->age == 1) { |
|
209 |
CreateEffectVehicleRel(v, 0, 7, 8, EV_CRASHED_SMOKE); |
|
210 |
SndPlayVehicleFx(0x10, v); |
|
211 |
v->u.disaster.image_override = 0xF42; |
|
212 |
} else if (v->age == 70) { |
|
213 |
v->u.disaster.image_override = 0xF43; |
|
214 |
} else if (v->age <= 300) { |
|
215 |
if (!(v->tick_counter&7)) { |
|
216 |
uint32 r = Random(); |
|
217 |
||
218 |
CreateEffectVehicleRel(v, |
|
219 |
-7 + (r&0xF), |
|
220 |
-7 + (r>>4&0xF), |
|
221 |
5 + (r>>8&0x7), |
|
222 |
EV_DEMOLISH); |
|
223 |
} |
|
224 |
} else if (v->age == 350) { |
|
225 |
v->next_order = 3; |
|
226 |
v->age = 0; |
|
227 |
} |
|
228 |
||
229 |
tile = v->tile;/**/ |
|
230 |
if (IS_TILETYPE(tile, MP_STATION) && |
|
231 |
IS_BYTE_INSIDE(_map5[tile], 8, 0x43) && |
|
232 |
IS_HUMAN_PLAYER(_map_owner[tile])) { |
|
233 |
||
234 |
st = DEREF_STATION(_map2[tile]); |
|
235 |
SETBITS(st->airport_flags, RUNWAY_IN_block); |
|
236 |
} |
|
237 |
} |
|
238 |
||
239 |
// UFO starts in the middle, and flies around a bit until it locates |
|
240 |
// a road vehicle which it targets. |
|
241 |
static void DisasterTick_UFO(Vehicle *v) |
|
242 |
{ |
|
243 |
GetNewVehiclePosResult gp; |
|
244 |
Vehicle *u; |
|
245 |
uint dist; |
|
246 |
byte z; |
|
247 |
||
248 |
v->u.disaster.image_override = (++v->tick_counter & 8) ? 0xF45 : 0xF44; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
249 |
|
0 | 250 |
if (v->next_order == 0) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
251 |
// fly around randomly |
0 | 252 |
int x = GET_TILE_X(v->dest_tile)*16; |
253 |
int y = GET_TILE_Y(v->dest_tile)*16; |
|
254 |
if (abs(x - v->x_pos) + abs(y - v->y_pos) >= 16) { |
|
255 |
v->direction = GetDirectionTowards(v, x, y); |
|
256 |
GetNewVehiclePos(v, &gp); |
|
257 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
258 |
return; |
|
259 |
} |
|
260 |
if (++v->age < 6) { |
|
261 |
v->dest_tile = TILE_MASK(Random()); |
|
262 |
return; |
|
263 |
} |
|
264 |
v->next_order = 1; |
|
265 |
||
266 |
FOR_ALL_VEHICLES(u) { |
|
267 |
if (u->type == VEH_Road && IS_HUMAN_PLAYER(u->owner)) { |
|
268 |
v->dest_tile = u->index; |
|
269 |
v->age = 0; |
|
270 |
return; |
|
271 |
} |
|
272 |
} |
|
273 |
||
274 |
DeleteDisasterVeh(v); |
|
275 |
} else { |
|
276 |
// target a vehicle |
|
277 |
u = &_vehicles[v->dest_tile]; |
|
278 |
if (u->type != VEH_Road) { |
|
279 |
DeleteDisasterVeh(v); |
|
280 |
return; |
|
281 |
} |
|
282 |
||
283 |
dist = abs(v->x_pos - u->x_pos) + abs(v->y_pos - u->y_pos); |
|
284 |
||
285 |
if (dist < 16 && !(u->vehstatus&VS_HIDDEN) && u->breakdown_ctr==0) { |
|
286 |
u->breakdown_ctr = 3; |
|
287 |
u->breakdown_delay = 140; |
|
288 |
} |
|
289 |
||
290 |
v->direction = GetDirectionTowards(v, u->x_pos, u->y_pos); |
|
291 |
GetNewVehiclePos(v, &gp); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
292 |
|
0 | 293 |
z = v->z_pos; |
294 |
if (dist <= 16 && z > u->z_pos) z--; |
|
295 |
SetDisasterVehiclePos(v, gp.x, gp.y, z); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
296 |
|
0 | 297 |
if (z <= u->z_pos && (u->vehstatus&VS_HIDDEN)==0) { |
298 |
v->age++; |
|
299 |
if (u->u.road.crashed_ctr == 0) { |
|
300 |
u->u.road.crashed_ctr++; |
|
301 |
u->vehstatus |= VS_CRASHED; |
|
302 |
||
303 |
AddNewsItem(STR_B001_ROAD_VEHICLE_DESTROYED, |
|
304 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), |
|
305 |
u->index, |
|
306 |
0); |
|
307 |
} |
|
308 |
} |
|
309 |
||
310 |
// destroy? |
|
311 |
if (v->age > 50) { |
|
312 |
CreateEffectVehicleRel(v, 0, 7, 8, EV_CRASHED_SMOKE); |
|
313 |
SndPlayVehicleFx(0x10, v); |
|
314 |
DeleteDisasterVeh(v); |
|
315 |
} |
|
316 |
} |
|
317 |
} |
|
318 |
||
319 |
static void DestructIndustry(Industry *i) |
|
320 |
{ |
|
321 |
uint tile; |
|
322 |
byte index = i - _industries; |
|
323 |
||
324 |
for(tile=0; tile != TILES_X*TILES_Y; tile++) { |
|
325 |
if (IS_TILETYPE(tile, MP_INDUSTRY) && _map2[tile] == index) { |
|
326 |
_map_owner[tile] = 0; |
|
327 |
MarkTileDirtyByTile(tile); |
|
328 |
} |
|
329 |
} |
|
330 |
} |
|
331 |
||
332 |
// Airplane which destroys an oil refinery |
|
333 |
static void DisasterTick_2(Vehicle *v) |
|
334 |
{ |
|
335 |
GetNewVehiclePosResult gp; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
336 |
|
0 | 337 |
v->tick_counter++; |
338 |
v->u.disaster.image_override = (v->next_order == 1 && v->tick_counter&4) ? 0xF4F : 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
339 |
|
0 | 340 |
GetNewVehiclePos(v, &gp); |
341 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
342 |
||
343 |
if (gp.x < -160) { |
|
344 |
DeleteDisasterVeh(v); |
|
345 |
return; |
|
346 |
} |
|
347 |
||
348 |
if (v->next_order == 2) { |
|
349 |
if (!(v->tick_counter&3)) { |
|
350 |
Industry *i = DEREF_INDUSTRY(v->dest_tile); |
|
351 |
int x = GET_TILE_X(i->xy)*16; |
|
352 |
int y = GET_TILE_Y(i->xy)*16; |
|
353 |
uint32 r = Random(); |
|
354 |
||
355 |
CreateEffectVehicleAbove( |
|
356 |
x + (r & 0x3F), |
|
357 |
y + (r >> 6 & 0x3F), |
|
358 |
(r >> 12 & 0xF), |
|
359 |
EV_DEMOLISH); |
|
360 |
||
361 |
if (++v->age >= 55) |
|
362 |
v->next_order = 3; |
|
363 |
} |
|
364 |
} else if (v->next_order == 1) { |
|
365 |
if (++v->age == 112) { |
|
366 |
Industry *i; |
|
367 |
||
368 |
v->next_order = 2; |
|
369 |
v->age = 0; |
|
370 |
||
371 |
i = DEREF_INDUSTRY(v->dest_tile); |
|
372 |
DestructIndustry(i); |
|
373 |
||
374 |
SET_DPARAM16(0, i->town->index); |
|
375 |
AddNewsItem(STR_B002_OIL_REFINERY_EXPLOSION, NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy, 0); |
|
376 |
SndPlayTileFx(0x10, i->xy); |
|
377 |
} |
|
378 |
} else if (v->next_order == 0) { |
|
379 |
int x,y; |
|
380 |
uint tile; |
|
381 |
int ind; |
|
382 |
||
383 |
x = v->x_pos - 15*16; |
|
384 |
y = v->y_pos; |
|
385 |
||
386 |
if ( (uint)x > (TILES_X-1) * 16-1) |
|
387 |
return; |
|
388 |
||
389 |
tile = TILE_FROM_XY(x,y); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
390 |
if (!IS_TILETYPE(tile, MP_INDUSTRY)) |
0 | 391 |
return; |
392 |
||
393 |
v->dest_tile = ind = _map2[tile]; |
|
394 |
||
395 |
if (DEREF_INDUSTRY(ind)->type == IT_OIL_REFINERY) { |
|
396 |
v->next_order = 1; |
|
397 |
v->age = 0; |
|
398 |
} |
|
399 |
} |
|
400 |
} |
|
401 |
||
402 |
// Helicopter which destroys a factory |
|
403 |
static void DisasterTick_3(Vehicle *v) |
|
404 |
{ |
|
405 |
GetNewVehiclePosResult gp; |
|
406 |
||
407 |
v->tick_counter++; |
|
408 |
v->u.disaster.image_override = (v->next_order == 1 && v->tick_counter&4) ? 0xF53 : 0; |
|
409 |
||
410 |
GetNewVehiclePos(v, &gp); |
|
411 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
412 |
||
413 |
if (gp.x > TILES_X * 16 + 9*16 - 1) { |
|
414 |
DeleteDisasterVeh(v); |
|
415 |
return; |
|
416 |
} |
|
417 |
||
418 |
if (v->next_order == 2) { |
|
419 |
if (!(v->tick_counter&3)) { |
|
420 |
Industry *i = DEREF_INDUSTRY(v->dest_tile); |
|
421 |
int x = GET_TILE_X(i->xy)*16; |
|
422 |
int y = GET_TILE_Y(i->xy)*16; |
|
423 |
uint32 r = Random(); |
|
424 |
||
425 |
CreateEffectVehicleAbove( |
|
426 |
x + (r & 0x3F), |
|
427 |
y + (r >> 6 & 0x3F), |
|
428 |
(r >> 12 & 0xF), |
|
429 |
EV_DEMOLISH); |
|
430 |
||
431 |
if (++v->age >= 55) |
|
432 |
v->next_order = 3; |
|
433 |
} |
|
434 |
} else if (v->next_order == 1) { |
|
435 |
if (++v->age == 112) { |
|
436 |
Industry *i; |
|
437 |
||
438 |
v->next_order = 2; |
|
439 |
v->age = 0; |
|
440 |
||
441 |
i = DEREF_INDUSTRY(v->dest_tile); |
|
442 |
DestructIndustry(i); |
|
443 |
||
444 |
SET_DPARAM16(0, i->town->index); |
|
445 |
AddNewsItem(STR_B003_FACTORY_DESTROYED_IN_SUSPICIOUS, NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy, 0); |
|
446 |
SndPlayTileFx(0x10, i->xy); |
|
447 |
} |
|
448 |
} else if (v->next_order == 0) { |
|
449 |
int x,y; |
|
450 |
uint tile; |
|
451 |
int ind; |
|
452 |
||
453 |
x = v->x_pos - 15*16; |
|
454 |
y = v->y_pos; |
|
455 |
||
456 |
if ( (uint)x > (TILES_X-1) * 16-1) |
|
457 |
return; |
|
458 |
||
459 |
tile = TILE_FROM_XY(x,y); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
460 |
if (!IS_TILETYPE(tile, MP_INDUSTRY)) |
0 | 461 |
return; |
462 |
||
463 |
v->dest_tile = ind = _map2[tile]; |
|
464 |
||
465 |
if (DEREF_INDUSTRY(ind)->type == IT_FACTORY) { |
|
466 |
v->next_order = 1; |
|
467 |
v->age = 0; |
|
468 |
} |
|
469 |
} |
|
470 |
} |
|
471 |
||
472 |
// Helicopter rotor blades |
|
473 |
static void DisasterTick_3b(Vehicle *v) |
|
474 |
{ |
|
475 |
if (++v->tick_counter & 1) |
|
476 |
return; |
|
477 |
||
478 |
if (++v->cur_image == 0xF40 + 1) |
|
479 |
v->cur_image = 0xF3E; |
|
480 |
||
481 |
VehiclePositionChanged(v); |
|
482 |
BeginVehicleMove(v); |
|
483 |
EndVehicleMove(v); |
|
484 |
} |
|
485 |
||
486 |
// Big UFO which lands on a piece of rail. |
|
487 |
// Will be shot down by a plane |
|
488 |
static void DisasterTick_4(Vehicle *v) |
|
489 |
{ |
|
490 |
GetNewVehiclePosResult gp; |
|
491 |
byte z; |
|
492 |
Vehicle *u,*w; |
|
493 |
Town *t; |
|
494 |
uint tile,tile_org; |
|
495 |
||
496 |
v->tick_counter++; |
|
497 |
||
498 |
if (v->next_order == 1) { |
|
499 |
int x = GET_TILE_X(v->dest_tile)*16 + 8; |
|
500 |
int y = GET_TILE_Y(v->dest_tile)*16 + 8; |
|
501 |
if (abs(v->x_pos - x) + abs(v->y_pos - y) >= 8) { |
|
502 |
v->direction = GetDirectionTowards(v, x, y); |
|
503 |
||
504 |
GetNewVehiclePos(v, &gp); |
|
505 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
506 |
return; |
|
507 |
} |
|
508 |
||
509 |
z = GetSlopeZ(v->x_pos, v->y_pos); |
|
510 |
if (z < v->z_pos) { |
|
511 |
SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos - 1); |
|
512 |
return; |
|
513 |
} |
|
514 |
||
515 |
v->next_order = 2; |
|
516 |
||
517 |
FOR_ALL_VEHICLES(u) { |
|
518 |
if (u->type == VEH_Train || u->type == VEH_Road) { |
|
519 |
if (abs(u->x_pos - v->x_pos) + abs(u->y_pos - v->y_pos) <= 12*16) { |
|
520 |
u->breakdown_ctr = 5; |
|
521 |
u->breakdown_delay = 0xF0; |
|
522 |
} |
|
523 |
} |
|
524 |
} |
|
525 |
||
526 |
t = ClosestTownFromTile(v->dest_tile, (uint)-1); |
|
527 |
SET_DPARAM16(0, t->index); |
|
528 |
AddNewsItem(STR_B004_UFO_LANDS_NEAR, |
|
529 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ACCIDENT, 0), |
|
530 |
v->tile, |
|
531 |
0); |
|
532 |
||
533 |
u = ForceAllocateSpecialVehicle(); |
|
534 |
if (u == NULL) { |
|
535 |
DeleteDisasterVeh(v); |
|
536 |
return; |
|
537 |
} |
|
538 |
||
539 |
InitializeDisasterVehicle(u, -6*16, v->y_pos, 135, 5, 11); |
|
540 |
u->u.disaster.unk2 = v->index; |
|
541 |
||
542 |
w = ForceAllocateSpecialVehicle(); |
|
543 |
if (w == NULL) |
|
544 |
return; |
|
545 |
||
546 |
u->next = w; |
|
547 |
InitializeDisasterVehicle(w, -6*16, v->y_pos, 0, 5, 12); |
|
548 |
w->vehstatus |= VS_DISASTER; |
|
549 |
} else if (v->next_order < 1) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
550 |
|
0 | 551 |
int x = GET_TILE_X(v->dest_tile)*16; |
552 |
int y = GET_TILE_Y(v->dest_tile)*16; |
|
553 |
if (abs(x - v->x_pos) + abs(y - v->y_pos) >= 16) { |
|
554 |
v->direction = GetDirectionTowards(v, x, y); |
|
555 |
GetNewVehiclePos(v, &gp); |
|
556 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
557 |
return; |
|
558 |
} |
|
559 |
||
560 |
if (++v->age < 6) { |
|
561 |
v->dest_tile = TILE_MASK(Random()); |
|
562 |
return; |
|
563 |
} |
|
564 |
v->next_order = 1; |
|
565 |
||
566 |
tile_org = tile = TILE_MASK(Random()); |
|
567 |
do { |
|
568 |
if (IS_TILETYPE(tile, MP_RAILWAY) && |
|
569 |
(_map5[tile]&~3)!=0xC0 && IS_HUMAN_PLAYER(_map_owner[tile])) |
|
570 |
break; |
|
571 |
tile = TILE_MASK(tile+1); |
|
572 |
} while (tile != tile_org); |
|
573 |
v->dest_tile = tile; |
|
574 |
v->age = 0; |
|
575 |
} else |
|
576 |
return; |
|
577 |
} |
|
578 |
||
579 |
// The plane which will shoot down the UFO |
|
580 |
static void DisasterTick_4b(Vehicle *v) |
|
581 |
{ |
|
582 |
GetNewVehiclePosResult gp; |
|
583 |
Vehicle *u; |
|
584 |
int i; |
|
585 |
||
586 |
v->tick_counter++; |
|
587 |
||
588 |
GetNewVehiclePos(v, &gp); |
|
589 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
590 |
||
591 |
if (gp.x > TILES_X * 16 + 9*16 - 1) { |
|
592 |
DeleteDisasterVeh(v); |
|
593 |
return; |
|
594 |
} |
|
595 |
||
596 |
if (v->next_order == 0) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
597 |
u = &_vehicles[v->u.disaster.unk2]; |
0 | 598 |
if (abs(v->x_pos - u->x_pos) > 16) |
599 |
return; |
|
600 |
v->next_order = 1; |
|
601 |
||
602 |
CreateEffectVehicleRel(u, 0, 7, 8, EV_CRASHED_SMOKE); |
|
603 |
SndPlayVehicleFx(0x10, u); |
|
604 |
||
605 |
DeleteDisasterVeh(u); |
|
606 |
||
607 |
for(i=0; i!=80; i++) { |
|
608 |
uint32 r = Random(); |
|
609 |
CreateEffectVehicleAbove( |
|
610 |
v->x_pos-32+(r&0x3F), |
|
611 |
v->y_pos-32+(r>>5&0x3F), |
|
612 |
0, |
|
613 |
EV_DEMOLISH); |
|
614 |
} |
|
615 |
||
616 |
BEGIN_TILE_LOOP(tile,6,6,v->tile - TILE_XY(3,3)) |
|
617 |
tile = TILE_MASK(tile); |
|
618 |
DisasterClearSquare(tile); |
|
619 |
END_TILE_LOOP(tile,6,6,v->tile - TILE_XY(3,3)) |
|
620 |
} |
|
621 |
} |
|
622 |
||
623 |
// Submarine handler |
|
624 |
static void DisasterTick_5_and_6(Vehicle *v) |
|
625 |
{ |
|
626 |
uint32 r; |
|
627 |
GetNewVehiclePosResult gp; |
|
628 |
uint tile; |
|
629 |
||
630 |
v->tick_counter++; |
|
631 |
||
632 |
if (++v->age > 8880) { |
|
633 |
VehiclePositionChanged(v); |
|
634 |
BeginVehicleMove(v); |
|
635 |
EndVehicleMove(v); |
|
636 |
DeleteVehicle(v); |
|
637 |
return; |
|
638 |
} |
|
639 |
||
640 |
if (!(v->tick_counter&1)) |
|
641 |
return; |
|
642 |
||
643 |
tile = v->tile + _tileoffs_by_dir[v->direction >> 1]; |
|
644 |
if (IsValidTile(tile) && |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
0
diff
changeset
|
645 |
(r=GetTileTrackStatus(tile,TRANSPORT_WATER),(byte)(r+(r >> 8)) == 0x3F) && |
0 | 646 |
!CHANCE16(1,90)) { |
647 |
GetNewVehiclePos(v, &gp); |
|
648 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
649 |
return; |
|
650 |
} |
|
651 |
||
652 |
v->direction = (v->direction + ((Random()&1)?2:-2))&7; |
|
653 |
} |
|
654 |
||
655 |
||
656 |
static void DisasterTick_NULL(Vehicle *v) {} |
|
657 |
typedef void DisasterVehicleTickProc(Vehicle *v); |
|
658 |
||
659 |
static DisasterVehicleTickProc * const _disastervehicle_tick_procs[] = { |
|
660 |
DisasterTick_Zeppeliner,DisasterTick_NULL, |
|
661 |
DisasterTick_UFO,DisasterTick_NULL, |
|
662 |
DisasterTick_2,DisasterTick_NULL, |
|
663 |
DisasterTick_3,DisasterTick_NULL,DisasterTick_3b, |
|
664 |
DisasterTick_4,DisasterTick_NULL, |
|
665 |
DisasterTick_4b,DisasterTick_NULL, |
|
666 |
DisasterTick_5_and_6, |
|
667 |
DisasterTick_5_and_6, |
|
668 |
}; |
|
669 |
||
670 |
||
671 |
void DisasterVehicle_Tick(Vehicle *v) |
|
672 |
{ |
|
673 |
_disastervehicle_tick_procs[v->subtype](v); |
|
674 |
} |
|
675 |
||
676 |
void HandleClickOnDisasterVeh(Vehicle *v) |
|
677 |
{ |
|
678 |
// not used |
|
679 |
} |
|
680 |
||
681 |
void OnNewDay_DisasterVehicle(Vehicle *v) |
|
682 |
{ |
|
683 |
// not used |
|
684 |
} |
|
685 |
||
686 |
typedef void DisasterInitProc(); |
|
687 |
||
688 |
// Zeppeliner which crashes on a small airport |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
689 |
static void Disaster0_Init() |
0 | 690 |
{ |
691 |
Vehicle *v = ForceAllocateSpecialVehicle(), *u; |
|
692 |
Station *st; |
|
693 |
int x; |
|
694 |
||
695 |
if (v == NULL) |
|
696 |
return; |
|
697 |
||
698 |
for(st=_stations;;) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
699 |
if (st->xy && st->airport_tile != 0 && |
0 | 700 |
st->airport_type <= 1 && |
701 |
IS_HUMAN_PLAYER(st->owner)) { |
|
702 |
x = (GET_TILE_X(st->xy) + 2) * 16; |
|
703 |
break; |
|
704 |
} |
|
705 |
||
706 |
if (++st == endof(_stations)) { |
|
707 |
x = (GET_TILE_X(Random())) * 16 + 8; |
|
708 |
break; |
|
709 |
} |
|
710 |
} |
|
711 |
||
712 |
InitializeDisasterVehicle(v, x, 0, 135, 3, 0); |
|
713 |
||
714 |
// Allocate shadow too? |
|
715 |
u = ForceAllocateSpecialVehicle(); |
|
716 |
if (u != NULL) { |
|
717 |
v->next = u; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
718 |
InitializeDisasterVehicle(u,x,0,0,3,1); |
0 | 719 |
u->vehstatus |= VS_DISASTER; |
720 |
} |
|
721 |
} |
|
722 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
723 |
static void Disaster1_Init() |
0 | 724 |
{ |
725 |
Vehicle *v = ForceAllocateSpecialVehicle(), *u; |
|
726 |
int x; |
|
727 |
||
728 |
if (v == NULL) |
|
729 |
return; |
|
730 |
||
731 |
x = (GET_TILE_X(Random())) * 16 + 8; |
|
732 |
||
733 |
InitializeDisasterVehicle(v, x, 0, 135, 3, 2); |
|
734 |
v->dest_tile = TILE_XY(TILES_X/2,TILES_Y/2); |
|
735 |
v->age = 0; |
|
736 |
||
737 |
// Allocate shadow too? |
|
738 |
u = ForceAllocateSpecialVehicle(); |
|
739 |
if (u != NULL) { |
|
740 |
v->next = u; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
741 |
InitializeDisasterVehicle(u,x,0,0,3,3); |
0 | 742 |
u->vehstatus |= VS_DISASTER; |
743 |
} |
|
744 |
} |
|
745 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
746 |
static void Disaster2_Init() |
0 | 747 |
{ |
748 |
Industry *i, *found; |
|
749 |
Vehicle *v,*u; |
|
750 |
int x,y; |
|
751 |
||
752 |
for(found=NULL,i=_industries; i != endof(_industries); i++) { |
|
753 |
if (i->xy != 0 && |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
754 |
i->type == IT_OIL_REFINERY && |
0 | 755 |
(found==NULL || CHANCE16(1,2))) { |
756 |
found = i; |
|
757 |
} |
|
758 |
} |
|
759 |
||
760 |
if (found == NULL) |
|
761 |
return; |
|
762 |
||
763 |
v = ForceAllocateSpecialVehicle(); |
|
764 |
if (v == NULL) |
|
765 |
return; |
|
766 |
||
767 |
x = (TILES_X+9) * 16 - 1; |
|
768 |
y = GET_TILE_Y(found->xy)*16 + 37; |
|
769 |
||
770 |
InitializeDisasterVehicle(v,x,y, 135,1,4); |
|
771 |
||
772 |
u = ForceAllocateSpecialVehicle(); |
|
773 |
if (u != NULL) { |
|
774 |
v->next = u; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
775 |
InitializeDisasterVehicle(u,x,y,0,3,5); |
0 | 776 |
u->vehstatus |= VS_DISASTER; |
777 |
} |
|
778 |
} |
|
779 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
780 |
static void Disaster3_Init() |
0 | 781 |
{ |
782 |
Industry *i, *found; |
|
783 |
Vehicle *v,*u,*w; |
|
784 |
int x,y; |
|
785 |
||
786 |
for(found=NULL,i=_industries; i != endof(_industries); i++) { |
|
787 |
if (i->xy != 0 && |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
788 |
i->type == IT_FACTORY && |
0 | 789 |
(found==NULL || CHANCE16(1,2))) { |
790 |
found = i; |
|
791 |
} |
|
792 |
} |
|
793 |
||
794 |
if (found == NULL) |
|
795 |
return; |
|
796 |
||
797 |
v = ForceAllocateSpecialVehicle(); |
|
798 |
if (v == NULL) |
|
799 |
return; |
|
800 |
||
801 |
x = -16 * 16; |
|
802 |
y = GET_TILE_Y(found->xy)*16 + 37; |
|
803 |
||
804 |
InitializeDisasterVehicle(v,x,y, 135,5,6); |
|
805 |
||
806 |
u = ForceAllocateSpecialVehicle(); |
|
807 |
if (u != NULL) { |
|
808 |
v->next = u; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
809 |
InitializeDisasterVehicle(u,x,y,0,5,7); |
0 | 810 |
u->vehstatus |= VS_DISASTER; |
811 |
||
812 |
w = ForceAllocateSpecialVehicle(); |
|
813 |
if (w != NULL) { |
|
814 |
u->next = w; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
815 |
InitializeDisasterVehicle(w,x,y,140,5,8); |
0 | 816 |
} |
817 |
} |
|
818 |
} |
|
819 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
820 |
static void Disaster4_Init() |
0 | 821 |
{ |
822 |
Vehicle *v = ForceAllocateSpecialVehicle(), *u; |
|
823 |
int x,y; |
|
824 |
||
825 |
if (v == NULL) |
|
826 |
return; |
|
827 |
||
828 |
x = (GET_TILE_X(Random())) * 16 + 8; |
|
829 |
||
830 |
y = (TILES_X-1)*16-1; |
|
831 |
InitializeDisasterVehicle(v, x, y, 135, 7, 9); |
|
832 |
v->dest_tile = TILE_XY(TILES_X/2,TILES_Y/2); |
|
833 |
v->age = 0; |
|
834 |
||
835 |
// Allocate shadow too? |
|
836 |
u = ForceAllocateSpecialVehicle(); |
|
837 |
if (u != NULL) { |
|
838 |
v->next = u; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
839 |
InitializeDisasterVehicle(u,x,y,0,7,10); |
0 | 840 |
u->vehstatus |= VS_DISASTER; |
841 |
} |
|
842 |
} |
|
843 |
||
844 |
// Submarine type 1 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
845 |
static void Disaster5_Init() |
0 | 846 |
{ |
847 |
Vehicle *v = ForceAllocateSpecialVehicle(); |
|
848 |
int x,y; |
|
849 |
byte dir; |
|
850 |
uint32 r; |
|
851 |
||
852 |
if (v == NULL) |
|
853 |
return; |
|
854 |
||
855 |
r = Random(); |
|
856 |
x = (GET_TILE_X(r)) * 16 + 8; |
|
857 |
||
858 |
y = 8; |
|
859 |
dir = 3; |
|
860 |
if (r & 0x80000000) { y = (TILES_X-1) * 16 - 8 - 1; dir = 7; } |
|
861 |
InitializeDisasterVehicle(v, x, y, 0, dir,13); |
|
862 |
v->age = 0; |
|
863 |
} |
|
864 |
||
865 |
// Submarine type 2 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
866 |
static void Disaster6_Init() |
0 | 867 |
{ |
868 |
Vehicle *v = ForceAllocateSpecialVehicle(); |
|
869 |
int x,y; |
|
870 |
byte dir; |
|
871 |
uint32 r; |
|
872 |
||
873 |
if (v == NULL) |
|
874 |
return; |
|
875 |
||
876 |
r = Random(); |
|
877 |
x = (GET_TILE_X(r)) * 16 + 8; |
|
878 |
||
879 |
y = 8; |
|
880 |
dir = 3; |
|
881 |
if (r & 0x80000000) { y = (TILES_X-1) * 16 - 8 - 1; dir = 7; } |
|
882 |
InitializeDisasterVehicle(v, x, y, 0, dir,14); |
|
883 |
v->age = 0; |
|
884 |
} |
|
885 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
886 |
static void Disaster7_Init() |
0 | 887 |
{ |
888 |
Industry *i; |
|
889 |
int maxloop = 15; |
|
890 |
int index = Random() & 0xF; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
891 |
|
0 | 892 |
do { |
893 |
for(i=_industries; i != endof(_industries); i++) { |
|
894 |
if (i->xy != 0 && i->type == IT_COAL_MINE && --index < 0) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
895 |
|
0 | 896 |
SET_DPARAM16(0, i->town->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
897 |
AddNewsItem(STR_B005_COAL_MINE_SUBSIDENCE_LEAVES, |
0 | 898 |
NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy + TILE_XY(1,1), 0); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
899 |
|
0 | 900 |
{ |
901 |
uint tile = i->xy; |
|
902 |
int step = _tileoffs_by_dir[Random() & 3]; |
|
903 |
int count = 30; |
|
904 |
do { |
|
905 |
DisasterClearSquare(tile); |
|
906 |
tile = TILE_MASK(tile + step); |
|
907 |
} while (--count); |
|
908 |
} |
|
909 |
return; |
|
910 |
} |
|
911 |
} |
|
912 |
} while (--maxloop != 0); |
|
913 |
} |
|
914 |
||
915 |
static DisasterInitProc * const _disaster_initprocs[] = { |
|
916 |
Disaster0_Init, |
|
917 |
Disaster1_Init, |
|
918 |
Disaster2_Init, |
|
919 |
Disaster3_Init, |
|
920 |
Disaster4_Init, |
|
921 |
Disaster5_Init, |
|
922 |
Disaster6_Init, |
|
923 |
Disaster7_Init, |
|
924 |
}; |
|
925 |
||
926 |
typedef struct { |
|
927 |
byte min,max; |
|
928 |
} DisasterYears; |
|
929 |
||
930 |
#define MK(a,b) {a-20,b-20} |
|
931 |
static const DisasterYears _dis_years[8] = { |
|
932 |
MK(30,55), |
|
933 |
MK(40,70), |
|
934 |
MK(60,90), |
|
935 |
MK(70,100), |
|
936 |
MK(100,200), |
|
937 |
MK(40,65), |
|
938 |
MK(75,110), |
|
939 |
MK(50,85), |
|
940 |
}; |
|
941 |
||
942 |
||
410 | 943 |
static void DoDisaster() |
0 | 944 |
{ |
945 |
byte buf[8]; |
|
946 |
byte year = _cur_year; |
|
947 |
int i,j; |
|
948 |
||
949 |
for(i=j=0; i!=lengthof(_dis_years); i++) { |
|
950 |
if (year >= _dis_years[i].min && |
|
951 |
year < _dis_years[i].max) |
|
952 |
buf[j++] = i; |
|
953 |
} |
|
954 |
||
955 |
if (j == 0) |
|
956 |
return; |
|
957 |
||
958 |
_disaster_initprocs[buf[(uint16)Random() * j >> 16]](); |
|
959 |
} |
|
960 |
||
961 |
||
962 |
static void ResetDisasterDelay() |
|
963 |
{ |
|
964 |
_disaster_delay = (int)(Random() & 0x1FF) + 730; |
|
965 |
} |
|
966 |
||
967 |
void DisasterDailyLoop() |
|
968 |
{ |
|
969 |
if (--_disaster_delay != 0) |
|
970 |
return; |
|
971 |
||
972 |
ResetDisasterDelay(); |
|
973 |
||
974 |
if (_opt.diff.disasters != 0) |
|
975 |
DoDisaster(); |
|
976 |
} |
|
977 |
||
978 |
void StartupDisasters() { |
|
979 |
ResetDisasterDelay(); |
|
980 |
} |
|
981 |