author | KUDr |
Sat, 21 Apr 2007 08:23:57 +0000 | |
branch | cpp_gui |
changeset 6308 | 646711c5feaa |
parent 6307 | f40e88cff863 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6268
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
3 |
/** @file disaster_cmd.cpp |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
4 |
* All disaster/easter egg vehicles are handled here. |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
5 |
* The general flow of control for the disaster vehicles is as follows: |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
6 |
* <ol> |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
7 |
* <li>Initialize the disaster in a disaster specific way (eg start position, |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
8 |
* possible target, etc.) Disaster_XXX_Init() function |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
9 |
* <li>Add a subtype to a disaster, which is an index into the function array |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
10 |
* that handles the vehicle's ticks. |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
11 |
* <li>Run the disaster vehicles each tick until their target has been reached, |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
12 |
* this happens in the DisasterTick_XXX() functions. In here, a vehicle's |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
13 |
* state is kept by v->current_order.dest variable. Each achieved sub-target |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
14 |
* will increase this value, and the last one will remove the disaster itself |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
15 |
* </ol> |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
16 |
*/ |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
17 |
|
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
18 |
|
0 | 19 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1359
diff
changeset
|
20 |
#include "openttd.h" |
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4346
diff
changeset
|
21 |
#include "functions.h" |
6307 | 22 |
#include "landscape.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
|
23 |
#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
|
24 |
#include "station_map.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
410
diff
changeset
|
25 |
#include "table/strings.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
555
diff
changeset
|
26 |
#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
|
27 |
#include "tile.h" |
0 | 28 |
#include "vehicle.h" |
29 |
#include "command.h" |
|
30 |
#include "news.h" |
|
31 |
#include "station.h" |
|
2435
66742d77db13
(svn r2961) - Fix: [ 1219123 ] Fix for [ 1216203 ] UFO-broken waypoint (lucaspiller)
Darkvater
parents:
2360
diff
changeset
|
32 |
#include "waypoint.h" |
0 | 33 |
#include "town.h" |
34 |
#include "industry.h" |
|
35 |
#include "player.h" |
|
3701
13911c5df3e7
(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
|
36 |
#include "airport.h" |
337
66647f97e7c0
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
37 |
#include "sound.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2140
diff
changeset
|
38 |
#include "variables.h" |
2535 | 39 |
#include "table/sprites.h" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4249
diff
changeset
|
40 |
#include "date.h" |
0 | 41 |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
42 |
enum DisasterSubType { |
5951
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
43 |
ST_Zeppeliner, |
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
44 |
ST_Zeppeliner_Shadow, |
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
45 |
ST_Small_Ufo, |
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
46 |
ST_Small_Ufo_Shadow, |
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
47 |
ST_Airplane, |
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
48 |
ST_Airplane_Shadow, |
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
49 |
ST_Helicopter, |
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
50 |
ST_Helicopter_Shadow, |
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
51 |
ST_Helicopter_Rotors, |
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
52 |
ST_Big_Ufo, |
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
53 |
ST_Big_Ufo_Shadow, |
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
54 |
ST_Big_Ufo_Destroyer, |
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
55 |
ST_Big_Ufo_Destroyer_Shadow, |
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
56 |
ST_Small_Submarine, |
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
57 |
ST_Big_Submarine, |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
58 |
}; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
59 |
|
1048 | 60 |
static void DisasterClearSquare(TileIndex tile) |
0 | 61 |
{ |
2639 | 62 |
if (!EnsureNoVehicle(tile)) return; |
0 | 63 |
|
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1212
diff
changeset
|
64 |
switch (GetTileType(tile)) { |
1048 | 65 |
case MP_RAILWAY: |
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4559
diff
changeset
|
66 |
if (IsHumanPlayer(GetTileOwner(tile)) && !IsRailWaypoint(tile)) { |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3701
diff
changeset
|
67 |
PlayerID p = _current_player; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3701
diff
changeset
|
68 |
_current_player = OWNER_WATER; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3701
diff
changeset
|
69 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3701
diff
changeset
|
70 |
_current_player = p; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3701
diff
changeset
|
71 |
} |
1048 | 72 |
break; |
0 | 73 |
|
1048 | 74 |
case MP_HOUSE: { |
2435
66742d77db13
(svn r2961) - Fix: [ 1219123 ] Fix for [ 1216203 ] UFO-broken waypoint (lucaspiller)
Darkvater
parents:
2360
diff
changeset
|
75 |
PlayerID p = _current_player; |
1048 | 76 |
_current_player = OWNER_NONE; |
3491
4c8427796c64
(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
|
77 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
1048 | 78 |
_current_player = p; |
79 |
break; |
|
80 |
} |
|
81 |
||
82 |
case MP_TREES: |
|
83 |
case MP_CLEAR: |
|
0 | 84 |
DoClearSquare(tile); |
1048 | 85 |
break; |
86 |
||
87 |
default: |
|
88 |
break; |
|
0 | 89 |
} |
90 |
} |
|
91 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
92 |
static const SpriteID _disaster_images_1[] = {SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP, SPR_BLIMP}; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
93 |
static const SpriteID _disaster_images_2[] = {SPR_UFO_SMALL_SCOUT, SPR_UFO_SMALL_SCOUT, SPR_UFO_SMALL_SCOUT, SPR_UFO_SMALL_SCOUT, SPR_UFO_SMALL_SCOUT, SPR_UFO_SMALL_SCOUT, SPR_UFO_SMALL_SCOUT, SPR_UFO_SMALL_SCOUT}; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
94 |
static const SpriteID _disaster_images_3[] = {SPR_F_15, SPR_F_15, SPR_F_15, SPR_F_15, SPR_F_15, SPR_F_15, SPR_F_15, SPR_F_15}; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
95 |
static const SpriteID _disaster_images_4[] = {SPR_SUB_SMALL_NE, SPR_SUB_SMALL_NE, SPR_SUB_SMALL_SE, SPR_SUB_SMALL_SE, SPR_SUB_SMALL_SW, SPR_SUB_SMALL_SW, SPR_SUB_SMALL_NW, SPR_SUB_SMALL_NW}; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
96 |
static const SpriteID _disaster_images_5[] = {SPR_SUB_LARGE_NE, SPR_SUB_LARGE_NE, SPR_SUB_LARGE_SE, SPR_SUB_LARGE_SE, SPR_SUB_LARGE_SW, SPR_SUB_LARGE_SW, SPR_SUB_LARGE_NW, SPR_SUB_LARGE_NW}; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
97 |
static const SpriteID _disaster_images_6[] = {SPR_UFO_HARVESTER, SPR_UFO_HARVESTER, SPR_UFO_HARVESTER, SPR_UFO_HARVESTER, SPR_UFO_HARVESTER, SPR_UFO_HARVESTER, SPR_UFO_HARVESTER, SPR_UFO_HARVESTER}; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
98 |
static const SpriteID _disaster_images_7[] = {SPR_XCOM_SKYRANGER, SPR_XCOM_SKYRANGER, SPR_XCOM_SKYRANGER, SPR_XCOM_SKYRANGER, SPR_XCOM_SKYRANGER, SPR_XCOM_SKYRANGER, SPR_XCOM_SKYRANGER, SPR_XCOM_SKYRANGER}; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
99 |
static const SpriteID _disaster_images_8[] = {SPR_AH_64A, SPR_AH_64A, SPR_AH_64A, SPR_AH_64A, SPR_AH_64A, SPR_AH_64A, SPR_AH_64A, SPR_AH_64A}; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
100 |
static const SpriteID _disaster_images_9[] = {SPR_ROTOR_MOVING_1, SPR_ROTOR_MOVING_1, SPR_ROTOR_MOVING_1, SPR_ROTOR_MOVING_1, SPR_ROTOR_MOVING_1, SPR_ROTOR_MOVING_1, SPR_ROTOR_MOVING_1, SPR_ROTOR_MOVING_1}; |
0 | 101 |
|
102 |
static const SpriteID * const _disaster_images[] = { |
|
6268
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
103 |
_disaster_images_1, _disaster_images_1, ///< zeppeliner and zeppeliner shadow |
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
104 |
_disaster_images_2, _disaster_images_2, ///< small ufo and small ufo shadow |
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
105 |
_disaster_images_3, _disaster_images_3, ///< combat aircraft and shadow |
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
106 |
_disaster_images_8, _disaster_images_8, _disaster_images_9, ///< combat helicopter, shadow and rotor |
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
107 |
_disaster_images_6, _disaster_images_6, ///< big ufo and shadow |
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
108 |
_disaster_images_7, _disaster_images_7, ///< skyranger and shadow |
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
109 |
_disaster_images_4, _disaster_images_5, ///< small and big submarine sprites |
0 | 110 |
}; |
111 |
||
112 |
static void DisasterVehicleUpdateImage(Vehicle *v) |
|
113 |
{ |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
114 |
SpriteID img = v->u.disaster.image_override; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
115 |
if (img == 0) img = _disaster_images[v->subtype][v->direction]; |
0 | 116 |
v->cur_image = img; |
117 |
} |
|
118 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
119 |
|
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
120 |
/** Initialize a disaster vehicle. These vehicles are of type VEH_DISASTER, are unclickable |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
121 |
* and owned by nobody */ |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
122 |
static void InitializeDisasterVehicle(Vehicle *v, int x, int y, byte z, Direction direction, byte subtype) |
0 | 123 |
{ |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
124 |
v->type = VEH_DISASTER; |
0 | 125 |
v->x_pos = x; |
126 |
v->y_pos = y; |
|
127 |
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
|
128 |
v->tile = TileVirtXY(x, y); |
0 | 129 |
v->direction = direction; |
130 |
v->subtype = subtype; |
|
131 |
v->x_offs = -1; |
|
132 |
v->y_offs = -1; |
|
133 |
v->sprite_width = 2; |
|
134 |
v->sprite_height = 2; |
|
135 |
v->z_height = 5; |
|
136 |
v->owner = OWNER_NONE; |
|
137 |
v->vehstatus = VS_UNCLICKABLE; |
|
138 |
v->u.disaster.image_override = 0; |
|
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
139 |
v->current_order.Free(); |
0 | 140 |
|
141 |
DisasterVehicleUpdateImage(v); |
|
142 |
VehiclePositionChanged(v); |
|
143 |
BeginVehicleMove(v); |
|
144 |
EndVehicleMove(v); |
|
145 |
} |
|
146 |
||
147 |
static void DeleteDisasterVeh(Vehicle *v) |
|
148 |
{ |
|
149 |
DeleteVehicleChain(v); |
|
150 |
} |
|
151 |
||
152 |
static void SetDisasterVehiclePos(Vehicle *v, int x, int y, byte z) |
|
153 |
{ |
|
154 |
Vehicle *u; |
|
155 |
||
156 |
BeginVehicleMove(v); |
|
157 |
v->x_pos = x; |
|
158 |
v->y_pos = y; |
|
159 |
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
|
160 |
v->tile = TileVirtXY(x, y); |
0 | 161 |
|
162 |
DisasterVehicleUpdateImage(v); |
|
163 |
VehiclePositionChanged(v); |
|
164 |
EndVehicleMove(v); |
|
165 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
166 |
if ((u = v->next) != NULL) { |
4249
9eedb1473740
(svn r5841) -Fix r5794: use the height of the edge of the map for shadows of disasters that are outside the map
rubidium
parents:
4175
diff
changeset
|
167 |
int safe_x = clamp(x, 0, MapMaxX() * TILE_SIZE); |
9eedb1473740
(svn r5841) -Fix r5794: use the height of the edge of the map for shadows of disasters that are outside the map
rubidium
parents:
4175
diff
changeset
|
168 |
int safe_y = clamp(y - 1, 0, MapMaxY() * TILE_SIZE); |
0 | 169 |
BeginVehicleMove(u); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
170 |
|
0 | 171 |
u->x_pos = x; |
5852
cb3f71b16e1a
(svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents:
5838
diff
changeset
|
172 |
u->y_pos = y - 1 - (max(z - GetSlopeZ(safe_x, safe_y), 0U) >> 3); |
4249
9eedb1473740
(svn r5841) -Fix r5794: use the height of the edge of the map for shadows of disasters that are outside the map
rubidium
parents:
4175
diff
changeset
|
173 |
safe_y = clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE); |
9eedb1473740
(svn r5841) -Fix r5794: use the height of the edge of the map for shadows of disasters that are outside the map
rubidium
parents:
4175
diff
changeset
|
174 |
u->z_pos = GetSlopeZ(safe_x, safe_y); |
0 | 175 |
u->direction = v->direction; |
176 |
||
177 |
DisasterVehicleUpdateImage(u); |
|
178 |
VehiclePositionChanged(u); |
|
179 |
EndVehicleMove(u); |
|
180 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
181 |
if ((u = u->next) != NULL) { |
0 | 182 |
BeginVehicleMove(u); |
183 |
u->x_pos = x; |
|
184 |
u->y_pos = y; |
|
185 |
u->z_pos = z + 5; |
|
186 |
VehiclePositionChanged(u); |
|
187 |
EndVehicleMove(u); |
|
188 |
} |
|
189 |
} |
|
190 |
} |
|
191 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
192 |
/** |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
193 |
* Zeppeliner handling, v->current_order.dest states: |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
194 |
* 0: Zeppeliner initialization has found a small airport, go there and crash |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
195 |
* 1: Create crash and animate falling down for extra dramatic effect |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
196 |
* 2: Create more smoke and leave debris on ground |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
197 |
* 2: Clear the runway after some time and remove crashed zeppeliner |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
198 |
* If not airport was found, only state 0 is reached until zeppeliner leaves map |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
199 |
*/ |
0 | 200 |
static void DisasterTick_Zeppeliner(Vehicle *v) |
201 |
{ |
|
202 |
Station *st; |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
203 |
int x, y; |
0 | 204 |
byte z; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
205 |
TileIndex tile; |
0 | 206 |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
207 |
v->tick_counter++; |
0 | 208 |
|
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
209 |
if (v->current_order.dest < 2) { |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
210 |
if (HASBIT(v->tick_counter, 0)) return; |
0 | 211 |
|
6268
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
212 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
213 |
|
0 | 214 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
215 |
||
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
216 |
if (v->current_order.dest == 1) { |
0 | 217 |
if (++v->age == 38) { |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
218 |
v->current_order.dest = 2; |
0 | 219 |
v->age = 0; |
220 |
} |
|
221 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
222 |
if (GB(v->tick_counter, 0, 3) == 0) CreateEffectVehicleRel(v, 0, -17, 2, EV_SMOKE); |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
223 |
|
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
224 |
} else if (v->current_order.dest == 0) { |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
225 |
tile = v->tile; |
0 | 226 |
|
1212
e9fbf66a8af2
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
227 |
if (IsValidTile(tile) && |
e9fbf66a8af2
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
228 |
IsTileType(tile, MP_STATION) && |
3338
2c60ed0dcce3
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
229 |
IsAirport(tile) && |
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4559
diff
changeset
|
230 |
IsHumanPlayer(GetTileOwner(tile))) { |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
231 |
v->current_order.dest = 1; |
0 | 232 |
v->age = 0; |
233 |
||
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3314
diff
changeset
|
234 |
SetDParam(0, GetStationIndex(tile)); |
0 | 235 |
AddNewsItem(STR_B000_ZEPPELIN_DISASTER_AT, |
6308 | 236 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_VEHICLE, NT_ACCIDENT, 0), |
0 | 237 |
v->index, |
238 |
0); |
|
239 |
} |
|
240 |
} |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
241 |
|
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
242 |
if (v->y_pos >= ((int)MapSizeY() + 9) * TILE_SIZE - 1) DeleteDisasterVeh(v); |
0 | 243 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
244 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
245 |
|
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
246 |
if (v->current_order.dest > 2) { |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
247 |
if (++v->age <= 13320) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
248 |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
249 |
tile = v->tile; |
0 | 250 |
|
1212
e9fbf66a8af2
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
251 |
if (IsValidTile(tile) && |
e9fbf66a8af2
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
252 |
IsTileType(tile, MP_STATION) && |
3338
2c60ed0dcce3
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
253 |
IsAirport(tile) && |
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4559
diff
changeset
|
254 |
IsHumanPlayer(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
|
255 |
st = GetStationByTile(tile); |
0 | 256 |
CLRBITS(st->airport_flags, RUNWAY_IN_block); |
257 |
} |
|
258 |
||
259 |
SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos); |
|
260 |
DeleteDisasterVeh(v); |
|
261 |
return; |
|
262 |
} |
|
263 |
||
264 |
x = v->x_pos; |
|
265 |
y = v->y_pos; |
|
6308 | 266 |
z = GetSlopeZ(x, y); |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
267 |
if (z < v->z_pos) z = v->z_pos - 1; |
0 | 268 |
SetDisasterVehiclePos(v, x, y, z); |
269 |
||
270 |
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
|
271 |
CreateEffectVehicleRel(v, 0, 7, 8, EV_EXPLOSION_LARGE); |
541 | 272 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
2535 | 273 |
v->u.disaster.image_override = SPR_BLIMP_CRASHING; |
0 | 274 |
} else if (v->age == 70) { |
2535 | 275 |
v->u.disaster.image_override = SPR_BLIMP_CRASHED; |
0 | 276 |
} else if (v->age <= 300) { |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
277 |
if (GB(v->tick_counter, 0, 3) == 0) { |
0 | 278 |
uint32 r = Random(); |
279 |
||
280 |
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
|
281 |
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
|
282 |
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
|
283 |
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
|
284 |
EV_EXPLOSION_SMALL); |
0 | 285 |
} |
286 |
} else if (v->age == 350) { |
|
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
287 |
v->current_order.dest = 3; |
0 | 288 |
v->age = 0; |
289 |
} |
|
290 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
291 |
tile = v->tile; |
1212
e9fbf66a8af2
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
292 |
if (IsValidTile(tile) && |
e9fbf66a8af2
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
293 |
IsTileType(tile, MP_STATION) && |
3338
2c60ed0dcce3
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
294 |
IsAirport(tile) && |
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4559
diff
changeset
|
295 |
IsHumanPlayer(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
|
296 |
st = GetStationByTile(tile); |
0 | 297 |
SETBITS(st->airport_flags, RUNWAY_IN_block); |
298 |
} |
|
299 |
} |
|
300 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
301 |
/** |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
302 |
* (Small) Ufo handling, v->current_order.dest states: |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
303 |
* 0: Fly around to the middle of the map, then randomly, after a while target a road vehicle |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
304 |
* 1: Home in on a road vehicle and crash it >:) |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
305 |
* If not road vehicle was found, only state 0 is used and Ufo disappears after a while |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
306 |
*/ |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
307 |
static void DisasterTick_Ufo(Vehicle *v) |
0 | 308 |
{ |
309 |
Vehicle *u; |
|
310 |
uint dist; |
|
311 |
byte z; |
|
312 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
313 |
v->u.disaster.image_override = (HASBIT(++v->tick_counter, 3)) ? 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
|
314 |
|
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
315 |
if (v->current_order.dest == 0) { |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
316 |
/* Fly around randomly */ |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
317 |
int x = TileX(v->dest_tile) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
318 |
int y = TileY(v->dest_tile) * TILE_SIZE; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
319 |
if (delta(x, v->x_pos) + delta(y, v->y_pos) >= TILE_SIZE) { |
0 | 320 |
v->direction = GetDirectionTowards(v, x, y); |
6268
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
321 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
0 | 322 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
323 |
return; |
|
324 |
} |
|
325 |
if (++v->age < 6) { |
|
2051 | 326 |
v->dest_tile = RandomTile(); |
0 | 327 |
return; |
328 |
} |
|
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
329 |
v->current_order.dest = 1; |
0 | 330 |
|
331 |
FOR_ALL_VEHICLES(u) { |
|
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
332 |
if (u->type == VEH_ROAD && IsHumanPlayer(u->owner)) { |
0 | 333 |
v->dest_tile = u->index; |
334 |
v->age = 0; |
|
335 |
return; |
|
336 |
} |
|
337 |
} |
|
338 |
||
339 |
DeleteDisasterVeh(v); |
|
340 |
} else { |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
341 |
/* Target a vehicle */ |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
342 |
u = GetVehicle(v->dest_tile); |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
343 |
if (u->type != VEH_ROAD) { |
0 | 344 |
DeleteDisasterVeh(v); |
345 |
return; |
|
346 |
} |
|
347 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
348 |
dist = delta(v->x_pos, u->x_pos) + delta(v->y_pos, u->y_pos); |
0 | 349 |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
350 |
if (dist < TILE_SIZE && !(u->vehstatus & VS_HIDDEN) && u->breakdown_ctr == 0) { |
0 | 351 |
u->breakdown_ctr = 3; |
352 |
u->breakdown_delay = 140; |
|
353 |
} |
|
354 |
||
355 |
v->direction = GetDirectionTowards(v, u->x_pos, u->y_pos); |
|
6268
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
356 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
357 |
|
0 | 358 |
z = v->z_pos; |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
359 |
if (dist <= TILE_SIZE && z > u->z_pos) z--; |
0 | 360 |
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
|
361 |
|
6308 | 362 |
if (z <= u->z_pos && (u->vehstatus & VS_HIDDEN) == 0) { |
0 | 363 |
v->age++; |
364 |
if (u->u.road.crashed_ctr == 0) { |
|
365 |
u->u.road.crashed_ctr++; |
|
366 |
u->vehstatus |= VS_CRASHED; |
|
367 |
||
368 |
AddNewsItem(STR_B001_ROAD_VEHICLE_DESTROYED, |
|
6308 | 369 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_VEHICLE, NT_ACCIDENT, 0), |
0 | 370 |
u->index, |
371 |
0); |
|
372 |
} |
|
373 |
} |
|
374 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
375 |
/* Destroy? */ |
0 | 376 |
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
|
377 |
CreateEffectVehicleRel(v, 0, 7, 8, EV_EXPLOSION_LARGE); |
541 | 378 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
0 | 379 |
DeleteDisasterVeh(v); |
380 |
} |
|
381 |
} |
|
382 |
} |
|
383 |
||
384 |
static void DestructIndustry(Industry *i) |
|
385 |
{ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
386 |
TileIndex tile; |
0 | 387 |
|
2026 | 388 |
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
|
389 |
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == i->index) { |
3495
f7d3ae07f4aa
(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
|
390 |
ResetIndustryConstructionStage(tile); |
0 | 391 |
MarkTileDirtyByTile(tile); |
392 |
} |
|
393 |
} |
|
394 |
} |
|
395 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
396 |
/** |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
397 |
* Airplane handling, v->current_order.dest states: |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
398 |
* 0: Fly towards the targetted oil refinery |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
399 |
* 1: If within 15 tiles, fire away rockets and destroy industry |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
400 |
* 2: Refinery explosions |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
401 |
* 3: Fly out of the map |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
402 |
* If the industry was removed in the meantime just fly to the end of the map |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
403 |
*/ |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
404 |
static void DisasterTick_Airplane(Vehicle *v) |
0 | 405 |
{ |
406 |
v->tick_counter++; |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
407 |
v->u.disaster.image_override = |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
408 |
(v->current_order.dest == 1 && HASBIT(v->tick_counter, 2)) ? SPR_F_15_FIRING : 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
409 |
|
6268
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
410 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
0 | 411 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
412 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
413 |
if (gp.x < (-10 * TILE_SIZE)) { |
0 | 414 |
DeleteDisasterVeh(v); |
415 |
return; |
|
416 |
} |
|
417 |
||
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
418 |
if (v->current_order.dest == 2) { |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
419 |
if (GB(v->tick_counter, 0, 2) == 0) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
420 |
Industry *i = GetIndustry(v->dest_tile); |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
421 |
int x = TileX(i->xy) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
422 |
int y = TileY(i->xy) * TILE_SIZE; |
0 | 423 |
uint32 r = Random(); |
424 |
||
425 |
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
|
426 |
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
|
427 |
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
|
428 |
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
|
429 |
EV_EXPLOSION_SMALL); |
0 | 430 |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
431 |
if (++v->age >= 55) v->current_order.dest = 3; |
0 | 432 |
} |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
433 |
} else if (v->current_order.dest == 1) { |
0 | 434 |
if (++v->age == 112) { |
435 |
Industry *i; |
|
436 |
||
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
437 |
v->current_order.dest = 2; |
0 | 438 |
v->age = 0; |
439 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
440 |
i = GetIndustry(v->dest_tile); |
0 | 441 |
DestructIndustry(i); |
442 |
||
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
443 |
SetDParam(0, i->town->index); |
6308 | 444 |
AddNewsItem(STR_B002_OIL_REFINERY_EXPLOSION, NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_ACCIDENT, 0), i->xy, 0); |
541 | 445 |
SndPlayTileFx(SND_12_EXPLOSION, i->xy); |
0 | 446 |
} |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
447 |
} else if (v->current_order.dest == 0) { |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
448 |
int x, y; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
449 |
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
|
450 |
uint ind; |
0 | 451 |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
452 |
x = v->x_pos - (15 * TILE_SIZE); |
0 | 453 |
y = v->y_pos; |
454 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
455 |
if ( (uint)x > MapMaxX() * TILE_SIZE - 1) return; |
0 | 456 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
457 |
tile = TileVirtXY(x, y); |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
458 |
if (!IsTileType(tile, MP_INDUSTRY)) return; |
0 | 459 |
|
3314
b8b234d4584f
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3269
diff
changeset
|
460 |
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
|
461 |
v->dest_tile = ind; |
0 | 462 |
|
6307 | 463 |
if (GetIndustrySpec(GetIndustry(ind)->type)->behaviour & INDUSTRYBEH_AIRPLANE_ATTACKS) { |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
464 |
v->current_order.dest = 1; |
0 | 465 |
v->age = 0; |
466 |
} |
|
467 |
} |
|
468 |
} |
|
469 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
470 |
/** |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
471 |
* Helicopter handling, v->current_order.dest states: |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
472 |
* 0: Fly towards the targetted factory |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
473 |
* 1: If within 15 tiles, fire away rockets and destroy industry |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
474 |
* 2: Factory explosions |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
475 |
* 3: Fly out of the map |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
476 |
*/ |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
477 |
static void DisasterTick_Helicopter(Vehicle *v) |
0 | 478 |
{ |
479 |
v->tick_counter++; |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
480 |
v->u.disaster.image_override = |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
481 |
(v->current_order.dest == 1 && HASBIT(v->tick_counter, 2)) ? SPR_AH_64A_FIRING : 0; |
0 | 482 |
|
6268
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
483 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
0 | 484 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
485 |
||
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
486 |
if (gp.x > (int)MapSizeX() * TILE_SIZE + 9 * TILE_SIZE - 1) { |
0 | 487 |
DeleteDisasterVeh(v); |
488 |
return; |
|
489 |
} |
|
490 |
||
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
491 |
if (v->current_order.dest == 2) { |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
492 |
if (GB(v->tick_counter, 0, 2) == 0) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
493 |
Industry *i = GetIndustry(v->dest_tile); |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
494 |
int x = TileX(i->xy) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
495 |
int y = TileY(i->xy) * TILE_SIZE; |
0 | 496 |
uint32 r = Random(); |
497 |
||
498 |
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
|
499 |
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
|
500 |
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
|
501 |
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
|
502 |
EV_EXPLOSION_SMALL); |
0 | 503 |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
504 |
if (++v->age >= 55) v->current_order.dest = 3; |
0 | 505 |
} |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
506 |
} else if (v->current_order.dest == 1) { |
0 | 507 |
if (++v->age == 112) { |
508 |
Industry *i; |
|
509 |
||
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
510 |
v->current_order.dest = 2; |
0 | 511 |
v->age = 0; |
512 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
513 |
i = GetIndustry(v->dest_tile); |
0 | 514 |
DestructIndustry(i); |
515 |
||
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
516 |
SetDParam(0, i->town->index); |
6308 | 517 |
AddNewsItem(STR_B003_FACTORY_DESTROYED_IN_SUSPICIOUS, NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_ACCIDENT, 0), i->xy, 0); |
541 | 518 |
SndPlayTileFx(SND_12_EXPLOSION, i->xy); |
0 | 519 |
} |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
520 |
} else if (v->current_order.dest == 0) { |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
521 |
int x, y; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
522 |
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
|
523 |
uint ind; |
0 | 524 |
|
5931
1d832a07c2d6
(svn r8140) -Fix [FS#54]: Combat helicopter flies past factory before it shoots. Chopper comes from the north-east, so it looks in +15 direction (forward), not -15 direction. Probably bad copy-paste from airplane-destroys-oil-refinery disaster.
Darkvater
parents:
5852
diff
changeset
|
525 |
x = v->x_pos + (15 * TILE_SIZE); |
0 | 526 |
y = v->y_pos; |
527 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
528 |
if ( (uint)x > MapMaxX() * TILE_SIZE - 1) return; |
0 | 529 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
530 |
tile = TileVirtXY(x, y); |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
531 |
if (!IsTileType(tile, MP_INDUSTRY)) return; |
0 | 532 |
|
3314
b8b234d4584f
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3269
diff
changeset
|
533 |
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
|
534 |
v->dest_tile = ind; |
0 | 535 |
|
6307 | 536 |
if (GetIndustrySpec(GetIndustry(ind)->type)->behaviour & INDUSTRYBEH_CHOPPER_ATTACKS) { |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
537 |
v->current_order.dest = 1; |
0 | 538 |
v->age = 0; |
539 |
} |
|
540 |
} |
|
541 |
} |
|
542 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
543 |
/** Helicopter rotor blades; keep these spinning */ |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
544 |
static void DisasterTick_Helicopter_Rotors(Vehicle *v) |
0 | 545 |
{ |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
546 |
v->tick_counter++; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
547 |
if (HASBIT(v->tick_counter, 0)) return; |
0 | 548 |
|
2535 | 549 |
if (++v->cur_image > SPR_ROTOR_MOVING_3) v->cur_image = SPR_ROTOR_MOVING_1; |
0 | 550 |
|
551 |
VehiclePositionChanged(v); |
|
552 |
BeginVehicleMove(v); |
|
553 |
EndVehicleMove(v); |
|
554 |
} |
|
555 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
556 |
/** |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
557 |
* (Big) Ufo handling, v->current_order.dest states: |
5951
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
558 |
* 0: Fly around to the middle of the map, then randomly for a while and home in on a piece of rail |
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
559 |
* 1: Land there and breakdown all trains in a radius of 12 tiles; and now we wait... |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
560 |
* because as soon as the Ufo lands, a fighter jet, a Skyranger, is called to clear up the mess |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
561 |
*/ |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
562 |
static void DisasterTick_Big_Ufo(Vehicle *v) |
0 | 563 |
{ |
564 |
byte z; |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
565 |
Vehicle *u, *w; |
0 | 566 |
Town *t; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
567 |
TileIndex tile; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
568 |
TileIndex tile_org; |
0 | 569 |
|
570 |
v->tick_counter++; |
|
571 |
||
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
572 |
if (v->current_order.dest == 1) { |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
573 |
int x = TileX(v->dest_tile) * TILE_SIZE + TILE_SIZE / 2; |
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
574 |
int y = TileY(v->dest_tile) * TILE_SIZE + TILE_SIZE / 2; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
575 |
if (delta(v->x_pos, x) + delta(v->y_pos, y) >= 8) { |
0 | 576 |
v->direction = GetDirectionTowards(v, x, y); |
577 |
||
6268
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
578 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
0 | 579 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
580 |
return; |
|
581 |
} |
|
582 |
||
583 |
z = GetSlopeZ(v->x_pos, v->y_pos); |
|
584 |
if (z < v->z_pos) { |
|
585 |
SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos - 1); |
|
586 |
return; |
|
587 |
} |
|
588 |
||
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
589 |
v->current_order.dest = 2; |
0 | 590 |
|
591 |
FOR_ALL_VEHICLES(u) { |
|
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
592 |
if (u->type == VEH_TRAIN || u->type == VEH_ROAD) { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
593 |
if (delta(u->x_pos, v->x_pos) + delta(u->y_pos, v->y_pos) <= 12 * TILE_SIZE) { |
0 | 594 |
u->breakdown_ctr = 5; |
595 |
u->breakdown_delay = 0xF0; |
|
596 |
} |
|
597 |
} |
|
598 |
} |
|
599 |
||
600 |
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
|
601 |
SetDParam(0, t->index); |
0 | 602 |
AddNewsItem(STR_B004_UFO_LANDS_NEAR, |
6308 | 603 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_ACCIDENT, 0), |
0 | 604 |
v->tile, |
605 |
0); |
|
606 |
||
607 |
u = ForceAllocateSpecialVehicle(); |
|
608 |
if (u == NULL) { |
|
609 |
DeleteDisasterVeh(v); |
|
610 |
return; |
|
611 |
} |
|
612 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
613 |
InitializeDisasterVehicle(u, -6 * TILE_SIZE, v->y_pos, 135, DIR_SW, ST_Big_Ufo_Destroyer); |
0 | 614 |
u->u.disaster.unk2 = v->index; |
615 |
||
616 |
w = ForceAllocateSpecialVehicle(); |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
617 |
if (w == NULL) return; |
0 | 618 |
|
619 |
u->next = w; |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
620 |
InitializeDisasterVehicle(w, -6 * TILE_SIZE, v->y_pos, 0, DIR_SW, ST_Big_Ufo_Destroyer_Shadow); |
4175
c0bcc65f36d4
(svn r5613) Rename VS_DISASTER to VS_SHADOW, because this is what this flag actually means
tron
parents:
4077
diff
changeset
|
621 |
w->vehstatus |= VS_SHADOW; |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
622 |
} else if (v->current_order.dest == 0) { |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
623 |
int x = TileX(v->dest_tile) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
624 |
int y = TileY(v->dest_tile) * TILE_SIZE; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
625 |
if (delta(x, v->x_pos) + delta(y, v->y_pos) >= TILE_SIZE) { |
0 | 626 |
v->direction = GetDirectionTowards(v, x, y); |
6268
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
627 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
0 | 628 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
629 |
return; |
|
630 |
} |
|
631 |
||
632 |
if (++v->age < 6) { |
|
2051 | 633 |
v->dest_tile = RandomTile(); |
0 | 634 |
return; |
635 |
} |
|
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
636 |
v->current_order.dest = 1; |
0 | 637 |
|
2051 | 638 |
tile_org = tile = RandomTile(); |
0 | 639 |
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
|
640 |
if (IsTileType(tile, MP_RAILWAY) && |
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3161
diff
changeset
|
641 |
IsPlainRailTile(tile) && |
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4559
diff
changeset
|
642 |
IsHumanPlayer(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
|
643 |
break; |
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3161
diff
changeset
|
644 |
} |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
645 |
tile = TILE_MASK(tile + 1); |
0 | 646 |
} while (tile != tile_org); |
647 |
v->dest_tile = tile; |
|
648 |
v->age = 0; |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
649 |
} else { |
0 | 650 |
return; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
651 |
} |
0 | 652 |
} |
653 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
654 |
/** |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
655 |
* Skyranger destroying (Big) Ufo handling, v->current_order.dest states: |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
656 |
* 0: Home in on landed Ufo and shoot it down |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
657 |
*/ |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
658 |
static void DisasterTick_Big_Ufo_Destroyer(Vehicle *v) |
0 | 659 |
{ |
660 |
Vehicle *u; |
|
661 |
int i; |
|
662 |
||
663 |
v->tick_counter++; |
|
664 |
||
6268
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
665 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
0 | 666 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
667 |
||
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
668 |
if (gp.x > (int)MapSizeX() * TILE_SIZE + 9 * TILE_SIZE - 1) { |
0 | 669 |
DeleteDisasterVeh(v); |
670 |
return; |
|
671 |
} |
|
672 |
||
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
673 |
if (v->current_order.dest == 0) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
674 |
u = GetVehicle(v->u.disaster.unk2); |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
675 |
if (delta(v->x_pos, u->x_pos) > TILE_SIZE) return; |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
676 |
v->current_order.dest = 1; |
0 | 677 |
|
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
|
678 |
CreateEffectVehicleRel(u, 0, 7, 8, EV_EXPLOSION_LARGE); |
541 | 679 |
SndPlayVehicleFx(SND_12_EXPLOSION, u); |
0 | 680 |
|
681 |
DeleteDisasterVeh(u); |
|
682 |
||
2952 | 683 |
for (i = 0; i != 80; i++) { |
0 | 684 |
uint32 r = Random(); |
685 |
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
|
686 |
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
|
687 |
GB(r, 5, 6) + v->y_pos - 32, |
0 | 688 |
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
|
689 |
EV_EXPLOSION_SMALL); |
0 | 690 |
} |
691 |
||
1981 | 692 |
BEGIN_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3)) |
0 | 693 |
tile = TILE_MASK(tile); |
694 |
DisasterClearSquare(tile); |
|
1981 | 695 |
END_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3)) |
0 | 696 |
} |
697 |
} |
|
698 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
699 |
/** |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
700 |
* Submarine, v->current_order.dest states: |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
701 |
* Unused, just float around aimlessly and pop up at different places, turning around |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
702 |
*/ |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
703 |
static void DisasterTick_Submarine(Vehicle *v) |
0 | 704 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
705 |
TileIndex tile; |
0 | 706 |
|
707 |
v->tick_counter++; |
|
708 |
||
709 |
if (++v->age > 8880) { |
|
710 |
VehiclePositionChanged(v); |
|
711 |
BeginVehicleMove(v); |
|
712 |
EndVehicleMove(v); |
|
713 |
DeleteVehicle(v); |
|
714 |
return; |
|
715 |
} |
|
716 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
717 |
if (!HASBIT(v->tick_counter, 0)) return; |
0 | 718 |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
719 |
tile = v->tile + TileOffsByDiagDir(DirToDiagDir(v->direction)); |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
720 |
if (IsValidTile(tile)) { |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
721 |
TrackdirBits r = (TrackdirBits)GetTileTrackStatus(tile, TRANSPORT_WATER); |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
722 |
|
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
723 |
if (TrackdirBitsToTrackBits(r) == TRACK_BIT_ALL && !CHANCE16(1, 90)) { |
6268
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
724 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
725 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
726 |
return; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
727 |
} |
0 | 728 |
} |
729 |
||
3160 | 730 |
v->direction = ChangeDir(v->direction, GB(Random(), 0, 1) ? DIRDIFF_90RIGHT : DIRDIFF_90LEFT); |
0 | 731 |
} |
732 |
||
733 |
||
734 |
static void DisasterTick_NULL(Vehicle *v) {} |
|
735 |
typedef void DisasterVehicleTickProc(Vehicle *v); |
|
736 |
||
737 |
static DisasterVehicleTickProc * const _disastervehicle_tick_procs[] = { |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
738 |
DisasterTick_Zeppeliner, DisasterTick_NULL, |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
739 |
DisasterTick_Ufo, DisasterTick_NULL, |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
740 |
DisasterTick_Airplane, DisasterTick_NULL, |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
741 |
DisasterTick_Helicopter, DisasterTick_NULL, DisasterTick_Helicopter_Rotors, |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
742 |
DisasterTick_Big_Ufo, DisasterTick_NULL, DisasterTick_Big_Ufo_Destroyer, |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
743 |
DisasterTick_NULL, |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
744 |
DisasterTick_Submarine, |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
745 |
DisasterTick_Submarine, |
0 | 746 |
}; |
747 |
||
748 |
||
749 |
void DisasterVehicle_Tick(Vehicle *v) |
|
750 |
{ |
|
751 |
_disastervehicle_tick_procs[v->subtype](v); |
|
752 |
} |
|
753 |
||
754 |
||
755 |
void OnNewDay_DisasterVehicle(Vehicle *v) |
|
756 |
{ |
|
757 |
// not used |
|
758 |
} |
|
759 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
760 |
typedef void DisasterInitProc(); |
0 | 761 |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
762 |
|
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
763 |
/** Zeppeliner which crashes on a small airport if one found, |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
764 |
* otherwise crashes on a random tile */ |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
765 |
static void Disaster_Zeppeliner_Init() |
0 | 766 |
{ |
767 |
Vehicle *v = ForceAllocateSpecialVehicle(), *u; |
|
768 |
Station *st; |
|
769 |
int x; |
|
770 |
||
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
771 |
if (v == NULL) return; |
0 | 772 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
773 |
/* Pick a random place, unless we find a small airport */ |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
774 |
x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
775 |
|
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
776 |
FOR_ALL_STATIONS(st) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
777 |
if (st->airport_tile != 0 && |
0 | 778 |
st->airport_type <= 1 && |
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4559
diff
changeset
|
779 |
IsHumanPlayer(st->owner)) { |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
780 |
x = (TileX(st->xy) + 2) * TILE_SIZE; |
0 | 781 |
break; |
782 |
} |
|
783 |
} |
|
784 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
785 |
InitializeDisasterVehicle(v, x, 0, 135, DIR_SE, ST_Zeppeliner); |
0 | 786 |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
787 |
/* Allocate shadow too? */ |
0 | 788 |
u = ForceAllocateSpecialVehicle(); |
789 |
if (u != NULL) { |
|
790 |
v->next = u; |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
791 |
InitializeDisasterVehicle(u, x, 0, 0, DIR_SE, ST_Zeppeliner_Shadow); |
4175
c0bcc65f36d4
(svn r5613) Rename VS_DISASTER to VS_SHADOW, because this is what this flag actually means
tron
parents:
4077
diff
changeset
|
792 |
u->vehstatus |= VS_SHADOW; |
0 | 793 |
} |
794 |
} |
|
795 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
796 |
|
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
797 |
/** Ufo which flies around aimlessly from the middle of the map a bit |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
798 |
* until it locates a road vehicle which it targets and then destroys */ |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
799 |
static void Disaster_Small_Ufo_Init() |
0 | 800 |
{ |
801 |
Vehicle *v = ForceAllocateSpecialVehicle(), *u; |
|
802 |
int x; |
|
803 |
||
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
804 |
if (v == NULL) return; |
0 | 805 |
|
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
806 |
x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2; |
0 | 807 |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
808 |
InitializeDisasterVehicle(v, x, 0, 135, DIR_SE, ST_Small_Ufo); |
1981 | 809 |
v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2); |
0 | 810 |
v->age = 0; |
811 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
812 |
/* Allocate shadow too? */ |
0 | 813 |
u = ForceAllocateSpecialVehicle(); |
814 |
if (u != NULL) { |
|
815 |
v->next = u; |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
816 |
InitializeDisasterVehicle(u, x, 0, 0, DIR_SE, ST_Small_Ufo_Shadow); |
4175
c0bcc65f36d4
(svn r5613) Rename VS_DISASTER to VS_SHADOW, because this is what this flag actually means
tron
parents:
4077
diff
changeset
|
817 |
u->vehstatus |= VS_SHADOW; |
0 | 818 |
} |
819 |
} |
|
820 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
821 |
|
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
822 |
/* Combat airplane which destroys an oil refinery */ |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
823 |
static void Disaster_Airplane_Init() |
0 | 824 |
{ |
825 |
Industry *i, *found; |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
826 |
Vehicle *v, *u; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
827 |
int x, y; |
0 | 828 |
|
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
829 |
found = NULL; |
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
830 |
|
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
831 |
FOR_ALL_INDUSTRIES(i) { |
6307 | 832 |
if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_AIRPLANE_ATTACKS) && |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
833 |
(found == NULL || CHANCE16(1, 2))) { |
0 | 834 |
found = i; |
835 |
} |
|
836 |
} |
|
837 |
||
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
838 |
if (found == NULL) return; |
0 | 839 |
|
840 |
v = ForceAllocateSpecialVehicle(); |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
841 |
if (v == NULL) return; |
0 | 842 |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
843 |
/* Start from the bottom (south side) of the map */ |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
844 |
x = (MapSizeX() + 9) * TILE_SIZE - 1; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
845 |
y = TileY(found->xy) * TILE_SIZE + 37; |
0 | 846 |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
847 |
InitializeDisasterVehicle(v, x, y, 135, DIR_NE, ST_Airplane); |
0 | 848 |
|
849 |
u = ForceAllocateSpecialVehicle(); |
|
850 |
if (u != NULL) { |
|
851 |
v->next = u; |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
852 |
InitializeDisasterVehicle(u, x, y, 0, DIR_SE, ST_Airplane_Shadow); |
4175
c0bcc65f36d4
(svn r5613) Rename VS_DISASTER to VS_SHADOW, because this is what this flag actually means
tron
parents:
4077
diff
changeset
|
853 |
u->vehstatus |= VS_SHADOW; |
0 | 854 |
} |
855 |
} |
|
856 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
857 |
|
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
858 |
/** Combat helicopter that destroys a factory */ |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
859 |
static void Disaster_Helicopter_Init() |
0 | 860 |
{ |
861 |
Industry *i, *found; |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
862 |
Vehicle *v, *u, *w; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
863 |
int x, y; |
0 | 864 |
|
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
865 |
found = NULL; |
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
866 |
|
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
867 |
FOR_ALL_INDUSTRIES(i) { |
6307 | 868 |
if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CHOPPER_ATTACKS) && |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
869 |
(found == NULL || CHANCE16(1, 2))) { |
0 | 870 |
found = i; |
871 |
} |
|
872 |
} |
|
873 |
||
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
874 |
if (found == NULL) return; |
0 | 875 |
|
876 |
v = ForceAllocateSpecialVehicle(); |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
877 |
if (v == NULL) return; |
0 | 878 |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
879 |
x = -16 * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
880 |
y = TileY(found->xy) * TILE_SIZE + 37; |
0 | 881 |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
882 |
InitializeDisasterVehicle(v, x, y, 135, DIR_SW, ST_Helicopter); |
0 | 883 |
|
884 |
u = ForceAllocateSpecialVehicle(); |
|
885 |
if (u != NULL) { |
|
886 |
v->next = u; |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
887 |
InitializeDisasterVehicle(u, x, y, 0, DIR_SW, ST_Helicopter_Shadow); |
4175
c0bcc65f36d4
(svn r5613) Rename VS_DISASTER to VS_SHADOW, because this is what this flag actually means
tron
parents:
4077
diff
changeset
|
888 |
u->vehstatus |= VS_SHADOW; |
0 | 889 |
|
890 |
w = ForceAllocateSpecialVehicle(); |
|
891 |
if (w != NULL) { |
|
892 |
u->next = w; |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
893 |
InitializeDisasterVehicle(w, x, y, 140, DIR_SW, ST_Helicopter_Rotors); |
0 | 894 |
} |
895 |
} |
|
896 |
} |
|
897 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
898 |
|
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
899 |
/* Big Ufo which lands on a piece of rail and will consequently be shot |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
900 |
* down by a combat airplane, destroying the surroundings */ |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
901 |
static void Disaster_Big_Ufo_Init() |
0 | 902 |
{ |
903 |
Vehicle *v = ForceAllocateSpecialVehicle(), *u; |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
904 |
int x, y; |
0 | 905 |
|
2639 | 906 |
if (v == NULL) return; |
0 | 907 |
|
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
908 |
x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2; |
0 | 909 |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
910 |
y = MapMaxX() * TILE_SIZE - 1; |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
911 |
InitializeDisasterVehicle(v, x, y, 135, DIR_NW, ST_Big_Ufo); |
1981 | 912 |
v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2); |
0 | 913 |
v->age = 0; |
914 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
915 |
/* Allocate shadow too? */ |
0 | 916 |
u = ForceAllocateSpecialVehicle(); |
917 |
if (u != NULL) { |
|
918 |
v->next = u; |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
919 |
InitializeDisasterVehicle(u, x, y, 0, DIR_NW, ST_Big_Ufo_Shadow); |
4175
c0bcc65f36d4
(svn r5613) Rename VS_DISASTER to VS_SHADOW, because this is what this flag actually means
tron
parents:
4077
diff
changeset
|
920 |
u->vehstatus |= VS_SHADOW; |
0 | 921 |
} |
922 |
} |
|
923 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
924 |
|
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
925 |
/* Curious submarine #1, just floats around */ |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
926 |
static void Disaster_Small_Submarine_Init() |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
927 |
{ |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
928 |
Vehicle *v = ForceAllocateSpecialVehicle(); |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
929 |
int x, y; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
930 |
Direction dir; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
931 |
uint32 r; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
932 |
|
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
933 |
if (v == NULL) return; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
934 |
|
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
935 |
r = Random(); |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
936 |
x = TileX(r) * TILE_SIZE + TILE_SIZE / 2; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
937 |
|
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
938 |
if (HASBIT(r, 31)) { |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
939 |
y = MapMaxX() * TILE_SIZE - TILE_SIZE / 2 - 1; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
940 |
dir = DIR_NW; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
941 |
} else { |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
942 |
y = TILE_SIZE / 2; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
943 |
dir = DIR_SE; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
944 |
} |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
945 |
InitializeDisasterVehicle(v, x, y, 0, dir, ST_Small_Submarine); |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
946 |
v->age = 0; |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
947 |
} |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
948 |
|
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
949 |
|
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
950 |
/* Curious submarine #2, just floats around */ |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
951 |
static void Disaster_Big_Submarine_Init() |
0 | 952 |
{ |
953 |
Vehicle *v = ForceAllocateSpecialVehicle(); |
|
6308 | 954 |
int x, y; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
955 |
Direction dir; |
0 | 956 |
uint32 r; |
957 |
||
2639 | 958 |
if (v == NULL) return; |
0 | 959 |
|
960 |
r = Random(); |
|
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
961 |
x = TileX(r) * TILE_SIZE + TILE_SIZE / 2; |
0 | 962 |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
963 |
if (HASBIT(r, 31)) { |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
964 |
y = MapMaxX() * TILE_SIZE - TILE_SIZE / 2 - 1; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
965 |
dir = DIR_NW; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
966 |
} else { |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
967 |
y = TILE_SIZE / 2; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
968 |
dir = DIR_SE; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
969 |
} |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
970 |
InitializeDisasterVehicle(v, x, y, 0, dir, ST_Big_Submarine); |
0 | 971 |
v->age = 0; |
972 |
} |
|
973 |
||
974 |
||
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
975 |
/** Coal mine catastrophe, destroys a stretch of 30 tiles of |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
976 |
* land in a certain direction */ |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
977 |
static void Disaster_CoalMine_Init() |
0 | 978 |
{ |
2642 | 979 |
int index = GB(Random(), 0, 4); |
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
980 |
uint m; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
981 |
|
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
982 |
for (m = 0; m < 15; m++) { |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
983 |
const Industry *i; |
2989 | 984 |
|
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
985 |
FOR_ALL_INDUSTRIES(i) { |
6307 | 986 |
if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CAN_SUBSIDENCE) && --index < 0) { |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
987 |
SetDParam(0, i->town->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
988 |
AddNewsItem(STR_B005_COAL_MINE_SUBSIDENCE_LEAVES, |
6308 | 989 |
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
|
990 |
|
0 | 991 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
992 |
TileIndex tile = i->xy; |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
993 |
TileIndexDiff step = TileOffsByDiagDir(GB(Random(), 0, 2)); |
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
994 |
uint n; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
995 |
|
2674
1d68ffc9f406
(svn r3216) - Fix (regression): endless loop introduced in revision 3190
Darkvater
parents:
2668
diff
changeset
|
996 |
for (n = 0; n < 30; n++) { |
0 | 997 |
DisasterClearSquare(tile); |
998 |
tile = TILE_MASK(tile + step); |
|
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
999 |
} |
0 | 1000 |
} |
1001 |
return; |
|
1002 |
} |
|
1003 |
} |
|
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
1004 |
} |
0 | 1005 |
} |
1006 |
||
1007 |
static DisasterInitProc * const _disaster_initprocs[] = { |
|
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
1008 |
Disaster_Zeppeliner_Init, |
5951
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
1009 |
Disaster_Small_Ufo_Init, |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
1010 |
Disaster_Airplane_Init, |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
1011 |
Disaster_Helicopter_Init, |
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
1012 |
Disaster_Big_Ufo_Init, |
5951
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
1013 |
Disaster_Small_Submarine_Init, |
9dfa5b0116e4
(svn r8164) -Codechange (r8159): Fix up some comments/doxygen for disasters and rename Submarine1/2 to small/big
Darkvater
parents:
5946
diff
changeset
|
1014 |
Disaster_Big_Submarine_Init, |
5946
ca8d7faa51e5
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5945
diff
changeset
|
1015 |
Disaster_CoalMine_Init, |
0 | 1016 |
}; |
1017 |
||
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
|
1018 |
static const struct { |
4293
2c24234a7aec
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4286
diff
changeset
|
1019 |
Year min; |
2c24234a7aec
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4286
diff
changeset
|
1020 |
Year max; |
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
|
1021 |
} _dis_years[] = { |
6268
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
1022 |
{ 1930, 1955 }, ///< zeppeliner |
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
1023 |
{ 1940, 1970 }, ///< ufo (small) |
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
1024 |
{ 1960, 1990 }, ///< airplane |
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
1025 |
{ 1970, 2000 }, ///< helicopter |
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
1026 |
{ 2000, 2100 }, ///< ufo (big) |
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
1027 |
{ 1940, 1965 }, ///< submarine (small) |
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
1028 |
{ 1975, 2010 }, ///< submarine (big) |
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5951
diff
changeset
|
1029 |
{ 1950, 1985 } ///< coalmine |
0 | 1030 |
}; |
1031 |
||
1032 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
1033 |
static void DoDisaster() |
0 | 1034 |
{ |
2639 | 1035 |
byte buf[lengthof(_dis_years)]; |
1036 |
uint i; |
|
1037 |
uint j; |
|
0 | 1038 |
|
2639 | 1039 |
j = 0; |
1040 |
for (i = 0; i != lengthof(_dis_years); i++) { |
|
4293
2c24234a7aec
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4286
diff
changeset
|
1041 |
if (_cur_year >= _dis_years[i].min && _cur_year < _dis_years[i].max) buf[j++] = i; |
0 | 1042 |
} |
1043 |
||
2639 | 1044 |
if (j == 0) return; |
0 | 1045 |
|
2637
8807e6a63f89
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2635
diff
changeset
|
1046 |
_disaster_initprocs[buf[RandomRange(j)]](); |
0 | 1047 |
} |
1048 |
||
1049 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
1050 |
static void ResetDisasterDelay() |
0 | 1051 |
{ |
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
|
1052 |
_disaster_delay = GB(Random(), 0, 9) + 730; |
0 | 1053 |
} |
1054 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
1055 |
void DisasterDailyLoop() |
0 | 1056 |
{ |
2639 | 1057 |
if (--_disaster_delay != 0) return; |
0 | 1058 |
|
1059 |
ResetDisasterDelay(); |
|
1060 |
||
2639 | 1061 |
if (_opt.diff.disasters != 0) DoDisaster(); |
0 | 1062 |
} |
1063 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
1064 |
void StartupDisasters() |
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
|
1065 |
{ |
0 | 1066 |
ResetDisasterDelay(); |
1067 |
} |