author | Darkvater |
Fri, 17 Mar 2006 23:47:03 +0000 | |
changeset 3250 | bf64b3e5f8db |
parent 3161 | 0274072d39b4 |
child 3269 | 95e7bffcb3c5 |
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 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
77 |
static void InitializeDisasterVehicle(Vehicle* v, int x, int y, byte z, Direction direction, byte subtype) |
0 | 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))) { |
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
|
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 |
||
2535 | 263 |
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
|
264 |
|
555
eec6c0294435
(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
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
|
267 |
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
|
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
eec6c0294435
(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
b0d6c7642f99
(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
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
|
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
4392ae3d8e31
(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
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
|
339 |
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
|
340 |
_m[tile].m1 = 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
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
352 |
v->u.disaster.image_override = |
2639 | 353 |
(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
|
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
eec6c0294435
(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
b0d6c7642f99
(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
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
|
366 |
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
|
367 |
int y = TileY(i->xy) * 16; |
0 | 368 |
uint32 r = Random(); |
369 |
||
370 |
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
|
371 |
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
|
372 |
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
|
373 |
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
|
374 |
EV_EXPLOSION_SMALL); |
0 | 375 |
|
376 |
if (++v->age >= 55) |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
377 |
v->current_order.station = 3; |
0 | 378 |
} |
555
eec6c0294435
(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
eec6c0294435
(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
b0d6c7642f99
(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
17ab2f22ff74
(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
eec6c0294435
(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
4392ae3d8e31
(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
8d09f9331a80
(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
9ea0c89fbb58
(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
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
|
405 |
if (!IsTileType(tile, MP_INDUSTRY)) |
0 | 406 |
return; |
407 |
||
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
|
408 |
v->dest_tile = ind = _m[tile].m2; |
0 | 409 |
|
919
b0d6c7642f99
(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
eec6c0294435
(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
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
423 |
v->u.disaster.image_override = |
2639 | 424 |
(v->current_order.station == 1 && v->tick_counter & 4) ? SPR_AH_64A_FIRING : 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
eec6c0294435
(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
b0d6c7642f99
(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
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
|
437 |
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
|
438 |
int y = TileY(i->xy) * 16; |
0 | 439 |
uint32 r = Random(); |
440 |
||
441 |
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
|
442 |
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
|
443 |
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
|
444 |
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
|
445 |
EV_EXPLOSION_SMALL); |
0 | 446 |
|
447 |
if (++v->age >= 55) |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
448 |
v->current_order.station = 3; |
0 | 449 |
} |
555
eec6c0294435
(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
eec6c0294435
(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
b0d6c7642f99
(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
17ab2f22ff74
(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
eec6c0294435
(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
4392ae3d8e31
(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
8d09f9331a80
(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
9ea0c89fbb58
(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
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
|
476 |
if (!IsTileType(tile, MP_INDUSTRY)) |
0 | 477 |
return; |
478 |
||
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
|
479 |
v->dest_tile = ind = _m[tile].m2; |
0 | 480 |
|
919
b0d6c7642f99
(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
eec6c0294435
(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 |
||
2535 | 494 |
if (++v->cur_image > SPR_ROTOR_MOVING_3) v->cur_image = SPR_ROTOR_MOVING_1; |
0 | 495 |
|
496 |
VehiclePositionChanged(v); |
|
497 |
BeginVehicleMove(v); |
|
498 |
EndVehicleMove(v); |
|
499 |
} |
|
500 |
||
501 |
// Big UFO which lands on a piece of rail. |
|
502 |
// Will be shot down by a plane |
|
503 |
static void DisasterTick_4(Vehicle *v) |
|
504 |
{ |
|
505 |
GetNewVehiclePosResult gp; |
|
506 |
byte z; |
|
507 |
Vehicle *u,*w; |
|
508 |
Town *t; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
509 |
TileIndex tile; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
510 |
TileIndex tile_org; |
0 | 511 |
|
512 |
v->tick_counter++; |
|
513 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
514 |
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
|
515 |
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
|
516 |
int y = TileY(v->dest_tile) * 16 + 8; |
0 | 517 |
if (abs(v->x_pos - x) + abs(v->y_pos - y) >= 8) { |
518 |
v->direction = GetDirectionTowards(v, x, y); |
|
519 |
||
520 |
GetNewVehiclePos(v, &gp); |
|
521 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
522 |
return; |
|
523 |
} |
|
524 |
||
525 |
z = GetSlopeZ(v->x_pos, v->y_pos); |
|
526 |
if (z < v->z_pos) { |
|
527 |
SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos - 1); |
|
528 |
return; |
|
529 |
} |
|
530 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
531 |
v->current_order.station = 2; |
0 | 532 |
|
533 |
FOR_ALL_VEHICLES(u) { |
|
534 |
if (u->type == VEH_Train || u->type == VEH_Road) { |
|
535 |
if (abs(u->x_pos - v->x_pos) + abs(u->y_pos - v->y_pos) <= 12*16) { |
|
536 |
u->breakdown_ctr = 5; |
|
537 |
u->breakdown_delay = 0xF0; |
|
538 |
} |
|
539 |
} |
|
540 |
} |
|
541 |
||
542 |
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
|
543 |
SetDParam(0, t->index); |
0 | 544 |
AddNewsItem(STR_B004_UFO_LANDS_NEAR, |
545 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ACCIDENT, 0), |
|
546 |
v->tile, |
|
547 |
0); |
|
548 |
||
549 |
u = ForceAllocateSpecialVehicle(); |
|
550 |
if (u == NULL) { |
|
551 |
DeleteDisasterVeh(v); |
|
552 |
return; |
|
553 |
} |
|
554 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
555 |
InitializeDisasterVehicle(u, -6 * 16, v->y_pos, 135, DIR_SW, 11); |
0 | 556 |
u->u.disaster.unk2 = v->index; |
557 |
||
558 |
w = ForceAllocateSpecialVehicle(); |
|
559 |
if (w == NULL) |
|
560 |
return; |
|
561 |
||
562 |
u->next = w; |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
563 |
InitializeDisasterVehicle(w, -6 * 16, v->y_pos, 0, DIR_SW, 12); |
0 | 564 |
w->vehstatus |= VS_DISASTER; |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
565 |
} 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
|
566 |
|
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
|
567 |
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
|
568 |
int y = TileY(v->dest_tile) * 16; |
2026 | 569 |
if (abs(x - v->x_pos) + abs(y - v->y_pos) >= 16) { |
0 | 570 |
v->direction = GetDirectionTowards(v, x, y); |
571 |
GetNewVehiclePos(v, &gp); |
|
572 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
573 |
return; |
|
574 |
} |
|
575 |
||
576 |
if (++v->age < 6) { |
|
2051 | 577 |
v->dest_tile = RandomTile(); |
0 | 578 |
return; |
579 |
} |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
580 |
v->current_order.station = 1; |
0 | 581 |
|
2051 | 582 |
tile_org = tile = RandomTile(); |
0 | 583 |
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
|
584 |
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
|
585 |
(_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
|
586 |
break; |
0 | 587 |
tile = TILE_MASK(tile+1); |
588 |
} while (tile != tile_org); |
|
589 |
v->dest_tile = tile; |
|
590 |
v->age = 0; |
|
591 |
} else |
|
592 |
return; |
|
593 |
} |
|
594 |
||
595 |
// The plane which will shoot down the UFO |
|
596 |
static void DisasterTick_4b(Vehicle *v) |
|
597 |
{ |
|
598 |
GetNewVehiclePosResult gp; |
|
599 |
Vehicle *u; |
|
600 |
int i; |
|
601 |
||
602 |
v->tick_counter++; |
|
603 |
||
604 |
GetNewVehiclePos(v, &gp); |
|
605 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
606 |
||
865 | 607 |
if (gp.x > (int)MapSizeX() * 16 + 9*16 - 1) { |
0 | 608 |
DeleteDisasterVeh(v); |
609 |
return; |
|
610 |
} |
|
611 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
612 |
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
|
613 |
u = GetVehicle(v->u.disaster.unk2); |
0 | 614 |
if (abs(v->x_pos - u->x_pos) > 16) |
615 |
return; |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
616 |
v->current_order.station = 1; |
0 | 617 |
|
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
|
618 |
CreateEffectVehicleRel(u, 0, 7, 8, EV_EXPLOSION_LARGE); |
541 | 619 |
SndPlayVehicleFx(SND_12_EXPLOSION, u); |
0 | 620 |
|
621 |
DeleteDisasterVeh(u); |
|
622 |
||
2952 | 623 |
for (i = 0; i != 80; i++) { |
0 | 624 |
uint32 r = Random(); |
625 |
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
|
626 |
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
|
627 |
GB(r, 5, 6) + v->y_pos - 32, |
0 | 628 |
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
|
629 |
EV_EXPLOSION_SMALL); |
0 | 630 |
} |
631 |
||
1981 | 632 |
BEGIN_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3)) |
0 | 633 |
tile = TILE_MASK(tile); |
634 |
DisasterClearSquare(tile); |
|
1981 | 635 |
END_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3)) |
0 | 636 |
} |
637 |
} |
|
638 |
||
639 |
// Submarine handler |
|
640 |
static void DisasterTick_5_and_6(Vehicle *v) |
|
641 |
{ |
|
642 |
uint32 r; |
|
643 |
GetNewVehiclePosResult gp; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
644 |
TileIndex tile; |
0 | 645 |
|
646 |
v->tick_counter++; |
|
647 |
||
648 |
if (++v->age > 8880) { |
|
649 |
VehiclePositionChanged(v); |
|
650 |
BeginVehicleMove(v); |
|
651 |
EndVehicleMove(v); |
|
652 |
DeleteVehicle(v); |
|
653 |
return; |
|
654 |
} |
|
655 |
||
656 |
if (!(v->tick_counter&1)) |
|
657 |
return; |
|
658 |
||
3161 | 659 |
tile = v->tile + TileOffsByDir(DirToDiagDir(v->direction)); |
0 | 660 |
if (IsValidTile(tile) && |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
0
diff
changeset
|
661 |
(r=GetTileTrackStatus(tile,TRANSPORT_WATER),(byte)(r+(r >> 8)) == 0x3F) && |
0 | 662 |
!CHANCE16(1,90)) { |
663 |
GetNewVehiclePos(v, &gp); |
|
664 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
665 |
return; |
|
666 |
} |
|
667 |
||
3160 | 668 |
v->direction = ChangeDir(v->direction, GB(Random(), 0, 1) ? DIRDIFF_90RIGHT : DIRDIFF_90LEFT); |
0 | 669 |
} |
670 |
||
671 |
||
672 |
static void DisasterTick_NULL(Vehicle *v) {} |
|
673 |
typedef void DisasterVehicleTickProc(Vehicle *v); |
|
674 |
||
675 |
static DisasterVehicleTickProc * const _disastervehicle_tick_procs[] = { |
|
676 |
DisasterTick_Zeppeliner,DisasterTick_NULL, |
|
677 |
DisasterTick_UFO,DisasterTick_NULL, |
|
678 |
DisasterTick_2,DisasterTick_NULL, |
|
679 |
DisasterTick_3,DisasterTick_NULL,DisasterTick_3b, |
|
680 |
DisasterTick_4,DisasterTick_NULL, |
|
681 |
DisasterTick_4b,DisasterTick_NULL, |
|
682 |
DisasterTick_5_and_6, |
|
683 |
DisasterTick_5_and_6, |
|
684 |
}; |
|
685 |
||
686 |
||
687 |
void DisasterVehicle_Tick(Vehicle *v) |
|
688 |
{ |
|
689 |
_disastervehicle_tick_procs[v->subtype](v); |
|
690 |
} |
|
691 |
||
692 |
||
693 |
void OnNewDay_DisasterVehicle(Vehicle *v) |
|
694 |
{ |
|
695 |
// not used |
|
696 |
} |
|
697 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
698 |
typedef void DisasterInitProc(void); |
0 | 699 |
|
700 |
// Zeppeliner which crashes on a small airport |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
701 |
static void Disaster0_Init(void) |
0 | 702 |
{ |
703 |
Vehicle *v = ForceAllocateSpecialVehicle(), *u; |
|
704 |
Station *st; |
|
705 |
int x; |
|
706 |
||
707 |
if (v == NULL) |
|
708 |
return; |
|
709 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
710 |
/* Pick a random place, unless we find |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
711 |
a small airport */ |
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
712 |
x = TileX(Random()) * 16 + 8; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
713 |
|
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
714 |
FOR_ALL_STATIONS(st) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
715 |
if (st->xy && st->airport_tile != 0 && |
0 | 716 |
st->airport_type <= 1 && |
717 |
IS_HUMAN_PLAYER(st->owner)) { |
|
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
718 |
x = (TileX(st->xy) + 2) * 16; |
0 | 719 |
break; |
720 |
} |
|
721 |
} |
|
722 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
723 |
InitializeDisasterVehicle(v, x, 0, 135, DIR_SE, 0); |
0 | 724 |
|
725 |
// Allocate shadow too? |
|
726 |
u = ForceAllocateSpecialVehicle(); |
|
727 |
if (u != NULL) { |
|
728 |
v->next = u; |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
729 |
InitializeDisasterVehicle(u, x, 0, 0, DIR_SE, 1); |
0 | 730 |
u->vehstatus |= VS_DISASTER; |
731 |
} |
|
732 |
} |
|
733 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
734 |
static void Disaster1_Init(void) |
0 | 735 |
{ |
736 |
Vehicle *v = ForceAllocateSpecialVehicle(), *u; |
|
737 |
int x; |
|
738 |
||
739 |
if (v == NULL) |
|
740 |
return; |
|
741 |
||
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
742 |
x = TileX(Random()) * 16 + 8; |
0 | 743 |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
744 |
InitializeDisasterVehicle(v, x, 0, 135, DIR_SE, 2); |
1981 | 745 |
v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2); |
0 | 746 |
v->age = 0; |
747 |
||
748 |
// Allocate shadow too? |
|
749 |
u = ForceAllocateSpecialVehicle(); |
|
750 |
if (u != NULL) { |
|
751 |
v->next = u; |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
752 |
InitializeDisasterVehicle(u, x, 0, 0, DIR_SE, 3); |
0 | 753 |
u->vehstatus |= VS_DISASTER; |
754 |
} |
|
755 |
} |
|
756 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
757 |
static void Disaster2_Init(void) |
0 | 758 |
{ |
759 |
Industry *i, *found; |
|
760 |
Vehicle *v,*u; |
|
761 |
int x,y; |
|
762 |
||
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
763 |
found = NULL; |
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
764 |
|
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
765 |
FOR_ALL_INDUSTRIES(i) { |
0 | 766 |
if (i->xy != 0 && |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
767 |
i->type == IT_OIL_REFINERY && |
0 | 768 |
(found==NULL || CHANCE16(1,2))) { |
769 |
found = i; |
|
770 |
} |
|
771 |
} |
|
772 |
||
773 |
if (found == NULL) |
|
774 |
return; |
|
775 |
||
776 |
v = ForceAllocateSpecialVehicle(); |
|
777 |
if (v == NULL) |
|
778 |
return; |
|
779 |
||
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
830
diff
changeset
|
780 |
x = (MapSizeX() + 9) * 16 - 1; |
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
781 |
y = TileY(found->xy) * 16 + 37; |
0 | 782 |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
783 |
InitializeDisasterVehicle(v, x, y, 135, DIR_NE, 4); |
0 | 784 |
|
785 |
u = ForceAllocateSpecialVehicle(); |
|
786 |
if (u != NULL) { |
|
787 |
v->next = u; |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
788 |
InitializeDisasterVehicle(u, x, y, 0, DIR_SE, 5); |
0 | 789 |
u->vehstatus |= VS_DISASTER; |
790 |
} |
|
791 |
} |
|
792 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
793 |
static void Disaster3_Init(void) |
0 | 794 |
{ |
795 |
Industry *i, *found; |
|
796 |
Vehicle *v,*u,*w; |
|
797 |
int x,y; |
|
798 |
||
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
799 |
found = NULL; |
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
800 |
|
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
801 |
FOR_ALL_INDUSTRIES(i) { |
0 | 802 |
if (i->xy != 0 && |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
803 |
i->type == IT_FACTORY && |
0 | 804 |
(found==NULL || CHANCE16(1,2))) { |
805 |
found = i; |
|
806 |
} |
|
807 |
} |
|
808 |
||
809 |
if (found == NULL) |
|
810 |
return; |
|
811 |
||
812 |
v = ForceAllocateSpecialVehicle(); |
|
813 |
if (v == NULL) |
|
814 |
return; |
|
815 |
||
816 |
x = -16 * 16; |
|
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
817 |
y = TileY(found->xy) * 16 + 37; |
0 | 818 |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
819 |
InitializeDisasterVehicle(v, x, y, 135, DIR_SW, 6); |
0 | 820 |
|
821 |
u = ForceAllocateSpecialVehicle(); |
|
822 |
if (u != NULL) { |
|
823 |
v->next = u; |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
824 |
InitializeDisasterVehicle(u, x, y, 0, DIR_SW, 7); |
0 | 825 |
u->vehstatus |= VS_DISASTER; |
826 |
||
827 |
w = ForceAllocateSpecialVehicle(); |
|
828 |
if (w != NULL) { |
|
829 |
u->next = w; |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
830 |
InitializeDisasterVehicle(w, x, y, 140, DIR_SW, 8); |
0 | 831 |
} |
832 |
} |
|
833 |
} |
|
834 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
835 |
static void Disaster4_Init(void) |
0 | 836 |
{ |
837 |
Vehicle *v = ForceAllocateSpecialVehicle(), *u; |
|
838 |
int x,y; |
|
839 |
||
2639 | 840 |
if (v == NULL) return; |
0 | 841 |
|
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
|
842 |
x = TileX(Random()) * 16 + 8; |
0 | 843 |
|
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
830
diff
changeset
|
844 |
y = MapMaxX() * 16 - 1; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
845 |
InitializeDisasterVehicle(v, x, y, 135, DIR_NW, 9); |
1981 | 846 |
v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2); |
0 | 847 |
v->age = 0; |
848 |
||
849 |
// Allocate shadow too? |
|
850 |
u = ForceAllocateSpecialVehicle(); |
|
851 |
if (u != NULL) { |
|
852 |
v->next = u; |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
853 |
InitializeDisasterVehicle(u, x, y, 0, DIR_NW, 10); |
0 | 854 |
u->vehstatus |= VS_DISASTER; |
855 |
} |
|
856 |
} |
|
857 |
||
858 |
// 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
|
859 |
static void Disaster5_Init(void) |
0 | 860 |
{ |
861 |
Vehicle *v = ForceAllocateSpecialVehicle(); |
|
862 |
int x,y; |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
863 |
Direction dir; |
0 | 864 |
uint32 r; |
865 |
||
2639 | 866 |
if (v == NULL) return; |
0 | 867 |
|
868 |
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
|
869 |
x = TileX(r) * 16 + 8; |
0 | 870 |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
871 |
if (r & 0x80000000) { |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
872 |
y = MapMaxX() * 16 - 8 - 1; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
873 |
dir = DIR_NW; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
874 |
} else { |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
875 |
y = 8; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
876 |
dir = DIR_SE; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
877 |
} |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
878 |
InitializeDisasterVehicle(v, x, y, 0, dir, 13); |
0 | 879 |
v->age = 0; |
880 |
} |
|
881 |
||
882 |
// 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
|
883 |
static void Disaster6_Init(void) |
0 | 884 |
{ |
885 |
Vehicle *v = ForceAllocateSpecialVehicle(); |
|
886 |
int x,y; |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
887 |
Direction dir; |
0 | 888 |
uint32 r; |
889 |
||
2639 | 890 |
if (v == NULL) return; |
0 | 891 |
|
892 |
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
|
893 |
x = TileX(r) * 16 + 8; |
0 | 894 |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
895 |
if (r & 0x80000000) { |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
896 |
y = MapMaxX() * 16 - 8 - 1; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
897 |
dir = DIR_NW; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
898 |
} else { |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
899 |
y = 8; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
900 |
dir = DIR_SE; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
901 |
} |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
902 |
InitializeDisasterVehicle(v, x, y, 0, dir, 14); |
0 | 903 |
v->age = 0; |
904 |
} |
|
905 |
||
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
|
906 |
static void Disaster7_Init(void) |
0 | 907 |
{ |
2642 | 908 |
int index = GB(Random(), 0, 4); |
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
909 |
uint m; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
910 |
|
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
911 |
for (m = 0; m < 15; m++) { |
2989 | 912 |
const Industry* i; |
913 |
||
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
914 |
FOR_ALL_INDUSTRIES(i) { |
2026 | 915 |
if (i->xy != 0 && i->type == IT_COAL_MINE && --index < 0) { |
534
17ab2f22ff74
(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
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
921 |
TileIndex tile = i->xy; |
2635 | 922 |
TileIndexDiff step = TileOffsByDir(GB(Random(), 0, 2)); |
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
923 |
uint n; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
924 |
|
2674
1d68ffc9f406
(svn r3216) - Fix (regression): endless loop introduced in revision 3190
Darkvater
parents:
2668
diff
changeset
|
925 |
for (n = 0; n < 30; n++) { |
0 | 926 |
DisasterClearSquare(tile); |
927 |
tile = TILE_MASK(tile + step); |
|
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
928 |
} |
0 | 929 |
} |
930 |
return; |
|
931 |
} |
|
932 |
} |
|
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
933 |
} |
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 |
||
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
|
947 |
#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
|
948 |
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
|
949 |
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
|
950 |
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
|
951 |
} _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
|
952 |
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
|
953 |
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
|
954 |
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
|
955 |
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
|
956 |
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
|
957 |
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
|
958 |
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
|
959 |
MK(1950, 1985) |
0 | 960 |
}; |
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
|
961 |
#undef MK |
0 | 962 |
|
963 |
||
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
|
964 |
static void DoDisaster(void) |
0 | 965 |
{ |
2639 | 966 |
byte buf[lengthof(_dis_years)]; |
0 | 967 |
byte year = _cur_year; |
2639 | 968 |
uint i; |
969 |
uint j; |
|
0 | 970 |
|
2639 | 971 |
j = 0; |
972 |
for (i = 0; i != lengthof(_dis_years); i++) { |
|
973 |
if (year >= _dis_years[i].min && year < _dis_years[i].max) buf[j++] = i; |
|
0 | 974 |
} |
975 |
||
2639 | 976 |
if (j == 0) return; |
0 | 977 |
|
2637
8807e6a63f89
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2635
diff
changeset
|
978 |
_disaster_initprocs[buf[RandomRange(j)]](); |
0 | 979 |
} |
980 |
||
981 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
982 |
static void ResetDisasterDelay(void) |
0 | 983 |
{ |
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
|
984 |
_disaster_delay = GB(Random(), 0, 9) + 730; |
0 | 985 |
} |
986 |
||
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
|
987 |
void DisasterDailyLoop(void) |
0 | 988 |
{ |
2639 | 989 |
if (--_disaster_delay != 0) return; |
0 | 990 |
|
991 |
ResetDisasterDelay(); |
|
992 |
||
2639 | 993 |
if (_opt.diff.disasters != 0) DoDisaster(); |
0 | 994 |
} |
995 |
||
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
|
996 |
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
|
997 |
{ |
0 | 998 |
ResetDisasterDelay(); |
999 |
} |