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