author | rubidium |
Sun, 25 May 2008 19:17:03 +0000 | |
changeset 9354 | 845e07db4549 |
parent 9234 | bfc9d27d3d0d |
child 9358 | 2e1e4d2f71dd |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6117
6507b2a7e71d
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
5700
diff
changeset
|
3 |
/** @file disaster_cmd.cpp |
5695
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" |
6453
226bcddeba32
(svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents:
6390
diff
changeset
|
21 |
#include "landscape.h" |
8119
52b48108425a
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents:
8116
diff
changeset
|
22 |
|
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3269
diff
changeset
|
23 |
#include "industry_map.h" |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3314
diff
changeset
|
24 |
#include "station_map.h" |
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
25 |
#include "command_func.h" |
8119
52b48108425a
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents:
8116
diff
changeset
|
26 |
#include "tile_cmd.h" |
8763
81fadd257f67
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents:
8616
diff
changeset
|
27 |
#include "news_func.h" |
8785
871586967963
(svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents:
8763
diff
changeset
|
28 |
#include "station_base.h" |
2435
9b9d43988058
(svn r2961) - Fix: [ 1219123 ] Fix for [ 1216203 ] UFO-broken waypoint (lucaspiller)
Darkvater
parents:
2360
diff
changeset
|
29 |
#include "waypoint.h" |
0 | 30 |
#include "town.h" |
31 |
#include "industry.h" |
|
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8157
diff
changeset
|
32 |
#include "player_func.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
|
33 |
#include "airport.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2140
diff
changeset
|
34 |
#include "variables.h" |
8270
e7c342f6b14c
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8264
diff
changeset
|
35 |
#include "settings_type.h" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8108
diff
changeset
|
36 |
#include "strings_func.h" |
8140
0d0d8c94f84b
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8139
diff
changeset
|
37 |
#include "date_func.h" |
8131
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8121
diff
changeset
|
38 |
#include "functions.h" |
8144
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
39 |
#include "vehicle_func.h" |
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
40 |
#include "vehicle_base.h" |
8157
1505def01945
(svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents:
8144
diff
changeset
|
41 |
#include "sound_func.h" |
9009
6684576ef32b
(svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium
parents:
8840
diff
changeset
|
42 |
#include "effectvehicle_func.h" |
0 | 43 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
44 |
#include "table/strings.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
45 |
#include "table/sprites.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
46 |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
ST_Big_Submarine, |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
63 |
}; |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
64 |
|
1048 | 65 |
static void DisasterClearSquare(TileIndex tile) |
0 | 66 |
{ |
7758
17ad53748c7b
(svn r11303) -Fix: EnsureNoVehicle and EnsureNoVehicleOnGround were both used to check whether there was no vehicle on the ground, except that the former didn't take care of aircraft shadows. So now we only use EnsureNoVehicleOnGround.
rubidium
parents:
7493
diff
changeset
|
67 |
if (!EnsureNoVehicleOnGround(tile)) return; |
0 | 68 |
|
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1212
diff
changeset
|
69 |
switch (GetTileType(tile)) { |
1048 | 70 |
case MP_RAILWAY: |
4845
72bbb6e2694e
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4559
diff
changeset
|
71 |
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
|
72 |
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
|
73 |
_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
|
74 |
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
|
75 |
_current_player = p; |
8347
7edfa9e0c8ad
(svn r11913) -Fix (r11871): update signals after company bankrupt and disaster too
smatz
parents:
8317
diff
changeset
|
76 |
|
7edfa9e0c8ad
(svn r11913) -Fix (r11871): update signals after company bankrupt and disaster too
smatz
parents:
8317
diff
changeset
|
77 |
/* update signals in buffer */ |
7edfa9e0c8ad
(svn r11913) -Fix (r11871): update signals after company bankrupt and disaster too
smatz
parents:
8317
diff
changeset
|
78 |
UpdateSignalsInBuffer(); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3701
diff
changeset
|
79 |
} |
1048 | 80 |
break; |
0 | 81 |
|
1048 | 82 |
case MP_HOUSE: { |
2435
9b9d43988058
(svn r2961) - Fix: [ 1219123 ] Fix for [ 1216203 ] UFO-broken waypoint (lucaspiller)
Darkvater
parents:
2360
diff
changeset
|
83 |
PlayerID p = _current_player; |
1048 | 84 |
_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
|
85 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
1048 | 86 |
_current_player = p; |
87 |
break; |
|
88 |
} |
|
89 |
||
90 |
case MP_TREES: |
|
91 |
case MP_CLEAR: |
|
0 | 92 |
DoClearSquare(tile); |
1048 | 93 |
break; |
94 |
||
95 |
default: |
|
96 |
break; |
|
0 | 97 |
} |
98 |
} |
|
99 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
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 | 109 |
|
110 |
static const SpriteID * const _disaster_images[] = { |
|
6125
a6fff965707c
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
111 |
_disaster_images_1, _disaster_images_1, ///< zeppeliner and zeppeliner shadow |
a6fff965707c
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
112 |
_disaster_images_2, _disaster_images_2, ///< small ufo and small ufo shadow |
a6fff965707c
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
113 |
_disaster_images_3, _disaster_images_3, ///< combat aircraft and shadow |
a6fff965707c
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
114 |
_disaster_images_8, _disaster_images_8, _disaster_images_9, ///< combat helicopter, shadow and rotor |
a6fff965707c
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
115 |
_disaster_images_6, _disaster_images_6, ///< big ufo and shadow |
a6fff965707c
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
116 |
_disaster_images_7, _disaster_images_7, ///< skyranger and shadow |
a6fff965707c
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
117 |
_disaster_images_4, _disaster_images_5, ///< small and big submarine sprites |
0 | 118 |
}; |
119 |
||
120 |
static void DisasterVehicleUpdateImage(Vehicle *v) |
|
121 |
{ |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
122 |
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
|
123 |
if (img == 0) img = _disaster_images[v->subtype][v->direction]; |
0 | 124 |
v->cur_image = img; |
125 |
} |
|
126 |
||
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
127 |
/** Initialize a disaster vehicle. These vehicles are of type VEH_DISASTER, are unclickable |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
128 |
* and owned by nobody */ |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
129 |
static void InitializeDisasterVehicle(Vehicle *v, int x, int y, byte z, Direction direction, byte subtype) |
0 | 130 |
{ |
131 |
v->x_pos = x; |
|
132 |
v->y_pos = y; |
|
133 |
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
|
134 |
v->tile = TileVirtXY(x, y); |
0 | 135 |
v->direction = direction; |
136 |
v->subtype = subtype; |
|
6558
c88e142f896e
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents:
6552
diff
changeset
|
137 |
v->UpdateDeltaXY(INVALID_DIR); |
0 | 138 |
v->owner = OWNER_NONE; |
139 |
v->vehstatus = VS_UNCLICKABLE; |
|
140 |
v->u.disaster.image_override = 0; |
|
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
141 |
v->current_order.Free(); |
0 | 142 |
|
143 |
DisasterVehicleUpdateImage(v); |
|
144 |
VehiclePositionChanged(v); |
|
8317
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8270
diff
changeset
|
145 |
MarkSingleVehicleDirty(v); |
0 | 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 |
||
7492
35acee076719
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7398
diff
changeset
|
167 |
if ((u = v->Next()) != NULL) { |
7922
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7758
diff
changeset
|
168 |
int safe_x = Clamp(x, 0, MapMaxX() * TILE_SIZE); |
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7758
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); |
7922
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7758
diff
changeset
|
174 |
safe_y = Clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE); |
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
|
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 |
||
7492
35acee076719
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7398
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 |
Station *st; |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
204 |
int x, y; |
0 | 205 |
byte z; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
206 |
TileIndex tile; |
0 | 207 |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
208 |
v->tick_counter++; |
0 | 209 |
|
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
210 |
if (v->current_order.GetDestination() < 2) { |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
211 |
if (HasBit(v->tick_counter, 0)) return; |
0 | 212 |
|
6153 | 213 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
214 |
|
0 | 215 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
216 |
||
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
217 |
if (v->current_order.GetDestination() == 1) { |
0 | 218 |
if (++v->age == 38) { |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
219 |
v->current_order.SetDestination(2); |
0 | 220 |
v->age = 0; |
221 |
} |
|
222 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
223 |
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
|
224 |
|
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
225 |
} else if (v->current_order.GetDestination() == 0) { |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
226 |
tile = v->tile; |
0 | 227 |
|
1212
781cda2ed164
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
228 |
if (IsValidTile(tile) && |
781cda2ed164
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
229 |
IsTileType(tile, MP_STATION) && |
3338
7cff208f0446
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
230 |
IsAirport(tile) && |
4845
72bbb6e2694e
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4559
diff
changeset
|
231 |
IsHumanPlayer(GetTileOwner(tile))) { |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
232 |
v->current_order.SetDestination(1); |
0 | 233 |
v->age = 0; |
234 |
||
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3314
diff
changeset
|
235 |
SetDParam(0, GetStationIndex(tile)); |
0 | 236 |
AddNewsItem(STR_B000_ZEPPELIN_DISASTER_AT, |
9234
bfc9d27d3d0d
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents:
9009
diff
changeset
|
237 |
NS_ACCIDENT_VEHICLE, |
0 | 238 |
v->index, |
239 |
0); |
|
240 |
} |
|
241 |
} |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
242 |
|
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
243 |
if (v->y_pos >= ((int)MapSizeY() + 9) * TILE_SIZE - 1) DeleteDisasterVeh(v); |
0 | 244 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
245 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
246 |
|
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
247 |
if (v->current_order.GetDestination() > 2) { |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
248 |
if (++v->age <= 13320) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
249 |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
250 |
tile = v->tile; |
0 | 251 |
|
1212
781cda2ed164
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
252 |
if (IsValidTile(tile) && |
781cda2ed164
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
253 |
IsTileType(tile, MP_STATION) && |
3338
7cff208f0446
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
254 |
IsAirport(tile) && |
4845
72bbb6e2694e
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4559
diff
changeset
|
255 |
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
|
256 |
st = GetStationByTile(tile); |
0 | 257 |
CLRBITS(st->airport_flags, RUNWAY_IN_block); |
258 |
} |
|
259 |
||
260 |
SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos); |
|
261 |
DeleteDisasterVeh(v); |
|
262 |
return; |
|
263 |
} |
|
264 |
||
265 |
x = v->x_pos; |
|
266 |
y = v->y_pos; |
|
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6453
diff
changeset
|
267 |
z = GetSlopeZ(x, y); |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
268 |
if (z < v->z_pos) z = v->z_pos - 1; |
0 | 269 |
SetDisasterVehiclePos(v, x, y, z); |
270 |
||
271 |
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
|
272 |
CreateEffectVehicleRel(v, 0, 7, 8, EV_EXPLOSION_LARGE); |
541 | 273 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
2535 | 274 |
v->u.disaster.image_override = SPR_BLIMP_CRASHING; |
0 | 275 |
} else if (v->age == 70) { |
2535 | 276 |
v->u.disaster.image_override = SPR_BLIMP_CRASHED; |
0 | 277 |
} 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
|
278 |
if (GB(v->tick_counter, 0, 3) == 0) { |
0 | 279 |
uint32 r = Random(); |
280 |
||
281 |
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
|
282 |
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
|
283 |
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
|
284 |
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
|
285 |
EV_EXPLOSION_SMALL); |
0 | 286 |
} |
287 |
} else if (v->age == 350) { |
|
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
288 |
v->current_order.SetDestination(3); |
0 | 289 |
v->age = 0; |
290 |
} |
|
291 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
292 |
tile = v->tile; |
1212
781cda2ed164
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
293 |
if (IsValidTile(tile) && |
781cda2ed164
(svn r1716) Prevent zeppelins from accessing non-existent tiles when leaving the map
tron
parents:
1209
diff
changeset
|
294 |
IsTileType(tile, MP_STATION) && |
3338
7cff208f0446
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
295 |
IsAirport(tile) && |
4845
72bbb6e2694e
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4559
diff
changeset
|
296 |
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
|
297 |
st = GetStationByTile(tile); |
0 | 298 |
SETBITS(st->airport_flags, RUNWAY_IN_block); |
299 |
} |
|
300 |
} |
|
301 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
302 |
/** |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
303 |
* (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
|
304 |
* 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
|
305 |
* 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
|
306 |
* 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
|
307 |
*/ |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
308 |
static void DisasterTick_Ufo(Vehicle *v) |
0 | 309 |
{ |
310 |
Vehicle *u; |
|
311 |
uint dist; |
|
312 |
byte z; |
|
313 |
||
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
314 |
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
|
315 |
|
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
316 |
if (v->current_order.GetDestination() == 0) { |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
317 |
/* Fly around randomly */ |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
318 |
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
|
319 |
int y = TileY(v->dest_tile) * TILE_SIZE; |
7970
7d6b9ab57081
(svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13
parents:
7967
diff
changeset
|
320 |
if (Delta(x, v->x_pos) + Delta(y, v->y_pos) >= TILE_SIZE) { |
0 | 321 |
v->direction = GetDirectionTowards(v, x, y); |
6153 | 322 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
0 | 323 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
324 |
return; |
|
325 |
} |
|
326 |
if (++v->age < 6) { |
|
2051 | 327 |
v->dest_tile = RandomTile(); |
0 | 328 |
return; |
329 |
} |
|
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
330 |
v->current_order.SetDestination(1); |
0 | 331 |
|
332 |
FOR_ALL_VEHICLES(u) { |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
333 |
if (u->type == VEH_ROAD && IsHumanPlayer(u->owner)) { |
0 | 334 |
v->dest_tile = u->index; |
335 |
v->age = 0; |
|
336 |
return; |
|
337 |
} |
|
338 |
} |
|
339 |
||
340 |
DeleteDisasterVeh(v); |
|
341 |
} else { |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
342 |
/* Target a vehicle */ |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
343 |
u = GetVehicle(v->dest_tile); |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
344 |
if (u->type != VEH_ROAD) { |
0 | 345 |
DeleteDisasterVeh(v); |
346 |
return; |
|
347 |
} |
|
348 |
||
7970
7d6b9ab57081
(svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13
parents:
7967
diff
changeset
|
349 |
dist = Delta(v->x_pos, u->x_pos) + Delta(v->y_pos, u->y_pos); |
0 | 350 |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
351 |
if (dist < TILE_SIZE && !(u->vehstatus & VS_HIDDEN) && u->breakdown_ctr == 0) { |
0 | 352 |
u->breakdown_ctr = 3; |
353 |
u->breakdown_delay = 140; |
|
354 |
} |
|
355 |
||
356 |
v->direction = GetDirectionTowards(v, u->x_pos, u->y_pos); |
|
6153 | 357 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
358 |
|
0 | 359 |
z = v->z_pos; |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
360 |
if (dist <= TILE_SIZE && z > u->z_pos) z--; |
0 | 361 |
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
|
362 |
|
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6453
diff
changeset
|
363 |
if (z <= u->z_pos && (u->vehstatus & VS_HIDDEN) == 0) { |
0 | 364 |
v->age++; |
365 |
if (u->u.road.crashed_ctr == 0) { |
|
366 |
u->u.road.crashed_ctr++; |
|
367 |
u->vehstatus |= VS_CRASHED; |
|
368 |
||
369 |
AddNewsItem(STR_B001_ROAD_VEHICLE_DESTROYED, |
|
9234
bfc9d27d3d0d
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents:
9009
diff
changeset
|
370 |
NS_ACCIDENT_VEHICLE, |
0 | 371 |
u->index, |
372 |
0); |
|
373 |
} |
|
374 |
} |
|
375 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
376 |
/* Destroy? */ |
0 | 377 |
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
|
378 |
CreateEffectVehicleRel(v, 0, 7, 8, EV_EXPLOSION_LARGE); |
541 | 379 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
0 | 380 |
DeleteDisasterVeh(v); |
381 |
} |
|
382 |
} |
|
383 |
} |
|
384 |
||
385 |
static void DestructIndustry(Industry *i) |
|
386 |
{ |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
387 |
TileIndex tile; |
0 | 388 |
|
2026 | 389 |
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
|
390 |
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
|
391 |
ResetIndustryConstructionStage(tile); |
0 | 392 |
MarkTileDirtyByTile(tile); |
393 |
} |
|
394 |
} |
|
395 |
} |
|
396 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
397 |
/** |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
398 |
* 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
|
399 |
* 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
|
400 |
* 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
|
401 |
* 2: Refinery explosions |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
402 |
* 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
|
403 |
* 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
|
404 |
*/ |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
405 |
static void DisasterTick_Airplane(Vehicle *v) |
0 | 406 |
{ |
407 |
v->tick_counter++; |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
408 |
v->u.disaster.image_override = |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
409 |
(v->current_order.GetDestination() == 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
|
410 |
|
6153 | 411 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
0 | 412 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
413 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
414 |
if (gp.x < (-10 * TILE_SIZE)) { |
0 | 415 |
DeleteDisasterVeh(v); |
416 |
return; |
|
417 |
} |
|
418 |
||
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
419 |
if (v->current_order.GetDestination() == 2) { |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
420 |
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
|
421 |
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
|
422 |
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
|
423 |
int y = TileY(i->xy) * TILE_SIZE; |
0 | 424 |
uint32 r = Random(); |
425 |
||
426 |
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
|
427 |
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
|
428 |
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
|
429 |
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
|
430 |
EV_EXPLOSION_SMALL); |
0 | 431 |
|
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
432 |
if (++v->age >= 55) v->current_order.SetDestination(3); |
0 | 433 |
} |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
434 |
} else if (v->current_order.GetDestination() == 1) { |
0 | 435 |
if (++v->age == 112) { |
436 |
Industry *i; |
|
437 |
||
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
438 |
v->current_order.SetDestination(2); |
0 | 439 |
v->age = 0; |
440 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
441 |
i = GetIndustry(v->dest_tile); |
0 | 442 |
DestructIndustry(i); |
443 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
444 |
SetDParam(0, i->town->index); |
9234
bfc9d27d3d0d
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents:
9009
diff
changeset
|
445 |
AddNewsItem(STR_B002_OIL_REFINERY_EXPLOSION, NS_ACCIDENT_TILE, i->xy, 0); |
541 | 446 |
SndPlayTileFx(SND_12_EXPLOSION, i->xy); |
0 | 447 |
} |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
448 |
} else if (v->current_order.GetDestination() == 0) { |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
449 |
int x, y; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
450 |
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
|
451 |
uint ind; |
0 | 452 |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
453 |
x = v->x_pos - (15 * TILE_SIZE); |
0 | 454 |
y = v->y_pos; |
455 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
456 |
if ( (uint)x > MapMaxX() * TILE_SIZE - 1) return; |
0 | 457 |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
458 |
tile = TileVirtXY(x, y); |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
459 |
if (!IsTileType(tile, MP_INDUSTRY)) return; |
0 | 460 |
|
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3269
diff
changeset
|
461 |
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
|
462 |
v->dest_tile = ind; |
0 | 463 |
|
6390
802629b3c7f1
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6263
diff
changeset
|
464 |
if (GetIndustrySpec(GetIndustry(ind)->type)->behaviour & INDUSTRYBEH_AIRPLANE_ATTACKS) { |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
465 |
v->current_order.SetDestination(1); |
0 | 466 |
v->age = 0; |
467 |
} |
|
468 |
} |
|
469 |
} |
|
470 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
471 |
/** |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
472 |
* 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
|
473 |
* 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
|
474 |
* 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
|
475 |
* 2: Factory explosions |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
476 |
* 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
|
477 |
*/ |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
478 |
static void DisasterTick_Helicopter(Vehicle *v) |
0 | 479 |
{ |
480 |
v->tick_counter++; |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
481 |
v->u.disaster.image_override = |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
482 |
(v->current_order.GetDestination() == 1 && HasBit(v->tick_counter, 2)) ? SPR_AH_64A_FIRING : 0; |
0 | 483 |
|
6153 | 484 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
0 | 485 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
486 |
||
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
487 |
if (gp.x > (int)MapSizeX() * TILE_SIZE + 9 * TILE_SIZE - 1) { |
0 | 488 |
DeleteDisasterVeh(v); |
489 |
return; |
|
490 |
} |
|
491 |
||
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
492 |
if (v->current_order.GetDestination() == 2) { |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
493 |
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
|
494 |
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
|
495 |
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
|
496 |
int y = TileY(i->xy) * TILE_SIZE; |
0 | 497 |
uint32 r = Random(); |
498 |
||
499 |
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
|
500 |
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
|
501 |
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
|
502 |
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
|
503 |
EV_EXPLOSION_SMALL); |
0 | 504 |
|
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
505 |
if (++v->age >= 55) v->current_order.SetDestination(3); |
0 | 506 |
} |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
507 |
} else if (v->current_order.GetDestination() == 1) { |
0 | 508 |
if (++v->age == 112) { |
509 |
Industry *i; |
|
510 |
||
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
511 |
v->current_order.SetDestination(2); |
0 | 512 |
v->age = 0; |
513 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
514 |
i = GetIndustry(v->dest_tile); |
0 | 515 |
DestructIndustry(i); |
516 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
517 |
SetDParam(0, i->town->index); |
9234
bfc9d27d3d0d
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents:
9009
diff
changeset
|
518 |
AddNewsItem(STR_B003_FACTORY_DESTROYED_IN_SUSPICIOUS, NS_ACCIDENT_TILE, i->xy, 0); |
541 | 519 |
SndPlayTileFx(SND_12_EXPLOSION, i->xy); |
0 | 520 |
} |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
521 |
} else if (v->current_order.GetDestination() == 0) { |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
522 |
int x, y; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
523 |
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
|
524 |
uint ind; |
0 | 525 |
|
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
|
526 |
x = v->x_pos + (15 * TILE_SIZE); |
0 | 527 |
y = v->y_pos; |
528 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
529 |
if ( (uint)x > MapMaxX() * TILE_SIZE - 1) return; |
0 | 530 |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
531 |
tile = TileVirtXY(x, y); |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
532 |
if (!IsTileType(tile, MP_INDUSTRY)) return; |
0 | 533 |
|
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3269
diff
changeset
|
534 |
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
|
535 |
v->dest_tile = ind; |
0 | 536 |
|
6390
802629b3c7f1
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6263
diff
changeset
|
537 |
if (GetIndustrySpec(GetIndustry(ind)->type)->behaviour & INDUSTRYBEH_CHOPPER_ATTACKS) { |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
538 |
v->current_order.SetDestination(1); |
0 | 539 |
v->age = 0; |
540 |
} |
|
541 |
} |
|
542 |
} |
|
543 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
544 |
/** 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
|
545 |
static void DisasterTick_Helicopter_Rotors(Vehicle *v) |
0 | 546 |
{ |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
547 |
v->tick_counter++; |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
548 |
if (HasBit(v->tick_counter, 0)) return; |
0 | 549 |
|
2535 | 550 |
if (++v->cur_image > SPR_ROTOR_MOVING_3) v->cur_image = SPR_ROTOR_MOVING_1; |
0 | 551 |
|
552 |
VehiclePositionChanged(v); |
|
8317
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8270
diff
changeset
|
553 |
MarkSingleVehicleDirty(v); |
0 | 554 |
} |
555 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
556 |
/** |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
557 |
* (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
|
558 |
* 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
|
559 |
* 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
|
560 |
* 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
|
561 |
*/ |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
562 |
static void DisasterTick_Big_Ufo(Vehicle *v) |
0 | 563 |
{ |
564 |
byte z; |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
565 |
Vehicle *u, *w; |
0 | 566 |
Town *t; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
567 |
TileIndex tile; |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
568 |
TileIndex tile_org; |
0 | 569 |
|
570 |
v->tick_counter++; |
|
571 |
||
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
572 |
if (v->current_order.GetDestination() == 1) { |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
573 |
int x = TileX(v->dest_tile) * TILE_SIZE + TILE_SIZE / 2; |
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
574 |
int y = TileY(v->dest_tile) * TILE_SIZE + TILE_SIZE / 2; |
7970
7d6b9ab57081
(svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13
parents:
7967
diff
changeset
|
575 |
if (Delta(v->x_pos, x) + Delta(v->y_pos, y) >= 8) { |
0 | 576 |
v->direction = GetDirectionTowards(v, x, y); |
577 |
||
6153 | 578 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
0 | 579 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
580 |
return; |
|
581 |
} |
|
582 |
||
583 |
z = GetSlopeZ(v->x_pos, v->y_pos); |
|
584 |
if (z < v->z_pos) { |
|
585 |
SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos - 1); |
|
586 |
return; |
|
587 |
} |
|
588 |
||
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
589 |
v->current_order.SetDestination(2); |
0 | 590 |
|
591 |
FOR_ALL_VEHICLES(u) { |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
592 |
if (u->type == VEH_TRAIN || u->type == VEH_ROAD) { |
7970
7d6b9ab57081
(svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13
parents:
7967
diff
changeset
|
593 |
if (Delta(u->x_pos, v->x_pos) + Delta(u->y_pos, v->y_pos) <= 12 * TILE_SIZE) { |
0 | 594 |
u->breakdown_ctr = 5; |
595 |
u->breakdown_delay = 0xF0; |
|
596 |
} |
|
597 |
} |
|
598 |
} |
|
599 |
||
600 |
t = ClosestTownFromTile(v->dest_tile, (uint)-1); |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
601 |
SetDParam(0, t->index); |
0 | 602 |
AddNewsItem(STR_B004_UFO_LANDS_NEAR, |
9234
bfc9d27d3d0d
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents:
9009
diff
changeset
|
603 |
NS_ACCIDENT_TILE, |
0 | 604 |
v->tile, |
605 |
0); |
|
606 |
||
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7334
diff
changeset
|
607 |
u = new DisasterVehicle(); |
0 | 608 |
if (u == NULL) { |
609 |
DeleteDisasterVeh(v); |
|
610 |
return; |
|
611 |
} |
|
612 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
613 |
InitializeDisasterVehicle(u, -6 * TILE_SIZE, v->y_pos, 135, DIR_SW, ST_Big_Ufo_Destroyer); |
7334
ed9a43cf642a
(svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents:
7317
diff
changeset
|
614 |
u->u.disaster.big_ufo_destroyer_target = v->index; |
0 | 615 |
|
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7334
diff
changeset
|
616 |
w = new DisasterVehicle(); |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
617 |
if (w == NULL) return; |
0 | 618 |
|
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
619 |
u->SetNext(w); |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
620 |
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
|
621 |
w->vehstatus |= VS_SHADOW; |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
622 |
} else if (v->current_order.GetDestination() == 0) { |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
623 |
int x = TileX(v->dest_tile) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
624 |
int y = TileY(v->dest_tile) * TILE_SIZE; |
7970
7d6b9ab57081
(svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13
parents:
7967
diff
changeset
|
625 |
if (Delta(x, v->x_pos) + Delta(y, v->y_pos) >= TILE_SIZE) { |
0 | 626 |
v->direction = GetDirectionTowards(v, x, y); |
6153 | 627 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
0 | 628 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
629 |
return; |
|
630 |
} |
|
631 |
||
632 |
if (++v->age < 6) { |
|
2051 | 633 |
v->dest_tile = RandomTile(); |
0 | 634 |
return; |
635 |
} |
|
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
636 |
v->current_order.SetDestination(1); |
0 | 637 |
|
2051 | 638 |
tile_org = tile = RandomTile(); |
0 | 639 |
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
|
640 |
if (IsTileType(tile, MP_RAILWAY) && |
3269
62fb247bf94b
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3161
diff
changeset
|
641 |
IsPlainRailTile(tile) && |
4845
72bbb6e2694e
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4559
diff
changeset
|
642 |
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
|
643 |
break; |
3269
62fb247bf94b
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3161
diff
changeset
|
644 |
} |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
645 |
tile = TILE_MASK(tile + 1); |
0 | 646 |
} while (tile != tile_org); |
647 |
v->dest_tile = tile; |
|
648 |
v->age = 0; |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
649 |
} else { |
0 | 650 |
return; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
651 |
} |
0 | 652 |
} |
653 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
654 |
/** |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
655 |
* 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
|
656 |
* 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
|
657 |
*/ |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
658 |
static void DisasterTick_Big_Ufo_Destroyer(Vehicle *v) |
0 | 659 |
{ |
660 |
Vehicle *u; |
|
661 |
int i; |
|
662 |
||
663 |
v->tick_counter++; |
|
664 |
||
6153 | 665 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
0 | 666 |
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); |
667 |
||
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
668 |
if (gp.x > (int)MapSizeX() * TILE_SIZE + 9 * TILE_SIZE - 1) { |
0 | 669 |
DeleteDisasterVeh(v); |
670 |
return; |
|
671 |
} |
|
672 |
||
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
673 |
if (v->current_order.GetDestination() == 0) { |
7334
ed9a43cf642a
(svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents:
7317
diff
changeset
|
674 |
u = GetVehicle(v->u.disaster.big_ufo_destroyer_target); |
7970
7d6b9ab57081
(svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13
parents:
7967
diff
changeset
|
675 |
if (Delta(v->x_pos, u->x_pos) > TILE_SIZE) return; |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8793
diff
changeset
|
676 |
v->current_order.SetDestination(1); |
0 | 677 |
|
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
|
678 |
CreateEffectVehicleRel(u, 0, 7, 8, EV_EXPLOSION_LARGE); |
541 | 679 |
SndPlayVehicleFx(SND_12_EXPLOSION, u); |
0 | 680 |
|
681 |
DeleteDisasterVeh(u); |
|
682 |
||
2952 | 683 |
for (i = 0; i != 80; i++) { |
0 | 684 |
uint32 r = Random(); |
685 |
CreateEffectVehicleAbove( |
|
2140
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
|
686 |
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
|
687 |
GB(r, 5, 6) + v->y_pos - 32, |
0 | 688 |
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
|
689 |
EV_EXPLOSION_SMALL); |
0 | 690 |
} |
691 |
||
1981 | 692 |
BEGIN_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3)) |
0 | 693 |
tile = TILE_MASK(tile); |
694 |
DisasterClearSquare(tile); |
|
1981 | 695 |
END_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3)) |
0 | 696 |
} |
697 |
} |
|
698 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
699 |
/** |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
700 |
* 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
|
701 |
* 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
|
702 |
*/ |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
703 |
static void DisasterTick_Submarine(Vehicle *v) |
0 | 704 |
{ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
705 |
TileIndex tile; |
0 | 706 |
|
707 |
v->tick_counter++; |
|
708 |
||
709 |
if (++v->age > 8880) { |
|
710 |
VehiclePositionChanged(v); |
|
8317
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8270
diff
changeset
|
711 |
MarkSingleVehicleDirty(v); |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7334
diff
changeset
|
712 |
delete v; |
0 | 713 |
return; |
714 |
} |
|
715 |
||
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
716 |
if (!HasBit(v->tick_counter, 0)) return; |
0 | 717 |
|
4559
aa0c13e39840
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
718 |
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
|
719 |
if (IsValidTile(tile)) { |
8616
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8467
diff
changeset
|
720 |
TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0)); |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8467
diff
changeset
|
721 |
if (trackbits == TRACK_BIT_ALL && !Chance16(1, 90)) { |
6153 | 722 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
723 |
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
|
724 |
return; |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
725 |
} |
0 | 726 |
} |
727 |
||
3160 | 728 |
v->direction = ChangeDir(v->direction, GB(Random(), 0, 1) ? DIRDIFF_90RIGHT : DIRDIFF_90LEFT); |
0 | 729 |
} |
730 |
||
731 |
||
732 |
static void DisasterTick_NULL(Vehicle *v) {} |
|
733 |
typedef void DisasterVehicleTickProc(Vehicle *v); |
|
734 |
||
735 |
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
|
736 |
DisasterTick_Zeppeliner, DisasterTick_NULL, |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
737 |
DisasterTick_Ufo, DisasterTick_NULL, |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
738 |
DisasterTick_Airplane, DisasterTick_NULL, |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
739 |
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
|
740 |
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
|
741 |
DisasterTick_NULL, |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
742 |
DisasterTick_Submarine, |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
743 |
DisasterTick_Submarine, |
0 | 744 |
}; |
745 |
||
746 |
||
7135
3c1bcca0d6bb
(svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium
parents:
6683
diff
changeset
|
747 |
void DisasterVehicle::Tick() |
0 | 748 |
{ |
7135
3c1bcca0d6bb
(svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium
parents:
6683
diff
changeset
|
749 |
_disastervehicle_tick_procs[this->subtype](this); |
0 | 750 |
} |
751 |
||
6247 | 752 |
typedef void DisasterInitProc(); |
0 | 753 |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
754 |
|
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
755 |
/** 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
|
756 |
* otherwise crashes on a random tile */ |
6247 | 757 |
static void Disaster_Zeppeliner_Init() |
0 | 758 |
{ |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7334
diff
changeset
|
759 |
Vehicle *v = new DisasterVehicle(), *u; |
0 | 760 |
Station *st; |
761 |
int x; |
|
762 |
||
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
763 |
if (v == NULL) return; |
0 | 764 |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
765 |
/* 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
|
766 |
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
|
767 |
|
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
768 |
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
|
769 |
if (st->airport_tile != 0 && |
0 | 770 |
st->airport_type <= 1 && |
4845
72bbb6e2694e
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4559
diff
changeset
|
771 |
IsHumanPlayer(st->owner)) { |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
772 |
x = (TileX(st->xy) + 2) * TILE_SIZE; |
0 | 773 |
break; |
774 |
} |
|
775 |
} |
|
776 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
777 |
InitializeDisasterVehicle(v, x, 0, 135, DIR_SE, ST_Zeppeliner); |
0 | 778 |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
779 |
/* Allocate shadow too? */ |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7334
diff
changeset
|
780 |
u = new DisasterVehicle(); |
0 | 781 |
if (u != NULL) { |
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
782 |
v->SetNext(u); |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
783 |
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
|
784 |
u->vehstatus |= VS_SHADOW; |
0 | 785 |
} |
786 |
} |
|
787 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
788 |
|
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
789 |
/** 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
|
790 |
* until it locates a road vehicle which it targets and then destroys */ |
6247 | 791 |
static void Disaster_Small_Ufo_Init() |
0 | 792 |
{ |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7334
diff
changeset
|
793 |
Vehicle *v = new DisasterVehicle(), *u; |
0 | 794 |
int x; |
795 |
||
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
796 |
if (v == NULL) return; |
0 | 797 |
|
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
798 |
x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2; |
0 | 799 |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
800 |
InitializeDisasterVehicle(v, x, 0, 135, DIR_SE, ST_Small_Ufo); |
1981 | 801 |
v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2); |
0 | 802 |
v->age = 0; |
803 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
804 |
/* Allocate shadow too? */ |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7334
diff
changeset
|
805 |
u = new DisasterVehicle(); |
0 | 806 |
if (u != NULL) { |
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
807 |
v->SetNext(u); |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
808 |
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
|
809 |
u->vehstatus |= VS_SHADOW; |
0 | 810 |
} |
811 |
} |
|
812 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
813 |
|
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
814 |
/* Combat airplane which destroys an oil refinery */ |
6247 | 815 |
static void Disaster_Airplane_Init() |
0 | 816 |
{ |
817 |
Industry *i, *found; |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
818 |
Vehicle *v, *u; |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
819 |
int x, y; |
0 | 820 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
821 |
found = NULL; |
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
822 |
|
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
823 |
FOR_ALL_INDUSTRIES(i) { |
6390
802629b3c7f1
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6263
diff
changeset
|
824 |
if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_AIRPLANE_ATTACKS) && |
7967
a230c063a672
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
7928
diff
changeset
|
825 |
(found == NULL || Chance16(1, 2))) { |
0 | 826 |
found = i; |
827 |
} |
|
828 |
} |
|
829 |
||
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
830 |
if (found == NULL) return; |
0 | 831 |
|
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7334
diff
changeset
|
832 |
v = new DisasterVehicle(); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
833 |
if (v == NULL) return; |
0 | 834 |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
835 |
/* 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
|
836 |
x = (MapSizeX() + 9) * TILE_SIZE - 1; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
837 |
y = TileY(found->xy) * TILE_SIZE + 37; |
0 | 838 |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
839 |
InitializeDisasterVehicle(v, x, y, 135, DIR_NE, ST_Airplane); |
0 | 840 |
|
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7334
diff
changeset
|
841 |
u = new DisasterVehicle(); |
0 | 842 |
if (u != NULL) { |
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
843 |
v->SetNext(u); |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
844 |
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
|
845 |
u->vehstatus |= VS_SHADOW; |
0 | 846 |
} |
847 |
} |
|
848 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
849 |
|
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
850 |
/** Combat helicopter that destroys a factory */ |
6247 | 851 |
static void Disaster_Helicopter_Init() |
0 | 852 |
{ |
853 |
Industry *i, *found; |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
854 |
Vehicle *v, *u, *w; |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
855 |
int x, y; |
0 | 856 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
857 |
found = NULL; |
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
858 |
|
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
859 |
FOR_ALL_INDUSTRIES(i) { |
6390
802629b3c7f1
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6263
diff
changeset
|
860 |
if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CHOPPER_ATTACKS) && |
7967
a230c063a672
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
7928
diff
changeset
|
861 |
(found == NULL || Chance16(1, 2))) { |
0 | 862 |
found = i; |
863 |
} |
|
864 |
} |
|
865 |
||
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
866 |
if (found == NULL) return; |
0 | 867 |
|
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7334
diff
changeset
|
868 |
v = new DisasterVehicle(); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
869 |
if (v == NULL) return; |
0 | 870 |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
871 |
x = -16 * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
872 |
y = TileY(found->xy) * TILE_SIZE + 37; |
0 | 873 |
|
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
874 |
InitializeDisasterVehicle(v, x, y, 135, DIR_SW, ST_Helicopter); |
0 | 875 |
|
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7334
diff
changeset
|
876 |
u = new DisasterVehicle(); |
0 | 877 |
if (u != NULL) { |
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
878 |
v->SetNext(u); |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
879 |
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
|
880 |
u->vehstatus |= VS_SHADOW; |
0 | 881 |
|
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7334
diff
changeset
|
882 |
w = new DisasterVehicle(); |
0 | 883 |
if (w != NULL) { |
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
884 |
u->SetNext(w); |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
885 |
InitializeDisasterVehicle(w, x, y, 140, DIR_SW, ST_Helicopter_Rotors); |
0 | 886 |
} |
887 |
} |
|
888 |
} |
|
889 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
890 |
|
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
891 |
/* 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
|
892 |
* down by a combat airplane, destroying the surroundings */ |
6247 | 893 |
static void Disaster_Big_Ufo_Init() |
0 | 894 |
{ |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7334
diff
changeset
|
895 |
Vehicle *v = new DisasterVehicle(), *u; |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
896 |
int x, y; |
0 | 897 |
|
2639 | 898 |
if (v == NULL) return; |
0 | 899 |
|
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
900 |
x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2; |
0 | 901 |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
902 |
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
|
903 |
InitializeDisasterVehicle(v, x, y, 135, DIR_NW, ST_Big_Ufo); |
1981 | 904 |
v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2); |
0 | 905 |
v->age = 0; |
906 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
907 |
/* Allocate shadow too? */ |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7334
diff
changeset
|
908 |
u = new DisasterVehicle(); |
0 | 909 |
if (u != NULL) { |
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
910 |
v->SetNext(u); |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
911 |
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
|
912 |
u->vehstatus |= VS_SHADOW; |
0 | 913 |
} |
914 |
} |
|
915 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
916 |
|
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
917 |
/* Curious submarine #1, just floats around */ |
6247 | 918 |
static void Disaster_Small_Submarine_Init() |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
919 |
{ |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7334
diff
changeset
|
920 |
Vehicle *v = new DisasterVehicle(); |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
921 |
int x, y; |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
922 |
Direction dir; |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
923 |
uint32 r; |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
924 |
|
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
925 |
if (v == NULL) return; |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
926 |
|
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
927 |
r = Random(); |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
928 |
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
|
929 |
|
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
930 |
if (HasBit(r, 31)) { |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
931 |
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
|
932 |
dir = DIR_NW; |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
933 |
} else { |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
934 |
y = TILE_SIZE / 2; |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
935 |
dir = DIR_SE; |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
936 |
} |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
937 |
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
|
938 |
v->age = 0; |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
939 |
} |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
940 |
|
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
941 |
|
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
942 |
/* Curious submarine #2, just floats around */ |
6247 | 943 |
static void Disaster_Big_Submarine_Init() |
0 | 944 |
{ |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7334
diff
changeset
|
945 |
Vehicle *v = new DisasterVehicle(); |
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6453
diff
changeset
|
946 |
int x, y; |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
947 |
Direction dir; |
0 | 948 |
uint32 r; |
949 |
||
2639 | 950 |
if (v == NULL) return; |
0 | 951 |
|
952 |
r = Random(); |
|
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
953 |
x = TileX(r) * TILE_SIZE + TILE_SIZE / 2; |
0 | 954 |
|
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
955 |
if (HasBit(r, 31)) { |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
956 |
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
|
957 |
dir = DIR_NW; |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
958 |
} else { |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3495
diff
changeset
|
959 |
y = TILE_SIZE / 2; |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
960 |
dir = DIR_SE; |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
2989
diff
changeset
|
961 |
} |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
962 |
InitializeDisasterVehicle(v, x, y, 0, dir, ST_Big_Submarine); |
0 | 963 |
v->age = 0; |
964 |
} |
|
965 |
||
966 |
||
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
967 |
/** 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
|
968 |
* land in a certain direction */ |
6247 | 969 |
static void Disaster_CoalMine_Init() |
0 | 970 |
{ |
2642 | 971 |
int index = GB(Random(), 0, 4); |
2648
677ba48b2549
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
972 |
uint m; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
973 |
|
2648
677ba48b2549
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
974 |
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
|
975 |
const Industry *i; |
2989 | 976 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
977 |
FOR_ALL_INDUSTRIES(i) { |
6390
802629b3c7f1
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6263
diff
changeset
|
978 |
if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CAN_SUBSIDENCE) && --index < 0) { |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
979 |
SetDParam(0, i->town->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
980 |
AddNewsItem(STR_B005_COAL_MINE_SUBSIDENCE_LEAVES, |
9234
bfc9d27d3d0d
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents:
9009
diff
changeset
|
981 |
NS_ACCIDENT_TILE, i->xy + TileDiffXY(1, 1), 0); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
982 |
|
0 | 983 |
{ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
984 |
TileIndex tile = i->xy; |
7317
e61af9d8a2b3
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7266
diff
changeset
|
985 |
TileIndexDiff step = TileOffsByDiagDir((DiagDirection)GB(Random(), 0, 2)); |
2648
677ba48b2549
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
986 |
uint n; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
987 |
|
2674
8585b4842df6
(svn r3216) - Fix (regression): endless loop introduced in revision 3190
Darkvater
parents:
2668
diff
changeset
|
988 |
for (n = 0; n < 30; n++) { |
0 | 989 |
DisasterClearSquare(tile); |
990 |
tile = TILE_MASK(tile + step); |
|
2648
677ba48b2549
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
991 |
} |
0 | 992 |
} |
993 |
return; |
|
994 |
} |
|
995 |
} |
|
2648
677ba48b2549
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2642
diff
changeset
|
996 |
} |
0 | 997 |
} |
998 |
||
999 |
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
|
1000 |
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
|
1001 |
Disaster_Small_Ufo_Init, |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
1002 |
Disaster_Airplane_Init, |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
1003 |
Disaster_Helicopter_Init, |
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
1004 |
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
|
1005 |
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
|
1006 |
Disaster_Big_Submarine_Init, |
5695
b7c7871ed66d
(svn r8159) -Cleanup: Sprinkle some coding-style and comments on the disaster code.
Darkvater
parents:
5694
diff
changeset
|
1007 |
Disaster_CoalMine_Init, |
0 | 1008 |
}; |
1009 |
||
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
|
1010 |
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
|
1011 |
Year min; |
4b7006c1b5eb
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4286
diff
changeset
|
1012 |
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
|
1013 |
} _dis_years[] = { |
6125
a6fff965707c
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1014 |
{ 1930, 1955 }, ///< zeppeliner |
a6fff965707c
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1015 |
{ 1940, 1970 }, ///< ufo (small) |
a6fff965707c
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1016 |
{ 1960, 1990 }, ///< airplane |
a6fff965707c
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1017 |
{ 1970, 2000 }, ///< helicopter |
a6fff965707c
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1018 |
{ 2000, 2100 }, ///< ufo (big) |
a6fff965707c
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1019 |
{ 1940, 1965 }, ///< submarine (small) |
a6fff965707c
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1020 |
{ 1975, 2010 }, ///< submarine (big) |
a6fff965707c
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1021 |
{ 1950, 1985 } ///< coalmine |
0 | 1022 |
}; |
1023 |
||
1024 |
||
6247 | 1025 |
static void DoDisaster() |
0 | 1026 |
{ |
2639 | 1027 |
byte buf[lengthof(_dis_years)]; |
1028 |
uint i; |
|
1029 |
uint j; |
|
0 | 1030 |
|
2639 | 1031 |
j = 0; |
1032 |
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
|
1033 |
if (_cur_year >= _dis_years[i].min && _cur_year < _dis_years[i].max) buf[j++] = i; |
0 | 1034 |
} |
1035 |
||
2639 | 1036 |
if (j == 0) return; |
0 | 1037 |
|
2637
722dae65c4a8
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2635
diff
changeset
|
1038 |
_disaster_initprocs[buf[RandomRange(j)]](); |
0 | 1039 |
} |
1040 |
||
1041 |
||
6247 | 1042 |
static void ResetDisasterDelay() |
0 | 1043 |
{ |
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
|
1044 |
_disaster_delay = GB(Random(), 0, 9) + 730; |
0 | 1045 |
} |
1046 |
||
6247 | 1047 |
void DisasterDailyLoop() |
0 | 1048 |
{ |
2639 | 1049 |
if (--_disaster_delay != 0) return; |
0 | 1050 |
|
1051 |
ResetDisasterDelay(); |
|
1052 |
||
2639 | 1053 |
if (_opt.diff.disasters != 0) DoDisaster(); |
0 | 1054 |
} |
1055 |
||
6247 | 1056 |
void StartupDisasters() |
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
|
1057 |
{ |
0 | 1058 |
ResetDisasterDelay(); |
1059 |
} |
|
6558
c88e142f896e
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents:
6552
diff
changeset
|
1060 |
|
c88e142f896e
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents:
6552
diff
changeset
|
1061 |
void DisasterVehicle::UpdateDeltaXY(Direction direction) |
c88e142f896e
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents:
6552
diff
changeset
|
1062 |
{ |
c88e142f896e
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents:
6552
diff
changeset
|
1063 |
this->x_offs = -1; |
c88e142f896e
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents:
6552
diff
changeset
|
1064 |
this->y_offs = -1; |
8793
5e35232593c3
(svn r12531) -Codechange: Rename some variables for consistency.
frosch
parents:
8785
diff
changeset
|
1065 |
this->x_extent = 2; |
5e35232593c3
(svn r12531) -Codechange: Rename some variables for consistency.
frosch
parents:
8785
diff
changeset
|
1066 |
this->y_extent = 2; |
5e35232593c3
(svn r12531) -Codechange: Rename some variables for consistency.
frosch
parents:
8785
diff
changeset
|
1067 |
this->z_extent = 5; |
6558
c88e142f896e
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents:
6552
diff
changeset
|
1068 |
} |