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