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