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