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