author | truelight |
Wed, 16 Nov 2005 14:41:01 +0000 | |
changeset 2668 | 54d9f9d4dca3 |
parent 2662 | 42c11a1a0a4b |
child 2674 | 1d68ffc9f406 |
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" |
2535 | 20 |
#include "table/sprites.h" |
0 | 21 |
|
1048 | 22 |
static void DisasterClearSquare(TileIndex tile) |
0 | 23 |
{ |
2639 | 24 |
if (!EnsureNoVehicle(tile)) return; |
0 | 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: |
2668
54d9f9d4dca3
(svn r3210) -Codechange: use IsRailWaypoint where possible (instead of magicnumbers)
truelight
parents:
2662
diff
changeset
|
28 |
if (IS_HUMAN_PLAYER(GetTileOwner(tile)) && !IsRailWaypoint(tile)) 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); |
2535 | 226 |
v->u.disaster.image_override = SPR_BLIMP_CRASHING; |
0 | 227 |
} else if (v->age == 70) { |
2535 | 228 |
v->u.disaster.image_override = SPR_BLIMP_CRASHED; |
0 | 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 |
||
2535 | 264 |
v->u.disaster.image_override = (++v->tick_counter & 8) ? SPR_UFO_SMALL_SCOUT_DARKER : SPR_UFO_SMALL_SCOUT; |
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 = |
2639 | 354 |
(v->current_order.station == 1 && v->tick_counter & 4) ? SPR_F_15_FIRING : 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 = |
2639 | 425 |
(v->current_order.station == 1 && v->tick_counter & 4) ? SPR_AH_64A_FIRING : 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 |
||
2535 | 495 |
if (++v->cur_image > SPR_ROTOR_MOVING_3) v->cur_image = SPR_ROTOR_MOVING_1; |
0 | 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
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
510 |
TileIndex tile; |
4392ae3d8e31
(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
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
515 |
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
|
516 |
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
|
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
eec6c0294435
(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
17ab2f22ff74
(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
eec6c0294435
(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
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
|
568 |
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
|
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
eec6c0294435
(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
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
|
585 |
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
|
586 |
(_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
|
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
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
613 |
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
|
614 |
u = GetVehicle(v->u.disaster.unk2); |
0 | 615 |
if (abs(v->x_pos - u->x_pos) > 16) |
616 |
return; |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
617 |
v->current_order.station = 1; |
0 | 618 |
|
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
|
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
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
|
627 |
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
|
628 |
GB(r, 5, 6) + v->y_pos - 32, |
0 | 629 |
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
|
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
4392ae3d8e31
(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 |
||
2642 | 669 |
v->direction = (v->direction + (GB(Random(), 0, 1) ? 2 : -2)) & 7; |
0 | 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 |
||
694 |
void OnNewDay_DisasterVehicle(Vehicle *v) |
|
695 |
{ |
|
696 |
// not used |
|
697 |
} |
|
698 |
||
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
|
699 |
typedef void DisasterInitProc(void); |
0 | 700 |
|
701 |
// 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
|
702 |
static void Disaster0_Init(void) |
0 | 703 |
{ |
704 |
Vehicle *v = ForceAllocateSpecialVehicle(), *u; |
|
705 |
Station *st; |
|
706 |
int x; |
|
707 |
||
708 |
if (v == NULL) |
|
709 |
return; |
|
710 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
711 |
/* 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
|
712 |
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
|
713 |
x = TileX(Random()) * 16 + 8; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
714 |
|
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
715 |
FOR_ALL_STATIONS(st) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
716 |
if (st->xy && st->airport_tile != 0 && |
0 | 717 |
st->airport_type <= 1 && |
718 |
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
|
719 |
x = (TileX(st->xy) + 2) * 16; |
0 | 720 |
break; |
721 |
} |
|
722 |
} |
|
723 |
||
724 |
InitializeDisasterVehicle(v, x, 0, 135, 3, 0); |
|
725 |
||
726 |
// Allocate shadow too? |
|
727 |
u = ForceAllocateSpecialVehicle(); |
|
728 |
if (u != NULL) { |
|
729 |
v->next = u; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
730 |
InitializeDisasterVehicle(u, x, 0, 0, 3, 1); |
0 | 731 |
u->vehstatus |= VS_DISASTER; |
732 |
} |
|
733 |
} |
|
734 |
||
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
|
735 |
static void Disaster1_Init(void) |
0 | 736 |
{ |
737 |
Vehicle *v = ForceAllocateSpecialVehicle(), *u; |
|
738 |
int x; |
|
739 |
||
740 |
if (v == NULL) |
|
741 |
return; |
|
742 |
||
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
|
743 |
x = TileX(Random()) * 16 + 8; |
0 | 744 |
|
745 |
InitializeDisasterVehicle(v, x, 0, 135, 3, 2); |
|
1981 | 746 |
v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2); |
0 | 747 |
v->age = 0; |
748 |
||
749 |
// Allocate shadow too? |
|
750 |
u = ForceAllocateSpecialVehicle(); |
|
751 |
if (u != NULL) { |
|
752 |
v->next = u; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
753 |
InitializeDisasterVehicle(u,x,0,0,3,3); |
0 | 754 |
u->vehstatus |= VS_DISASTER; |
755 |
} |
|
756 |
} |
|
757 |
||
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
|
758 |
static void Disaster2_Init(void) |
0 | 759 |
{ |
760 |
Industry *i, *found; |
|
761 |
Vehicle *v,*u; |
|
762 |
int x,y; |
|
763 |
||
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
764 |
found = NULL; |
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
765 |
|
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
766 |
FOR_ALL_INDUSTRIES(i) { |
0 | 767 |
if (i->xy != 0 && |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
768 |
i->type == IT_OIL_REFINERY && |
0 | 769 |
(found==NULL || CHANCE16(1,2))) { |
770 |
found = i; |
|
771 |
} |
|
772 |
} |
|
773 |
||
774 |
if (found == NULL) |
|
775 |
return; |
|
776 |
||
777 |
v = ForceAllocateSpecialVehicle(); |
|
778 |
if (v == NULL) |
|
779 |
return; |
|
780 |
||
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
830
diff
changeset
|
781 |
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
|
782 |
y = TileY(found->xy) * 16 + 37; |
0 | 783 |
|
784 |
InitializeDisasterVehicle(v,x,y, 135,1,4); |
|
785 |
||
786 |
u = ForceAllocateSpecialVehicle(); |
|
787 |
if (u != NULL) { |
|
788 |
v->next = u; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
789 |
InitializeDisasterVehicle(u,x,y,0,3,5); |
0 | 790 |
u->vehstatus |= VS_DISASTER; |
791 |
} |
|
792 |
} |
|
793 |
||
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
|
794 |
static void Disaster3_Init(void) |
0 | 795 |
{ |
796 |
Industry *i, *found; |
|
797 |
Vehicle *v,*u,*w; |
|
798 |
int x,y; |
|
799 |
||
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
800 |
found = NULL; |
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
801 |
|
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
802 |
FOR_ALL_INDUSTRIES(i) { |
0 | 803 |
if (i->xy != 0 && |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
804 |
i->type == IT_FACTORY && |
0 | 805 |
(found==NULL || CHANCE16(1,2))) { |
806 |
found = i; |
|
807 |
} |
|
808 |
} |
|
809 |
||
810 |
if (found == NULL) |
|
811 |
return; |
|
812 |
||
813 |
v = ForceAllocateSpecialVehicle(); |
|
814 |
if (v == NULL) |
|
815 |
return; |
|
816 |
||
817 |
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
|
818 |
y = TileY(found->xy) * 16 + 37; |
0 | 819 |
|
820 |
InitializeDisasterVehicle(v,x,y, 135,5,6); |
|
821 |
||
822 |
u = ForceAllocateSpecialVehicle(); |
|
823 |
if (u != NULL) { |
|
824 |
v->next = u; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
825 |
InitializeDisasterVehicle(u,x,y,0,5,7); |
0 | 826 |
u->vehstatus |= VS_DISASTER; |
827 |
||
828 |
w = ForceAllocateSpecialVehicle(); |
|
829 |
if (w != NULL) { |
|
830 |
u->next = w; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
831 |
InitializeDisasterVehicle(w,x,y,140,5,8); |
0 | 832 |
} |
833 |
} |
|
834 |
} |
|
835 |
||
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
|
836 |
static void Disaster4_Init(void) |
0 | 837 |
{ |
838 |
Vehicle *v = ForceAllocateSpecialVehicle(), *u; |
|
839 |
int x,y; |
|
840 |
||
2639 | 841 |
if (v == NULL) return; |
0 | 842 |
|
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
843 |
x = TileX(Random()) * 16 + 8; |
0 | 844 |
|
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
830
diff
changeset
|
845 |
y = MapMaxX() * 16 - 1; |
0 | 846 |
InitializeDisasterVehicle(v, x, y, 135, 7, 9); |
1981 | 847 |
v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2); |
0 | 848 |
v->age = 0; |
849 |
||
850 |
// Allocate shadow too? |
|
851 |
u = ForceAllocateSpecialVehicle(); |
|
852 |
if (u != NULL) { |
|
853 |
v->next = u; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
854 |
InitializeDisasterVehicle(u,x,y,0,7,10); |
0 | 855 |
u->vehstatus |= VS_DISASTER; |
856 |
} |
|
857 |
} |
|
858 |
||
859 |
// Submarine type 1 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
860 |
static void Disaster5_Init(void) |
0 | 861 |
{ |
862 |
Vehicle *v = ForceAllocateSpecialVehicle(); |
|
863 |
int x,y; |
|
864 |
byte dir; |
|
865 |
uint32 r; |
|
866 |
||
2639 | 867 |
if (v == NULL) return; |
0 | 868 |
|
869 |
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
|
870 |
x = TileX(r) * 16 + 8; |
0 | 871 |
|
872 |
y = 8; |
|
873 |
dir = 3; |
|
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
830
diff
changeset
|
874 |
if (r & 0x80000000) { y = MapMaxX() * 16 - 8 - 1; dir = 7; } |
0 | 875 |
InitializeDisasterVehicle(v, x, y, 0, dir,13); |
876 |
v->age = 0; |
|
877 |
} |
|
878 |
||
879 |
// 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
|
880 |
static void Disaster6_Init(void) |
0 | 881 |
{ |
882 |
Vehicle *v = ForceAllocateSpecialVehicle(); |
|
883 |
int x,y; |
|
884 |
byte dir; |
|
885 |
uint32 r; |
|
886 |
||
2639 | 887 |
if (v == NULL) return; |
0 | 888 |
|
889 |
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
|
890 |
x = TileX(r) * 16 + 8; |
0 | 891 |
|
892 |
y = 8; |
|
893 |
dir = 3; |
|
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
830
diff
changeset
|
894 |
if (r & 0x80000000) { y = MapMaxX() * 16 - 8 - 1; dir = 7; } |
0 | 895 |
InitializeDisasterVehicle(v, x, y, 0, dir,14); |
896 |
v->age = 0; |
|
897 |
} |
|
898 |
||
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
|
899 |
static void Disaster7_Init(void) |
0 | 900 |
{ |
2642 | 901 |
int index = GB(Random(), 0, 4); |
0 | 902 |
Industry *i; |
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
903 |
uint m; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
904 |
|
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
905 |
for (m = 0; m < 15; m++) { |
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
906 |
FOR_ALL_INDUSTRIES(i) { |
2026 | 907 |
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
|
908 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
909 |
SetDParam(0, i->town->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
910 |
AddNewsItem(STR_B005_COAL_MINE_SUBSIDENCE_LEAVES, |
1981 | 911 |
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
|
912 |
|
0 | 913 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
914 |
TileIndex tile = i->xy; |
2635 | 915 |
TileIndexDiff step = TileOffsByDir(GB(Random(), 0, 2)); |
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
916 |
uint n; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
917 |
|
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
918 |
for (n = 0; n < 30; i++) { |
0 | 919 |
DisasterClearSquare(tile); |
920 |
tile = TILE_MASK(tile + step); |
|
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
921 |
} |
0 | 922 |
} |
923 |
return; |
|
924 |
} |
|
925 |
} |
|
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
926 |
} |
0 | 927 |
} |
928 |
||
929 |
static DisasterInitProc * const _disaster_initprocs[] = { |
|
930 |
Disaster0_Init, |
|
931 |
Disaster1_Init, |
|
932 |
Disaster2_Init, |
|
933 |
Disaster3_Init, |
|
934 |
Disaster4_Init, |
|
935 |
Disaster5_Init, |
|
936 |
Disaster6_Init, |
|
937 |
Disaster7_Init, |
|
938 |
}; |
|
939 |
||
2655
807e49a44ace
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
940 |
#define MK(a, b) { (a) - MAX_YEAR_BEGIN_REAL, (b) - MAX_YEAR_BEGIN_REAL } |
807e49a44ace
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
941 |
static const struct { |
807e49a44ace
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
942 |
byte min; |
807e49a44ace
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
943 |
byte max; |
807e49a44ace
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
944 |
} _dis_years[] = { |
807e49a44ace
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
945 |
MK(1930, 1955), |
807e49a44ace
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
946 |
MK(1940, 1970), |
807e49a44ace
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
947 |
MK(1960, 1990), |
807e49a44ace
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
948 |
MK(1970, 2000), |
807e49a44ace
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
949 |
MK(2000, 2100), |
807e49a44ace
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
950 |
MK(1940, 1965), |
807e49a44ace
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
951 |
MK(1975, 2010), |
807e49a44ace
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
952 |
MK(1950, 1985) |
0 | 953 |
}; |
2655
807e49a44ace
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
954 |
#undef MK |
0 | 955 |
|
956 |
||
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
|
957 |
static void DoDisaster(void) |
0 | 958 |
{ |
2639 | 959 |
byte buf[lengthof(_dis_years)]; |
0 | 960 |
byte year = _cur_year; |
2639 | 961 |
uint i; |
962 |
uint j; |
|
0 | 963 |
|
2639 | 964 |
j = 0; |
965 |
for (i = 0; i != lengthof(_dis_years); i++) { |
|
966 |
if (year >= _dis_years[i].min && year < _dis_years[i].max) buf[j++] = i; |
|
0 | 967 |
} |
968 |
||
2639 | 969 |
if (j == 0) return; |
0 | 970 |
|
2637
8807e6a63f89
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2635
diff
changeset
|
971 |
_disaster_initprocs[buf[RandomRange(j)]](); |
0 | 972 |
} |
973 |
||
974 |
||
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
|
975 |
static void ResetDisasterDelay(void) |
0 | 976 |
{ |
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
|
977 |
_disaster_delay = GB(Random(), 0, 9) + 730; |
0 | 978 |
} |
979 |
||
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
|
980 |
void DisasterDailyLoop(void) |
0 | 981 |
{ |
2639 | 982 |
if (--_disaster_delay != 0) return; |
0 | 983 |
|
984 |
ResetDisasterDelay(); |
|
985 |
||
2639 | 986 |
if (_opt.diff.disasters != 0) DoDisaster(); |
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 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
|
990 |
{ |
0 | 991 |
ResetDisasterDelay(); |
992 |
} |