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