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