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