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