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