author | Darkvater |
Mon, 31 Jul 2006 22:40:55 +0000 | |
changeset 4204 | 3aa39be759f2 |
parent 4175 | b79ec8a94d4e |
child 4249 | cc919af15ec3 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1359
diff
changeset
|
4 |
#include "openttd.h" |
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3269
diff
changeset
|
5 |
#include "industry_map.h" |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3314
diff
changeset
|
6 |
#include "station_map.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
410
diff
changeset
|
7 |
#include "table/strings.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
8 |
#include "functions.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
555
diff
changeset
|
9 |
#include "map.h" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1093
diff
changeset
|
10 |
#include "tile.h" |
0 | 11 |
#include "vehicle.h" |
12 |
#include "command.h" |
|
13 |
#include "news.h" |
|
14 |
#include "station.h" |
|
2435
9b9d43988058
(svn r2961) - Fix: [ 1219123 ] Fix for [ 1216203 ] UFO-broken waypoint (lucaspiller)
Darkvater
parents:
2360
diff
changeset
|
15 |
#include "waypoint.h" |
0 | 16 |
#include "town.h" |
17 |
#include "industry.h" |
|
18 |
#include "player.h" |
|
3701
fdbb6bcab8a2
(svn r4642) - Codechange: reorganise airport.h and airport_movement.h to avoid having 8 copies of the airport FTAs, and make the enums used available elsewhere.
peter1138
parents:
3645
diff
changeset
|
19 |
#include "airport.h" |
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
20 |
#include "sound.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2140
diff
changeset
|
21 |
#include "variables.h" |
2535 | 22 |
#include "table/sprites.h" |
0 | 23 |
|
1048 | 24 |
static void DisasterClearSquare(TileIndex tile) |
0 | 25 |
{ |
2639 | 26 |
if (!EnsureNoVehicle(tile)) return; |
0 | 27 |
|
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1212
diff
changeset
|
28 |
switch (GetTileType(tile)) { |
1048 | 29 |
case MP_RAILWAY: |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3701
diff
changeset
|
30 |
if (IS_HUMAN_PLAYER(GetTileOwner(tile)) && !IsRailWaypoint(tile)) { |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3701
diff
changeset
|
31 |
PlayerID p = _current_player; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3701
diff
changeset
|
32 |
_current_player = OWNER_WATER; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3701
diff
changeset
|
33 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3701
diff
changeset
|
34 |
_current_player = p; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3701
diff
changeset
|
35 |
} |
1048 | 36 |
break; |
0 | 37 |
|
1048 | 38 |
case MP_HOUSE: { |
2435
9b9d43988058
(svn r2961) - Fix: [ 1219123 ] Fix for [ 1216203 ] UFO-broken waypoint (lucaspiller)
Darkvater
parents:
2360
diff
changeset
|
39 |
PlayerID p = _current_player; |
1048 | 40 |
_current_player = OWNER_NONE; |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
41 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
1048 | 42 |
_current_player = p; |
43 |
break; |
|
44 |
} |
|
45 |
||
46 |
case MP_TREES: |
|
47 |
case MP_CLEAR: |
|
0 | 48 |
DoClearSquare(tile); |
1048 | 49 |
break; |
50 |
||
51 |
default: |
|
52 |
break; |
|
0 | 53 |
} |
54 |
} |
|
55 |
||
56 |
static const SpriteID _disaster_images_1[] = {0xF41,0xF41,0xF41,0xF41,0xF41,0xF41,0xF41,0xF41}; |
|
57 |
static const SpriteID _disaster_images_2[] = {0xF44,0xF44,0xF44,0xF44,0xF44,0xF44,0xF44,0xF44}; |
|
58 |
static const SpriteID _disaster_images_3[] = {0xF4E,0xF4E,0xF4E,0xF4E,0xF4E,0xF4E,0xF4E,0xF4E}; |
|
59 |
static const SpriteID _disaster_images_4[] = {0xF46,0xF46,0xF47,0xF47,0xF48,0xF48,0xF49,0xF49}; |
|
60 |
static const SpriteID _disaster_images_5[] = {0xF4A,0xF4A,0xF4B,0xF4B,0xF4C,0xF4C,0xF4D,0xF4D}; |
|
61 |
static const SpriteID _disaster_images_6[] = {0xF50,0xF50,0xF50,0xF50,0xF50,0xF50,0xF50,0xF50}; |
|
62 |
static const SpriteID _disaster_images_7[] = {0xF51,0xF51,0xF51,0xF51,0xF51,0xF51,0xF51,0xF51}; |
|
63 |
static const SpriteID _disaster_images_8[] = {0xF52,0xF52,0xF52,0xF52,0xF52,0xF52,0xF52,0xF52}; |
|
64 |
static const SpriteID _disaster_images_9[] = {0xF3E,0xF3E,0xF3E,0xF3E,0xF3E,0xF3E,0xF3E,0xF3E}; |
|
65 |
||
66 |
static const SpriteID * const _disaster_images[] = { |
|
67 |
_disaster_images_1,_disaster_images_1, |
|
68 |
_disaster_images_2,_disaster_images_2, |
|
69 |
_disaster_images_3,_disaster_images_3, |
|
70 |
_disaster_images_8,_disaster_images_8,_disaster_images_9, |
|
71 |
_disaster_images_6,_disaster_images_6, |
|
72 |
_disaster_images_7,_disaster_images_7, |
|
73 |
_disaster_images_4,_disaster_images_5, |
|
74 |
}; |
|
75 |
||
76 |
static void DisasterVehicleUpdateImage(Vehicle *v) |
|
77 |
{ |
|
78 |
int img = v->u.disaster.image_override; |
|
79 |
if (img == 0) |
|
80 |
img = _disaster_images[v->subtype][v->direction]; |
|
81 |
v->cur_image = img; |
|
82 |
} |
|
83 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
84 |
static void InitializeDisasterVehicle(Vehicle* v, int x, int y, byte z, Direction direction, byte subtype) |
0 | 85 |
{ |
86 |
v->type = VEH_Disaster; |
|
87 |
v->x_pos = x; |
|
88 |
v->y_pos = y; |
|
89 |
v->z_pos = z; |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
90 |
v->tile = TileVirtXY(x, y); |
0 | 91 |
v->direction = direction; |
92 |
v->subtype = subtype; |
|
93 |
v->x_offs = -1; |
|
94 |
v->y_offs = -1; |
|
95 |
v->sprite_width = 2; |
|
96 |
v->sprite_height = 2; |
|
97 |
v->z_height = 5; |
|
98 |
v->owner = OWNER_NONE; |
|
99 |
v->vehstatus = VS_UNCLICKABLE; |
|
100 |
v->u.disaster.image_override = 0; |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
101 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
102 |
v->current_order.flags = 0; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
103 |
v->current_order.station = 0; |
0 | 104 |
|
105 |
DisasterVehicleUpdateImage(v); |
|
106 |
VehiclePositionChanged(v); |
|
107 |
BeginVehicleMove(v); |
|
108 |
EndVehicleMove(v); |
|
109 |
} |
|
110 |
||
111 |
static void DeleteDisasterVeh(Vehicle *v) |
|
112 |
{ |
|
113 |
DeleteVehicleChain(v); |
|
114 |
} |
|
115 |
||
116 |
static void SetDisasterVehiclePos(Vehicle *v, int x, int y, byte z) |
|
117 |
{ |
|
118 |
Vehicle *u; |
|
119 |
int yt; |
|
120 |
||
121 |
BeginVehicleMove(v); |
|
122 |
v->x_pos = x; |
|
123 |
v->y_pos = y; |
|
124 |
v->z_pos = z; |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
125 |
v->tile = TileVirtXY(x, y); |
0 | 126 |
|
127 |
DisasterVehicleUpdateImage(v); |
|
128 |
VehiclePositionChanged(v); |
|
129 |
EndVehicleMove(v); |
|
130 |
||
131 |
if ( (u=v->next) != NULL) { |
|
132 |
BeginVehicleMove(u); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
133 |
|
0 | 134 |
u->x_pos = x; |
135 |
u->y_pos = yt = y - 1 - (max(z - GetSlopeZ(x, y-1), 0) >> 3); |
|
136 |
u->z_pos = GetSlopeZ(x,yt); |
|
137 |
u->direction = v->direction; |
|
138 |
||
139 |
DisasterVehicleUpdateImage(u); |
|
140 |
VehiclePositionChanged(u); |
|
141 |
EndVehicleMove(u); |
|
142 |
||
143 |
if ( (u=u->next) != NULL) { |
|
144 |
BeginVehicleMove(u); |
|
145 |
u->x_pos = x; |
|
146 |
u->y_pos = y; |
|
147 |
u->z_pos = z + 5; |
|
148 |
VehiclePositionChanged(u); |
|
149 |
EndVehicleMove(u); |
|
150 |
} |
|
151 |
} |
|
152 |
} |
|
153 |
||
154 |
||
155 |
static void DisasterTick_Zeppeliner(Vehicle *v) |
|
156 |
{ |
|
157 |
GetNewVehiclePosResult gp; |
|
158 |
Station *st; |
|
159 |
int x,y; |
|
160 |
byte z; |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
161 |
TileIndex tile; |
0 | 162 |
|
163 |
++v->tick_counter; |
|
164 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
165 |
if (v->current_order.station < 2) { |
0 | 166 |
if (v->tick_counter&1) |
167 |
return; |
|
168 |
||
169 |
GetNewVehiclePos(v, &gp); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
170 |
|
0 | 171 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
172 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
173 |
if (v->current_order.station == 1) { |
0 | 174 |
if (++v->age == 38) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
175 |
v->current_order.station = 2; |
0 | 176 |
v->age = 0; |
177 |
} |
|
178 |
||
179 |
if ((v->tick_counter&7)==0) { |
|
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1214
diff
changeset
|
180 |
CreateEffectVehicleRel(v, 0, -17, 2, EV_SMOKE); |
0 | 181 |
} |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
182 |
} else if (v->current_order.station == 0) { |
0 | 183 |
tile = v->tile; /**/ |
184 |
||
1212
781cda2ed164
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
185 |
if (IsValidTile(tile) && |
781cda2ed164
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
186 |
IsTileType(tile, MP_STATION) && |
3338
7cff208f0446
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
187 |
IsAirport(tile) && |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
188 |
IS_HUMAN_PLAYER(GetTileOwner(tile))) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
189 |
v->current_order.station = 1; |
0 | 190 |
v->age = 0; |
191 |
||
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3314
diff
changeset
|
192 |
SetDParam(0, GetStationIndex(tile)); |
0 | 193 |
AddNewsItem(STR_B000_ZEPPELIN_DISASTER_AT, |
194 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), |
|
195 |
v->index, |
|
196 |
0); |
|
197 |
} |
|
198 |
} |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
199 |
if (v->y_pos >= ((int)MapSizeY() + 9) * TILE_SIZE - 1) |
0 | 200 |
DeleteDisasterVeh(v); |
201 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
202 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
203 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
204 |
if (v->current_order.station > 2) { |
0 | 205 |
if (++v->age <= 13320) |
206 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
207 |
|
0 | 208 |
tile = v->tile; /**/ |
209 |
||
1212
781cda2ed164
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
210 |
if (IsValidTile(tile) && |
781cda2ed164
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
211 |
IsTileType(tile, MP_STATION) && |
3338
7cff208f0446
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
212 |
IsAirport(tile) && |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
213 |
IS_HUMAN_PLAYER(GetTileOwner(tile))) { |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3314
diff
changeset
|
214 |
st = GetStationByTile(tile); |
0 | 215 |
CLRBITS(st->airport_flags, RUNWAY_IN_block); |
216 |
} |
|
217 |
||
218 |
SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos); |
|
219 |
DeleteDisasterVeh(v); |
|
220 |
return; |
|
221 |
} |
|
222 |
||
223 |
x = v->x_pos; |
|
224 |
y = v->y_pos; |
|
225 |
z = GetSlopeZ(x,y); |
|
226 |
if (z < v->z_pos) |
|
227 |
z = v->z_pos - 1; |
|
228 |
SetDisasterVehiclePos(v, x, y, z); |
|
229 |
||
230 |
if (++v->age == 1) { |
|
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1214
diff
changeset
|
231 |
CreateEffectVehicleRel(v, 0, 7, 8, EV_EXPLOSION_LARGE); |
541 | 232 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
2535 | 233 |
v->u.disaster.image_override = SPR_BLIMP_CRASHING; |
0 | 234 |
} else if (v->age == 70) { |
2535 | 235 |
v->u.disaster.image_override = SPR_BLIMP_CRASHED; |
0 | 236 |
} else if (v->age <= 300) { |
237 |
if (!(v->tick_counter&7)) { |
|
238 |
uint32 r = Random(); |
|
239 |
||
240 |
CreateEffectVehicleRel(v, |
|
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2051
diff
changeset
|
241 |
GB(r, 0, 4) - 7, |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2051
diff
changeset
|
242 |
GB(r, 4, 4) - 7, |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2051
diff
changeset
|
243 |
GB(r, 8, 3) + 5, |
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1214
diff
changeset
|
244 |
EV_EXPLOSION_SMALL); |
0 | 245 |
} |
246 |
} else if (v->age == 350) { |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
247 |
v->current_order.station = 3; |
0 | 248 |
v->age = 0; |
249 |
} |
|
250 |
||
251 |
tile = v->tile;/**/ |
|
1212
781cda2ed164
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
252 |
if (IsValidTile(tile) && |
781cda2ed164
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
253 |
IsTileType(tile, MP_STATION) && |
3338
7cff208f0446
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
254 |
IsAirport(tile) && |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
255 |
IS_HUMAN_PLAYER(GetTileOwner(tile))) { |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3314
diff
changeset
|
256 |
st = GetStationByTile(tile); |
0 | 257 |
SETBITS(st->airport_flags, RUNWAY_IN_block); |
258 |
} |
|
259 |
} |
|
260 |
||
261 |
// UFO starts in the middle, and flies around a bit until it locates |
|
262 |
// a road vehicle which it targets. |
|
263 |
static void DisasterTick_UFO(Vehicle *v) |
|
264 |
{ |
|
265 |
GetNewVehiclePosResult gp; |
|
266 |
Vehicle *u; |
|
267 |
uint dist; |
|
268 |
byte z; |
|
269 |
||
2535 | 270 |
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
|
271 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
272 |
if (v->current_order.station == 0) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
273 |
// fly around randomly |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
274 |
int x = TileX(v->dest_tile) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
275 |
int y = TileY(v->dest_tile) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
276 |
if (abs(x - v->x_pos) + abs(y - v->y_pos) >= TILE_SIZE) { |
0 | 277 |
v->direction = GetDirectionTowards(v, x, y); |
278 |
GetNewVehiclePos(v, &gp); |
|
279 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
280 |
return; |
|
281 |
} |
|
282 |
if (++v->age < 6) { |
|
2051 | 283 |
v->dest_tile = RandomTile(); |
0 | 284 |
return; |
285 |
} |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
286 |
v->current_order.station = 1; |
0 | 287 |
|
288 |
FOR_ALL_VEHICLES(u) { |
|
289 |
if (u->type == VEH_Road && IS_HUMAN_PLAYER(u->owner)) { |
|
290 |
v->dest_tile = u->index; |
|
291 |
v->age = 0; |
|
292 |
return; |
|
293 |
} |
|
294 |
} |
|
295 |
||
296 |
DeleteDisasterVeh(v); |
|
297 |
} else { |
|
298 |
// target a vehicle |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
299 |
u = GetVehicle(v->dest_tile); |
0 | 300 |
if (u->type != VEH_Road) { |
301 |
DeleteDisasterVeh(v); |
|
302 |
return; |
|
303 |
} |
|
304 |
||
305 |
dist = abs(v->x_pos - u->x_pos) + abs(v->y_pos - u->y_pos); |
|
306 |
||
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
307 |
if (dist < TILE_SIZE && !(u->vehstatus&VS_HIDDEN) && u->breakdown_ctr==0) { |
0 | 308 |
u->breakdown_ctr = 3; |
309 |
u->breakdown_delay = 140; |
|
310 |
} |
|
311 |
||
312 |
v->direction = GetDirectionTowards(v, u->x_pos, u->y_pos); |
|
313 |
GetNewVehiclePos(v, &gp); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
314 |
|
0 | 315 |
z = v->z_pos; |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
316 |
if (dist <= TILE_SIZE && z > u->z_pos) z--; |
0 | 317 |
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
|
318 |
|
0 | 319 |
if (z <= u->z_pos && (u->vehstatus&VS_HIDDEN)==0) { |
320 |
v->age++; |
|
321 |
if (u->u.road.crashed_ctr == 0) { |
|
322 |
u->u.road.crashed_ctr++; |
|
323 |
u->vehstatus |= VS_CRASHED; |
|
324 |
||
325 |
AddNewsItem(STR_B001_ROAD_VEHICLE_DESTROYED, |
|
326 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), |
|
327 |
u->index, |
|
328 |
0); |
|
329 |
} |
|
330 |
} |
|
331 |
||
332 |
// destroy? |
|
333 |
if (v->age > 50) { |
|
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1214
diff
changeset
|
334 |
CreateEffectVehicleRel(v, 0, 7, 8, EV_EXPLOSION_LARGE); |
541 | 335 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
0 | 336 |
DeleteDisasterVeh(v); |
337 |
} |
|
338 |
} |
|
339 |
} |
|
340 |
||
341 |
static void DestructIndustry(Industry *i) |
|
342 |
{ |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
343 |
TileIndex tile; |
0 | 344 |
|
2026 | 345 |
for (tile = 0; tile != MapSize(); tile++) { |
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3269
diff
changeset
|
346 |
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == i->index) { |
3495
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3491
diff
changeset
|
347 |
ResetIndustryConstructionStage(tile); |
0 | 348 |
MarkTileDirtyByTile(tile); |
349 |
} |
|
350 |
} |
|
351 |
} |
|
352 |
||
353 |
// Airplane which destroys an oil refinery |
|
354 |
static void DisasterTick_2(Vehicle *v) |
|
355 |
{ |
|
356 |
GetNewVehiclePosResult gp; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
357 |
|
0 | 358 |
v->tick_counter++; |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
359 |
v->u.disaster.image_override = |
2639 | 360 |
(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
|
361 |
|
0 | 362 |
GetNewVehiclePos(v, &gp); |
363 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
364 |
||
365 |
if (gp.x < -160) { |
|
366 |
DeleteDisasterVeh(v); |
|
367 |
return; |
|
368 |
} |
|
369 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
370 |
if (v->current_order.station == 2) { |
0 | 371 |
if (!(v->tick_counter&3)) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
372 |
Industry *i = GetIndustry(v->dest_tile); |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
373 |
int x = TileX(i->xy) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
374 |
int y = TileY(i->xy) * TILE_SIZE; |
0 | 375 |
uint32 r = Random(); |
376 |
||
377 |
CreateEffectVehicleAbove( |
|
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2051
diff
changeset
|
378 |
GB(r, 0, 6) + x, |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2051
diff
changeset
|
379 |
GB(r, 6, 6) + y, |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2051
diff
changeset
|
380 |
GB(r, 12, 4), |
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1214
diff
changeset
|
381 |
EV_EXPLOSION_SMALL); |
0 | 382 |
|
383 |
if (++v->age >= 55) |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
384 |
v->current_order.station = 3; |
0 | 385 |
} |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
386 |
} else if (v->current_order.station == 1) { |
0 | 387 |
if (++v->age == 112) { |
388 |
Industry *i; |
|
389 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
390 |
v->current_order.station = 2; |
0 | 391 |
v->age = 0; |
392 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
393 |
i = GetIndustry(v->dest_tile); |
0 | 394 |
DestructIndustry(i); |
395 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
396 |
SetDParam(0, i->town->index); |
0 | 397 |
AddNewsItem(STR_B002_OIL_REFINERY_EXPLOSION, NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy, 0); |
541 | 398 |
SndPlayTileFx(SND_12_EXPLOSION, i->xy); |
0 | 399 |
} |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
400 |
} else if (v->current_order.station == 0) { |
0 | 401 |
int x,y; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
402 |
TileIndex tile; |
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3269
diff
changeset
|
403 |
uint ind; |
0 | 404 |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
405 |
x = v->x_pos - 15 * TILE_SIZE; |
0 | 406 |
y = v->y_pos; |
407 |
||
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
408 |
if ( (uint)x > MapMaxX() * TILE_SIZE - 1) |
0 | 409 |
return; |
410 |
||
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
411 |
tile = TileVirtXY(x, y); |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
926
diff
changeset
|
412 |
if (!IsTileType(tile, MP_INDUSTRY)) |
0 | 413 |
return; |
414 |
||
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3269
diff
changeset
|
415 |
ind = GetIndustryIndex(tile); |
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3269
diff
changeset
|
416 |
v->dest_tile = ind; |
0 | 417 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
418 |
if (GetIndustry(ind)->type == IT_OIL_REFINERY) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
419 |
v->current_order.station = 1; |
0 | 420 |
v->age = 0; |
421 |
} |
|
422 |
} |
|
423 |
} |
|
424 |
||
425 |
// Helicopter which destroys a factory |
|
426 |
static void DisasterTick_3(Vehicle *v) |
|
427 |
{ |
|
428 |
GetNewVehiclePosResult gp; |
|
429 |
||
430 |
v->tick_counter++; |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
431 |
v->u.disaster.image_override = |
2639 | 432 |
(v->current_order.station == 1 && v->tick_counter & 4) ? SPR_AH_64A_FIRING : 0; |
0 | 433 |
|
434 |
GetNewVehiclePos(v, &gp); |
|
435 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
436 |
||
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
437 |
if (gp.x > (int)MapSizeX() * TILE_SIZE + 9 * TILE_SIZE - 1) { |
0 | 438 |
DeleteDisasterVeh(v); |
439 |
return; |
|
440 |
} |
|
441 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
442 |
if (v->current_order.station == 2) { |
0 | 443 |
if (!(v->tick_counter&3)) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
444 |
Industry *i = GetIndustry(v->dest_tile); |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
445 |
int x = TileX(i->xy) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
446 |
int y = TileY(i->xy) * TILE_SIZE; |
0 | 447 |
uint32 r = Random(); |
448 |
||
449 |
CreateEffectVehicleAbove( |
|
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2051
diff
changeset
|
450 |
GB(r, 0, 6) + x, |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2051
diff
changeset
|
451 |
GB(r, 6, 6) + y, |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2051
diff
changeset
|
452 |
GB(r, 12, 4), |
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1214
diff
changeset
|
453 |
EV_EXPLOSION_SMALL); |
0 | 454 |
|
455 |
if (++v->age >= 55) |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
456 |
v->current_order.station = 3; |
0 | 457 |
} |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
458 |
} else if (v->current_order.station == 1) { |
0 | 459 |
if (++v->age == 112) { |
460 |
Industry *i; |
|
461 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
462 |
v->current_order.station = 2; |
0 | 463 |
v->age = 0; |
464 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
465 |
i = GetIndustry(v->dest_tile); |
0 | 466 |
DestructIndustry(i); |
467 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
468 |
SetDParam(0, i->town->index); |
0 | 469 |
AddNewsItem(STR_B003_FACTORY_DESTROYED_IN_SUSPICIOUS, NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy, 0); |
541 | 470 |
SndPlayTileFx(SND_12_EXPLOSION, i->xy); |
0 | 471 |
} |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
472 |
} else if (v->current_order.station == 0) { |
0 | 473 |
int x,y; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
474 |
TileIndex tile; |
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3269
diff
changeset
|
475 |
uint ind; |
0 | 476 |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
477 |
x = v->x_pos - 15 * TILE_SIZE; |
0 | 478 |
y = v->y_pos; |
479 |
||
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
480 |
if ( (uint)x > MapMaxX() * TILE_SIZE - 1) |
0 | 481 |
return; |
482 |
||
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
483 |
tile = TileVirtXY(x, y); |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
926
diff
changeset
|
484 |
if (!IsTileType(tile, MP_INDUSTRY)) |
0 | 485 |
return; |
486 |
||
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3269
diff
changeset
|
487 |
ind = GetIndustryIndex(tile); |
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3269
diff
changeset
|
488 |
v->dest_tile = ind; |
0 | 489 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
490 |
if (GetIndustry(ind)->type == IT_FACTORY) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
491 |
v->current_order.station = 1; |
0 | 492 |
v->age = 0; |
493 |
} |
|
494 |
} |
|
495 |
} |
|
496 |
||
497 |
// Helicopter rotor blades |
|
498 |
static void DisasterTick_3b(Vehicle *v) |
|
499 |
{ |
|
500 |
if (++v->tick_counter & 1) |
|
501 |
return; |
|
502 |
||
2535 | 503 |
if (++v->cur_image > SPR_ROTOR_MOVING_3) v->cur_image = SPR_ROTOR_MOVING_1; |
0 | 504 |
|
505 |
VehiclePositionChanged(v); |
|
506 |
BeginVehicleMove(v); |
|
507 |
EndVehicleMove(v); |
|
508 |
} |
|
509 |
||
510 |
// Big UFO which lands on a piece of rail. |
|
511 |
// Will be shot down by a plane |
|
512 |
static void DisasterTick_4(Vehicle *v) |
|
513 |
{ |
|
514 |
GetNewVehiclePosResult gp; |
|
515 |
byte z; |
|
516 |
Vehicle *u,*w; |
|
517 |
Town *t; |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
518 |
TileIndex tile; |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
519 |
TileIndex tile_org; |
0 | 520 |
|
521 |
v->tick_counter++; |
|
522 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
523 |
if (v->current_order.station == 1) { |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
524 |
int x = TileX(v->dest_tile) * TILE_SIZE + TILE_SIZE / 2; |
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
525 |
int y = TileY(v->dest_tile) * TILE_SIZE + TILE_SIZE / 2; |
0 | 526 |
if (abs(v->x_pos - x) + abs(v->y_pos - y) >= 8) { |
527 |
v->direction = GetDirectionTowards(v, x, y); |
|
528 |
||
529 |
GetNewVehiclePos(v, &gp); |
|
530 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
531 |
return; |
|
532 |
} |
|
533 |
||
534 |
z = GetSlopeZ(v->x_pos, v->y_pos); |
|
535 |
if (z < v->z_pos) { |
|
536 |
SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos - 1); |
|
537 |
return; |
|
538 |
} |
|
539 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
540 |
v->current_order.station = 2; |
0 | 541 |
|
542 |
FOR_ALL_VEHICLES(u) { |
|
543 |
if (u->type == VEH_Train || u->type == VEH_Road) { |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
544 |
if (abs(u->x_pos - v->x_pos) + abs(u->y_pos - v->y_pos) <= 12 * TILE_SIZE) { |
0 | 545 |
u->breakdown_ctr = 5; |
546 |
u->breakdown_delay = 0xF0; |
|
547 |
} |
|
548 |
} |
|
549 |
} |
|
550 |
||
551 |
t = ClosestTownFromTile(v->dest_tile, (uint)-1); |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
552 |
SetDParam(0, t->index); |
0 | 553 |
AddNewsItem(STR_B004_UFO_LANDS_NEAR, |
554 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ACCIDENT, 0), |
|
555 |
v->tile, |
|
556 |
0); |
|
557 |
||
558 |
u = ForceAllocateSpecialVehicle(); |
|
559 |
if (u == NULL) { |
|
560 |
DeleteDisasterVeh(v); |
|
561 |
return; |
|
562 |
} |
|
563 |
||
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
564 |
InitializeDisasterVehicle(u, -6 * TILE_SIZE, v->y_pos, 135, DIR_SW, 11); |
0 | 565 |
u->u.disaster.unk2 = v->index; |
566 |
||
567 |
w = ForceAllocateSpecialVehicle(); |
|
568 |
if (w == NULL) |
|
569 |
return; |
|
570 |
||
571 |
u->next = w; |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
572 |
InitializeDisasterVehicle(w, -6 * TILE_SIZE, v->y_pos, 0, DIR_SW, 12); |
4175
b79ec8a94d4e
(svn r5613) Rename VS_DISASTER to VS_SHADOW, because this is what this flag actually means
tron
parents:
4077
diff
changeset
|
573 |
w->vehstatus |= VS_SHADOW; |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
574 |
} 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
|
575 |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
576 |
int x = TileX(v->dest_tile) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
577 |
int y = TileY(v->dest_tile) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
578 |
if (abs(x - v->x_pos) + abs(y - v->y_pos) >= TILE_SIZE) { |
0 | 579 |
v->direction = GetDirectionTowards(v, x, y); |
580 |
GetNewVehiclePos(v, &gp); |
|
581 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
582 |
return; |
|
583 |
} |
|
584 |
||
585 |
if (++v->age < 6) { |
|
2051 | 586 |
v->dest_tile = RandomTile(); |
0 | 587 |
return; |
588 |
} |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
589 |
v->current_order.station = 1; |
0 | 590 |
|
2051 | 591 |
tile_org = tile = RandomTile(); |
0 | 592 |
do { |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
926
diff
changeset
|
593 |
if (IsTileType(tile, MP_RAILWAY) && |
3269
62fb247bf94b
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3161
diff
changeset
|
594 |
IsPlainRailTile(tile) && |
62fb247bf94b
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3161
diff
changeset
|
595 |
IS_HUMAN_PLAYER(GetTileOwner(tile))) { |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
596 |
break; |
3269
62fb247bf94b
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3161
diff
changeset
|
597 |
} |
0 | 598 |
tile = TILE_MASK(tile+1); |
599 |
} while (tile != tile_org); |
|
600 |
v->dest_tile = tile; |
|
601 |
v->age = 0; |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
602 |
} else { |
0 | 603 |
return; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
604 |
} |
0 | 605 |
} |
606 |
||
607 |
// The plane which will shoot down the UFO |
|
608 |
static void DisasterTick_4b(Vehicle *v) |
|
609 |
{ |
|
610 |
GetNewVehiclePosResult gp; |
|
611 |
Vehicle *u; |
|
612 |
int i; |
|
613 |
||
614 |
v->tick_counter++; |
|
615 |
||
616 |
GetNewVehiclePos(v, &gp); |
|
617 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
618 |
||
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
619 |
if (gp.x > (int)MapSizeX() * TILE_SIZE + 9 * TILE_SIZE - 1) { |
0 | 620 |
DeleteDisasterVeh(v); |
621 |
return; |
|
622 |
} |
|
623 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
624 |
if (v->current_order.station == 0) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
625 |
u = GetVehicle(v->u.disaster.unk2); |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
626 |
if (abs(v->x_pos - u->x_pos) > TILE_SIZE) |
0 | 627 |
return; |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
628 |
v->current_order.station = 1; |
0 | 629 |
|
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1214
diff
changeset
|
630 |
CreateEffectVehicleRel(u, 0, 7, 8, EV_EXPLOSION_LARGE); |
541 | 631 |
SndPlayVehicleFx(SND_12_EXPLOSION, u); |
0 | 632 |
|
633 |
DeleteDisasterVeh(u); |
|
634 |
||
2952 | 635 |
for (i = 0; i != 80; i++) { |
0 | 636 |
uint32 r = Random(); |
637 |
CreateEffectVehicleAbove( |
|
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2051
diff
changeset
|
638 |
GB(r, 0, 6) + v->x_pos - 32, |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2051
diff
changeset
|
639 |
GB(r, 5, 6) + v->y_pos - 32, |
0 | 640 |
0, |
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1214
diff
changeset
|
641 |
EV_EXPLOSION_SMALL); |
0 | 642 |
} |
643 |
||
1981 | 644 |
BEGIN_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3)) |
0 | 645 |
tile = TILE_MASK(tile); |
646 |
DisasterClearSquare(tile); |
|
1981 | 647 |
END_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3)) |
0 | 648 |
} |
649 |
} |
|
650 |
||
651 |
// Submarine handler |
|
652 |
static void DisasterTick_5_and_6(Vehicle *v) |
|
653 |
{ |
|
654 |
uint32 r; |
|
655 |
GetNewVehiclePosResult gp; |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
656 |
TileIndex tile; |
0 | 657 |
|
658 |
v->tick_counter++; |
|
659 |
||
660 |
if (++v->age > 8880) { |
|
661 |
VehiclePositionChanged(v); |
|
662 |
BeginVehicleMove(v); |
|
663 |
EndVehicleMove(v); |
|
664 |
DeleteVehicle(v); |
|
665 |
return; |
|
666 |
} |
|
667 |
||
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
668 |
if (!(v->tick_counter & 1)) return; |
0 | 669 |
|
3161 | 670 |
tile = v->tile + TileOffsByDir(DirToDiagDir(v->direction)); |
0 | 671 |
if (IsValidTile(tile) && |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
0
diff
changeset
|
672 |
(r=GetTileTrackStatus(tile,TRANSPORT_WATER),(byte)(r+(r >> 8)) == 0x3F) && |
0 | 673 |
!CHANCE16(1,90)) { |
674 |
GetNewVehiclePos(v, &gp); |
|
675 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
|
676 |
return; |
|
677 |
} |
|
678 |
||
3160 | 679 |
v->direction = ChangeDir(v->direction, GB(Random(), 0, 1) ? DIRDIFF_90RIGHT : DIRDIFF_90LEFT); |
0 | 680 |
} |
681 |
||
682 |
||
683 |
static void DisasterTick_NULL(Vehicle *v) {} |
|
684 |
typedef void DisasterVehicleTickProc(Vehicle *v); |
|
685 |
||
686 |
static DisasterVehicleTickProc * const _disastervehicle_tick_procs[] = { |
|
687 |
DisasterTick_Zeppeliner,DisasterTick_NULL, |
|
688 |
DisasterTick_UFO,DisasterTick_NULL, |
|
689 |
DisasterTick_2,DisasterTick_NULL, |
|
690 |
DisasterTick_3,DisasterTick_NULL,DisasterTick_3b, |
|
691 |
DisasterTick_4,DisasterTick_NULL, |
|
692 |
DisasterTick_4b,DisasterTick_NULL, |
|
693 |
DisasterTick_5_and_6, |
|
694 |
DisasterTick_5_and_6, |
|
695 |
}; |
|
696 |
||
697 |
||
698 |
void DisasterVehicle_Tick(Vehicle *v) |
|
699 |
{ |
|
700 |
_disastervehicle_tick_procs[v->subtype](v); |
|
701 |
} |
|
702 |
||
703 |
||
704 |
void OnNewDay_DisasterVehicle(Vehicle *v) |
|
705 |
{ |
|
706 |
// not used |
|
707 |
} |
|
708 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
709 |
typedef void DisasterInitProc(void); |
0 | 710 |
|
711 |
// Zeppeliner which crashes on a small airport |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
712 |
static void Disaster0_Init(void) |
0 | 713 |
{ |
714 |
Vehicle *v = ForceAllocateSpecialVehicle(), *u; |
|
715 |
Station *st; |
|
716 |
int x; |
|
717 |
||
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
718 |
if (v == NULL) return; |
0 | 719 |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
720 |
/* Pick a random place, unless we find a small airport */ |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
721 |
x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2; |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
722 |
|
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
723 |
FOR_ALL_STATIONS(st) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
724 |
if (st->xy && st->airport_tile != 0 && |
0 | 725 |
st->airport_type <= 1 && |
726 |
IS_HUMAN_PLAYER(st->owner)) { |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
727 |
x = (TileX(st->xy) + 2) * TILE_SIZE; |
0 | 728 |
break; |
729 |
} |
|
730 |
} |
|
731 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
732 |
InitializeDisasterVehicle(v, x, 0, 135, DIR_SE, 0); |
0 | 733 |
|
734 |
// Allocate shadow too? |
|
735 |
u = ForceAllocateSpecialVehicle(); |
|
736 |
if (u != NULL) { |
|
737 |
v->next = u; |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
738 |
InitializeDisasterVehicle(u, x, 0, 0, DIR_SE, 1); |
4175
b79ec8a94d4e
(svn r5613) Rename VS_DISASTER to VS_SHADOW, because this is what this flag actually means
tron
parents:
4077
diff
changeset
|
739 |
u->vehstatus |= VS_SHADOW; |
0 | 740 |
} |
741 |
} |
|
742 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
743 |
static void Disaster1_Init(void) |
0 | 744 |
{ |
745 |
Vehicle *v = ForceAllocateSpecialVehicle(), *u; |
|
746 |
int x; |
|
747 |
||
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
748 |
if (v == NULL) return; |
0 | 749 |
|
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
750 |
x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2; |
0 | 751 |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
752 |
InitializeDisasterVehicle(v, x, 0, 135, DIR_SE, 2); |
1981 | 753 |
v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2); |
0 | 754 |
v->age = 0; |
755 |
||
756 |
// Allocate shadow too? |
|
757 |
u = ForceAllocateSpecialVehicle(); |
|
758 |
if (u != NULL) { |
|
759 |
v->next = u; |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
760 |
InitializeDisasterVehicle(u, x, 0, 0, DIR_SE, 3); |
4175
b79ec8a94d4e
(svn r5613) Rename VS_DISASTER to VS_SHADOW, because this is what this flag actually means
tron
parents:
4077
diff
changeset
|
761 |
u->vehstatus |= VS_SHADOW; |
0 | 762 |
} |
763 |
} |
|
764 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
765 |
static void Disaster2_Init(void) |
0 | 766 |
{ |
767 |
Industry *i, *found; |
|
768 |
Vehicle *v,*u; |
|
769 |
int x,y; |
|
770 |
||
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
771 |
found = NULL; |
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
772 |
|
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
773 |
FOR_ALL_INDUSTRIES(i) { |
0 | 774 |
if (i->xy != 0 && |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
775 |
i->type == IT_OIL_REFINERY && |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
776 |
(found == NULL || CHANCE16(1, 2))) { |
0 | 777 |
found = i; |
778 |
} |
|
779 |
} |
|
780 |
||
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
781 |
if (found == NULL) return; |
0 | 782 |
|
783 |
v = ForceAllocateSpecialVehicle(); |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
784 |
if (v == NULL) return; |
0 | 785 |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
786 |
x = (MapSizeX() + 9) * TILE_SIZE - 1; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
787 |
y = TileY(found->xy) * TILE_SIZE + 37; |
0 | 788 |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
789 |
InitializeDisasterVehicle(v, x, y, 135, DIR_NE, 4); |
0 | 790 |
|
791 |
u = ForceAllocateSpecialVehicle(); |
|
792 |
if (u != NULL) { |
|
793 |
v->next = u; |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
794 |
InitializeDisasterVehicle(u, x, y, 0, DIR_SE, 5); |
4175
b79ec8a94d4e
(svn r5613) Rename VS_DISASTER to VS_SHADOW, because this is what this flag actually means
tron
parents:
4077
diff
changeset
|
795 |
u->vehstatus |= VS_SHADOW; |
0 | 796 |
} |
797 |
} |
|
798 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
799 |
static void Disaster3_Init(void) |
0 | 800 |
{ |
801 |
Industry *i, *found; |
|
802 |
Vehicle *v,*u,*w; |
|
803 |
int x,y; |
|
804 |
||
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
805 |
found = NULL; |
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
806 |
|
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
807 |
FOR_ALL_INDUSTRIES(i) { |
0 | 808 |
if (i->xy != 0 && |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
809 |
i->type == IT_FACTORY && |
0 | 810 |
(found==NULL || CHANCE16(1,2))) { |
811 |
found = i; |
|
812 |
} |
|
813 |
} |
|
814 |
||
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
815 |
if (found == NULL) return; |
0 | 816 |
|
817 |
v = ForceAllocateSpecialVehicle(); |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
818 |
if (v == NULL) return; |
0 | 819 |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
820 |
x = -16 * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
821 |
y = TileY(found->xy) * TILE_SIZE + 37; |
0 | 822 |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
823 |
InitializeDisasterVehicle(v, x, y, 135, DIR_SW, 6); |
0 | 824 |
|
825 |
u = ForceAllocateSpecialVehicle(); |
|
826 |
if (u != NULL) { |
|
827 |
v->next = u; |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
828 |
InitializeDisasterVehicle(u, x, y, 0, DIR_SW, 7); |
4175
b79ec8a94d4e
(svn r5613) Rename VS_DISASTER to VS_SHADOW, because this is what this flag actually means
tron
parents:
4077
diff
changeset
|
829 |
u->vehstatus |= VS_SHADOW; |
0 | 830 |
|
831 |
w = ForceAllocateSpecialVehicle(); |
|
832 |
if (w != NULL) { |
|
833 |
u->next = w; |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
834 |
InitializeDisasterVehicle(w, x, y, 140, DIR_SW, 8); |
0 | 835 |
} |
836 |
} |
|
837 |
} |
|
838 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
839 |
static void Disaster4_Init(void) |
0 | 840 |
{ |
841 |
Vehicle *v = ForceAllocateSpecialVehicle(), *u; |
|
842 |
int x,y; |
|
843 |
||
2639 | 844 |
if (v == NULL) return; |
0 | 845 |
|
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
846 |
x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2; |
0 | 847 |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
848 |
y = MapMaxX() * TILE_SIZE - 1; |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
849 |
InitializeDisasterVehicle(v, x, y, 135, DIR_NW, 9); |
1981 | 850 |
v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2); |
0 | 851 |
v->age = 0; |
852 |
||
853 |
// Allocate shadow too? |
|
854 |
u = ForceAllocateSpecialVehicle(); |
|
855 |
if (u != NULL) { |
|
856 |
v->next = u; |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
857 |
InitializeDisasterVehicle(u, x, y, 0, DIR_NW, 10); |
4175
b79ec8a94d4e
(svn r5613) Rename VS_DISASTER to VS_SHADOW, because this is what this flag actually means
tron
parents:
4077
diff
changeset
|
858 |
u->vehstatus |= VS_SHADOW; |
0 | 859 |
} |
860 |
} |
|
861 |
||
862 |
// Submarine type 1 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
863 |
static void Disaster5_Init(void) |
0 | 864 |
{ |
865 |
Vehicle *v = ForceAllocateSpecialVehicle(); |
|
866 |
int x,y; |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
867 |
Direction dir; |
0 | 868 |
uint32 r; |
869 |
||
2639 | 870 |
if (v == NULL) return; |
0 | 871 |
|
872 |
r = Random(); |
|
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
873 |
x = TileX(r) * TILE_SIZE + TILE_SIZE / 2; |
0 | 874 |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
875 |
if (r & 0x80000000) { |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
876 |
y = MapMaxX() * TILE_SIZE - TILE_SIZE / 2 - 1; |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
877 |
dir = DIR_NW; |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
878 |
} else { |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
879 |
y = TILE_SIZE / 2; |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
880 |
dir = DIR_SE; |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
881 |
} |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
882 |
InitializeDisasterVehicle(v, x, y, 0, dir, 13); |
0 | 883 |
v->age = 0; |
884 |
} |
|
885 |
||
886 |
// Submarine type 2 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
887 |
static void Disaster6_Init(void) |
0 | 888 |
{ |
889 |
Vehicle *v = ForceAllocateSpecialVehicle(); |
|
890 |
int x,y; |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
891 |
Direction dir; |
0 | 892 |
uint32 r; |
893 |
||
2639 | 894 |
if (v == NULL) return; |
0 | 895 |
|
896 |
r = Random(); |
|
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
897 |
x = TileX(r) * TILE_SIZE + TILE_SIZE / 2; |
0 | 898 |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
899 |
if (r & 0x80000000) { |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
900 |
y = MapMaxX() * TILE_SIZE - TILE_SIZE / 2 - 1; |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
901 |
dir = DIR_NW; |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
902 |
} else { |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
903 |
y = TILE_SIZE / 2; |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
904 |
dir = DIR_SE; |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
905 |
} |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
906 |
InitializeDisasterVehicle(v, x, y, 0, dir, 14); |
0 | 907 |
v->age = 0; |
908 |
} |
|
909 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
910 |
static void Disaster7_Init(void) |
0 | 911 |
{ |
2642 | 912 |
int index = GB(Random(), 0, 4); |
2648
677ba48b2549
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
913 |
uint m; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
914 |
|
2648
677ba48b2549
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
915 |
for (m = 0; m < 15; m++) { |
2989 | 916 |
const Industry* i; |
917 |
||
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
918 |
FOR_ALL_INDUSTRIES(i) { |
2026 | 919 |
if (i->xy != 0 && i->type == IT_COAL_MINE && --index < 0) { |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
920 |
SetDParam(0, i->town->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
921 |
AddNewsItem(STR_B005_COAL_MINE_SUBSIDENCE_LEAVES, |
1981 | 922 |
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
|
923 |
|
0 | 924 |
{ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
925 |
TileIndex tile = i->xy; |
2635 | 926 |
TileIndexDiff step = TileOffsByDir(GB(Random(), 0, 2)); |
2648
677ba48b2549
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
927 |
uint n; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
928 |
|
2674
8585b4842df6
(svn r3216) - Fix (regression): endless loop introduced in revision 3190
Darkvater
parents:
2668
diff
changeset
|
929 |
for (n = 0; n < 30; n++) { |
0 | 930 |
DisasterClearSquare(tile); |
931 |
tile = TILE_MASK(tile + step); |
|
2648
677ba48b2549
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
932 |
} |
0 | 933 |
} |
934 |
return; |
|
935 |
} |
|
936 |
} |
|
2648
677ba48b2549
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
937 |
} |
0 | 938 |
} |
939 |
||
940 |
static DisasterInitProc * const _disaster_initprocs[] = { |
|
941 |
Disaster0_Init, |
|
942 |
Disaster1_Init, |
|
943 |
Disaster2_Init, |
|
944 |
Disaster3_Init, |
|
945 |
Disaster4_Init, |
|
946 |
Disaster5_Init, |
|
947 |
Disaster6_Init, |
|
948 |
Disaster7_Init, |
|
949 |
}; |
|
950 |
||
2655
1ff3459b4c84
(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 |
#define MK(a, b) { (a) - MAX_YEAR_BEGIN_REAL, (b) - MAX_YEAR_BEGIN_REAL } |
1ff3459b4c84
(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 |
static const struct { |
1ff3459b4c84
(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 |
byte min; |
1ff3459b4c84
(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 |
byte max; |
1ff3459b4c84
(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 |
} _dis_years[] = { |
1ff3459b4c84
(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(1930, 1955), |
1ff3459b4c84
(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, 1970), |
1ff3459b4c84
(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(1960, 1990), |
1ff3459b4c84
(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(1970, 2000), |
1ff3459b4c84
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
960 |
MK(2000, 2100), |
1ff3459b4c84
(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 |
MK(1940, 1965), |
1ff3459b4c84
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
962 |
MK(1975, 2010), |
1ff3459b4c84
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
963 |
MK(1950, 1985) |
0 | 964 |
}; |
2655
1ff3459b4c84
(svn r3197) Use a better bias so you can directly see the date range a disaster can happen in
tron
parents:
2648
diff
changeset
|
965 |
#undef MK |
0 | 966 |
|
967 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
968 |
static void DoDisaster(void) |
0 | 969 |
{ |
2639 | 970 |
byte buf[lengthof(_dis_years)]; |
0 | 971 |
byte year = _cur_year; |
2639 | 972 |
uint i; |
973 |
uint j; |
|
0 | 974 |
|
2639 | 975 |
j = 0; |
976 |
for (i = 0; i != lengthof(_dis_years); i++) { |
|
977 |
if (year >= _dis_years[i].min && year < _dis_years[i].max) buf[j++] = i; |
|
0 | 978 |
} |
979 |
||
2639 | 980 |
if (j == 0) return; |
0 | 981 |
|
2637
722dae65c4a8
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2635
diff
changeset
|
982 |
_disaster_initprocs[buf[RandomRange(j)]](); |
0 | 983 |
} |
984 |
||
985 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
986 |
static void ResetDisasterDelay(void) |
0 | 987 |
{ |
2484
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2435
diff
changeset
|
988 |
_disaster_delay = GB(Random(), 0, 9) + 730; |
0 | 989 |
} |
990 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
991 |
void DisasterDailyLoop(void) |
0 | 992 |
{ |
2639 | 993 |
if (--_disaster_delay != 0) return; |
0 | 994 |
|
995 |
ResetDisasterDelay(); |
|
996 |
||
2639 | 997 |
if (_opt.diff.disasters != 0) DoDisaster(); |
0 | 998 |
} |
999 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
1000 |
void StartupDisasters(void) |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1048
diff
changeset
|
1001 |
{ |
0 | 1002 |
ResetDisasterDelay(); |
1003 |
} |