src/aircraft_cmd.cpp
author convert-repo
Mon, 07 Apr 2008 16:21:55 +0000
changeset 10076 dfd70e42c4ae
parent 9339 daaa2adbaf99
child 10079 99aba130db3c
permissions -rw-r--r--
update tags
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: 6426
diff changeset
     3
/** @file aircraft_cmd.cpp
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: 6426
diff changeset
     4
 * This file deals with aircraft and airport movements functionalities */
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: 6426
diff changeset
     5
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1877
diff changeset
     7
#include "openttd.h"
3963
d7d284c2f1f7 (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents: 3955
diff changeset
     8
#include "aircraft.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1282
diff changeset
     9
#include "debug.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: 6911
diff changeset
    10
#include "landscape.h"
3315
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3186
diff changeset
    11
#include "station_map.h"
7476
7f086e4b2a76 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 7449
diff changeset
    12
#include "timetable.h"
1790
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1786
diff changeset
    13
#include "depot.h"
9259
088d3649dd4f (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 9173
diff changeset
    14
#include "news_func.h"
6105
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
    15
#include "aircraft.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "airport.h"
1752
cdbfb2f23e72 (svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents: 1614
diff changeset
    17
#include "vehicle_gui.h"
2962
dbd168a4703a (svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents: 2952
diff changeset
    18
#include "newgrf_engine.h"
3973
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
    19
#include "newgrf_callbacks.h"
4244
44dcec623504 (svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents: 4242
diff changeset
    20
#include "newgrf_text.h"
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4574
diff changeset
    21
#include "newgrf_sound.h"
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
    22
#include "spritecache.h"
6666
88f1598fafb3 (svn r9352) -Codechange: Use cargo class to determine if an aircraft should carry mail
peter1138
parents: 6660
diff changeset
    23
#include "cargotype.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8604
diff changeset
    24
#include "strings_func.h"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8610
diff changeset
    25
#include "command_func.h"
8627
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8612
diff changeset
    26
#include "window_func.h"
8636
2b158acb649c (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8635
diff changeset
    27
#include "date_func.h"
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8636
diff changeset
    28
#include "vehicle_func.h"
8653
a83f7a536919 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8641
diff changeset
    29
#include "sound_func.h"
8627
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8612
diff changeset
    30
#include "functions.h"
8707
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8653
diff changeset
    31
#include "variables.h"
8708
0c29fbc79be4 (svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium
parents: 8707
diff changeset
    32
#include "autoreplace_func.h"
0c29fbc79be4 (svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium
parents: 8707
diff changeset
    33
#include "autoreplace_gui.h"
8720
4e60c30e2006 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8708
diff changeset
    34
#include "gfx_func.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8726
diff changeset
    35
#include "player_func.h"
8766
c86cfa3a7580 (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8760
diff changeset
    36
#include "settings_type.h"
9280
9c03416d26b1 (svn r12488) -Codechange: split order.h into order_base.h and order_func.h.
rubidium
parents: 9274
diff changeset
    37
#include "order_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    39
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    40
#include "table/sprites.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    41
7054
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    42
void Aircraft::UpdateDeltaXY(Direction direction)
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    43
{
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    44
	uint32 x;
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    45
#define MKIT(a, b, c, d) ((a & 0xFF) << 24) | ((b & 0xFF) << 16) | ((c & 0xFF) << 8) | ((d & 0xFF) << 0)
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    46
	switch (this->subtype) {
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    47
		default: NOT_REACHED();
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    48
		case AIR_AIRCRAFT:
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    49
		case AIR_HELICOPTER:
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    50
			switch (this->u.air.state) {
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    51
				case ENDTAKEOFF:
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    52
				case LANDING:
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    53
				case HELILANDING:
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    54
				case FLYING:     x = MKIT(24, 24, -1, -1); break;
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    55
				default:         x = MKIT( 2,  2, -1, -1); break;
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    56
			}
9289
92f1249c304e (svn r12531) -Codechange: Rename some variables for consistency.
frosch
parents: 9282
diff changeset
    57
			this->z_extent = 5;
7054
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    58
			break;
9289
92f1249c304e (svn r12531) -Codechange: Rename some variables for consistency.
frosch
parents: 9282
diff changeset
    59
		case AIR_SHADOW:     this->z_extent = 1; x = MKIT(2,  2,  0,  0); break;
92f1249c304e (svn r12531) -Codechange: Rename some variables for consistency.
frosch
parents: 9282
diff changeset
    60
		case AIR_ROTOR:      this->z_extent = 1; x = MKIT(2,  2, -1, -1); break;
7054
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    61
	}
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    62
#undef MKIT
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    63
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    64
	this->x_offs        = GB(x,  0, 8);
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    65
	this->y_offs        = GB(x,  8, 8);
9289
92f1249c304e (svn r12531) -Codechange: Rename some variables for consistency.
frosch
parents: 9282
diff changeset
    66
	this->x_extent      = GB(x, 16, 8);
92f1249c304e (svn r12531) -Codechange: Rename some variables for consistency.
frosch
parents: 9282
diff changeset
    67
	this->y_extent      = GB(x, 24, 8);
7054
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    68
}
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    69
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
    70
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
    71
/** this maps the terminal to its corresponding state and block flag
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
    72
 *  currently set for 10 terms, 4 helipads */
6005
cf29375327f9 (svn r8305) -Codechange: defining 'static const' in a header is a bit weird.
truelight
parents: 5919
diff changeset
    73
static const byte _airport_terminal_state[] = {2, 3, 4, 5, 6, 7, 19, 20, 0, 0, 8, 9, 21, 22};
cf29375327f9 (svn r8305) -Codechange: defining 'static const' in a header is a bit weird.
truelight
parents: 5919
diff changeset
    74
static const byte _airport_terminal_flag[] =  {0, 1, 2, 3, 4, 5, 22, 23, 0, 0, 6, 7, 24, 25};
cf29375327f9 (svn r8305) -Codechange: defining 'static const' in a header is a bit weird.
truelight
parents: 5919
diff changeset
    75
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
    76
static bool AirportMove(Vehicle *v, const AirportFTAClass *apc);
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
    77
static bool AirportSetBlocks(Vehicle *v, const AirportFTA *current_pos, const AirportFTAClass *apc);
4843
724322df355a (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
    78
static bool AirportHasBlock(Vehicle *v, const AirportFTA *current_pos, const AirportFTAClass *apc);
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
    79
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *apc);
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
    80
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *apc);
899
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
    81
static void CrashAirplane(Vehicle *v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
static void AircraftNextAirportPos_and_Order(Vehicle *v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
static byte GetAircraftFlyingAltitude(const Vehicle *v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
static const SpriteID _aircraft_sprite[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
	0x0EB5, 0x0EBD, 0x0EC5, 0x0ECD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
	0x0ED5, 0x0EDD, 0x0E9D, 0x0EA5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
	0x0EAD, 0x0EE5, 0x0F05, 0x0F0D,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
	0x0F15, 0x0F1D, 0x0F25, 0x0F2D,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
	0x0EED, 0x0EF5, 0x0EFD, 0x0F35,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
	0x0E9D, 0x0EA5, 0x0EAD, 0x0EB5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
	0x0EBD, 0x0EC5
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
    96
/** Helicopter rotor animation states */
3710
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
    97
enum HelicopterRotorStates {
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
    98
	HRS_ROTOR_STOPPED,
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
    99
	HRS_ROTOR_MOVING_1,
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   100
	HRS_ROTOR_MOVING_2,
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   101
	HRS_ROTOR_MOVING_3,
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   102
};
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   103
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   104
/** Find the nearest hangar to v
1532
83719caec8d1 (svn r2036) Fix FindNearestHanger(), it never worked correctly because 0xFFFF != 65000 and a 16bit number has no 17th bit
tron
parents: 1530
diff changeset
   105
 * INVALID_STATION is returned, if the player does not have any suitable
83719caec8d1 (svn r2036) Fix FindNearestHanger(), it never worked correctly because 0xFFFF != 65000 and a 16bit number has no 17th bit
tron
parents: 1530
diff changeset
   106
 * airports (like helipads only)
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   107
 * @param v vehicle looking for a hangar
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   108
 * @return the StationID if one is found, otherwise, INVALID_STATION
1532
83719caec8d1 (svn r2036) Fix FindNearestHanger(), it never worked correctly because 0xFFFF != 65000 and a 16bit number has no 17th bit
tron
parents: 1530
diff changeset
   109
 */
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   110
static StationID FindNearestHangar(const Vehicle *v)
1194
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   111
{
1532
83719caec8d1 (svn r2036) Fix FindNearestHanger(), it never worked correctly because 0xFFFF != 65000 and a 16bit number has no 17th bit
tron
parents: 1530
diff changeset
   112
	const Station *st;
83719caec8d1 (svn r2036) Fix FindNearestHanger(), it never worked correctly because 0xFFFF != 65000 and a 16bit number has no 17th bit
tron
parents: 1530
diff changeset
   113
	uint best = 0;
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   114
	StationID index = INVALID_STATION;
4284
adbca0e65aaa (svn r5914) -Fix [FS#235]: Bugfix for errors in FindNearestHangar function in aircraft_cmd.c (mart3p).
Darkvater
parents: 4261
diff changeset
   115
	TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos);
1194
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   116
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   117
	FOR_ALL_STATIONS(st) {
6351
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
   118
		if (st->owner != v->owner || !(st->facilities & FACIL_AIRPORT)) continue;
1204
94bc5d4587c1 (svn r1708) - Fix: FindNearestHangar() will no longer return a hangar where a jet will crash if it is a jet, that is searching
bjarni
parents: 1200
diff changeset
   119
6358
e7997742bf02 (svn r8755) -Fix
tron
parents: 6353
diff changeset
   120
		const AirportFTAClass *afc = st->Airport();
6351
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
   121
		if (afc->nof_depots == 0 || (
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
   122
					/* don't crash the plane if we know it can't land at the airport */
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
   123
					afc->flags & AirportFTAClass::SHORT_STRIP &&
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
   124
					AircraftVehInfo(v->engine_type)->subtype & AIR_FAST &&
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
   125
					!_cheats.no_jetcrash.value
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
   126
				)) {
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
   127
			continue;
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
   128
		}
1532
83719caec8d1 (svn r2036) Fix FindNearestHanger(), it never worked correctly because 0xFFFF != 65000 and a 16bit number has no 17th bit
tron
parents: 1530
diff changeset
   129
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   130
		/* v->tile can't be used here, when aircraft is flying v->tile is set to 0 */
6351
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
   131
		uint distance = DistanceSquare(vtile, st->airport_tile);
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
   132
		if (distance < best || index == INVALID_STATION) {
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
   133
			best = distance;
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
   134
			index = st->index;
1194
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   135
		}
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   136
	}
1532
83719caec8d1 (svn r2036) Fix FindNearestHanger(), it never worked correctly because 0xFFFF != 65000 and a 16bit number has no 17th bit
tron
parents: 1530
diff changeset
   137
	return index;
1194
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   138
}
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   139
1614
4ee38e74afd1 (svn r2118) - Fix: Fix compilation with network disabled, and comment out some of the warnings (unused function)
Darkvater
parents: 1533
diff changeset
   140
#if 0
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   141
/** Check if given vehicle has a goto hangar in his orders
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   142
 * @param v vehicle to inquiry
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   143
 * @return true if vehicle v has an airport in the schedule, that has a hangar */
1194
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   144
static bool HaveHangarInOrderList(Vehicle *v)
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   145
{
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   146
	const Order *order;
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   147
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   148
	FOR_VEHICLE_ORDERS(v, order) {
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   149
		const Station *st = GetStation(order->station);
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   150
		if (st->owner == v->owner && st->facilities & FACIL_AIRPORT) {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   151
			/* If an airport doesn't have a hangar, skip it */
6358
e7997742bf02 (svn r8755) -Fix
tron
parents: 6353
diff changeset
   152
			if (st->Airport()->nof_depots != 0)
1194
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   153
				return true;
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   154
		}
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   155
	}
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   156
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   157
	return false;
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   158
}
1614
4ee38e74afd1 (svn r2118) - Fix: Fix compilation with network disabled, and comment out some of the warnings (unused function)
Darkvater
parents: 1533
diff changeset
   159
#endif
1194
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   160
7630
2cd754d7dfa4 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 7592
diff changeset
   161
int Aircraft::GetImage(Direction direction) const
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
{
7630
2cd754d7dfa4 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 7592
diff changeset
   163
	int spritenum = this->spritenum;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
	if (is_custom_sprite(spritenum)) {
7630
2cd754d7dfa4 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 7592
diff changeset
   166
		int sprite = GetCustomVehicleSprite(this, direction);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2962
diff changeset
   168
		if (sprite != 0) return sprite;
8722
30cffd0c4e40 (svn r11789) -Codechange: coding style for global variable names
peter1138
parents: 8720
diff changeset
   169
		spritenum = _orig_aircraft_vehicle_info[this->engine_type - AIRCRAFT_ENGINES_INDEX].image_index;
0
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
	return direction + _aircraft_sprite[spritenum];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
3710
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   174
SpriteID GetRotorImage(const Vehicle *v)
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   175
{
6105
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
   176
	assert(v->subtype == AIR_HELICOPTER);
3710
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   177
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: 7986
diff changeset
   178
	const Vehicle *w = v->Next()->Next();
3710
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   179
	if (is_custom_sprite(v->spritenum)) {
4056
30ceffc75059 (svn r5336) - NewGRF: draw custom helicopter rotor sprites in vehicle info window, ensuring the correct direction is used (inspiration from mart3p)
peter1138
parents: 4023
diff changeset
   180
		SpriteID spritenum = GetCustomRotorSprite(v, false);
3710
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   181
		if (spritenum != 0) return spritenum;
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   182
	}
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   183
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   184
	/* Return standard rotor sprites if there are no custom sprites for this helicopter */
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   185
	return SPR_ROTOR_STOPPED + w->u.air.state;
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   186
}
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   187
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5902
diff changeset
   188
void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
{
4023
b65af90447d2 (svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
tron
parents: 3988
diff changeset
   190
	const AircraftVehicleInfo* avi = AircraftVehInfo(engine);
b65af90447d2 (svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
tron
parents: 3988
diff changeset
   191
	int spritenum = avi->image_index;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5902
diff changeset
   192
	SpriteID sprite = (6 + _aircraft_sprite[spritenum]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 337
diff changeset
   194
	if (is_custom_sprite(spritenum)) {
3186
5798593c2d95 (svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents: 3183
diff changeset
   195
		sprite = GetCustomVehicleIcon(engine, DIR_W);
5012
dc660b2bf438 (svn r7032) - Fix (r1704): Sprite index wasn't updated with correct image number if
peter1138
parents: 4991
diff changeset
   196
		if (sprite == 0) {
8722
30cffd0c4e40 (svn r11789) -Codechange: coding style for global variable names
peter1138
parents: 8720
diff changeset
   197
			spritenum = _orig_aircraft_vehicle_info[engine - AIRCRAFT_ENGINES_INDEX].image_index;
5012
dc660b2bf438 (svn r7032) - Fix (r1704): Sprite index wasn't updated with correct image number if
peter1138
parents: 4991
diff changeset
   198
			sprite = (6 + _aircraft_sprite[spritenum]);
dc660b2bf438 (svn r7032) - Fix (r1704): Sprite index wasn't updated with correct image number if
peter1138
parents: 4991
diff changeset
   199
		}
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 337
diff changeset
   200
	}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 337
diff changeset
   201
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5902
diff changeset
   202
	DrawSprite(sprite, pal, x, y);
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 337
diff changeset
   203
4023
b65af90447d2 (svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
tron
parents: 3988
diff changeset
   204
	if (!(avi->subtype & AIR_CTOL)) {
3710
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   205
		SpriteID rotor_sprite = GetCustomRotorIcon(engine);
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   206
		if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5902
diff changeset
   207
		DrawSprite(rotor_sprite, PAL_NONE, x, y - 5);
1200
a2036275549e (svn r1704) - Fix: [newgrf] rotors of custom helicopters are displayed correctly in the hangar window
dominik
parents: 1197
diff changeset
   208
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   211
/** Get the size of the sprite of an aircraft sprite heading west (used for lists)
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   212
 * @param engine The engine to get the sprite from
6905
c0a93961678a (svn r9545) -Documentation: Some corrections to previous doxygen work
belugas
parents: 6903
diff changeset
   213
 * @param width The width of the sprite
c0a93961678a (svn r9545) -Documentation: Some corrections to previous doxygen work
belugas
parents: 6903
diff changeset
   214
 * @param height The height of the sprite
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   215
 */
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   216
void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height)
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   217
{
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   218
	const AircraftVehicleInfo* avi = AircraftVehInfo(engine);
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   219
	int spritenum = avi->image_index;
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   220
	SpriteID sprite = (6 + _aircraft_sprite[spritenum]);
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   221
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   222
	if (is_custom_sprite(spritenum)) {
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   223
		sprite = GetCustomVehicleIcon(engine, DIR_W);
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   224
		if (sprite == 0) {
8722
30cffd0c4e40 (svn r11789) -Codechange: coding style for global variable names
peter1138
parents: 8720
diff changeset
   225
			spritenum = _orig_aircraft_vehicle_info[engine - AIRCRAFT_ENGINES_INDEX].image_index;
6223
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   226
			sprite = (6 + _aircraft_sprite[spritenum]);
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   227
		}
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   228
	}
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   229
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   230
	const Sprite *spr = GetSprite(sprite);
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   231
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   232
	width  = spr->width ;
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   233
	height = spr->height;
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   234
}
92d2073c3d7e (svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents: 6203
diff changeset
   235
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7139
diff changeset
   236
static CommandCost EstimateAircraftCost(EngineID engine, const AircraftVehicleInfo *avi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
{
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8722
diff changeset
   238
	return CommandCost(EXPENSES_NEW_VEHICLES, GetEngineProperty(engine, 0x0B, avi->base_cost) * (_price.aircraft_base >> 3) >> 5);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
3973
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   242
/**
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   243
 * Calculates cargo capacity based on an aircraft's passenger
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   244
 * and mail capacities.
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   245
 * @param cid Which cargo type to calculate a capacity for.
6905
c0a93961678a (svn r9545) -Documentation: Some corrections to previous doxygen work
belugas
parents: 6903
diff changeset
   246
 * @param avi Which engine to find a cargo capacity for.
3973
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   247
 * @return New cargo capacity value.
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   248
 */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   249
uint16 AircraftDefaultCargoCapacity(CargoID cid, const AircraftVehicleInfo *avi)
3973
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   250
{
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   251
	assert(cid != CT_INVALID);
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   252
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   253
	/* An aircraft can carry twice as much goods as normal cargo,
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   254
	 * and four times as many passengers. */
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   255
	switch (cid) {
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   256
		case CT_PASSENGERS:
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   257
			return avi->passenger_capacity;
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   258
		case CT_MAIL:
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   259
			return avi->passenger_capacity + avi->mail_capacity;
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   260
		case CT_GOODS:
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   261
			return (avi->passenger_capacity + avi->mail_capacity) / 2;
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   262
		default:
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   263
			return (avi->passenger_capacity + avi->mail_capacity) / 4;
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   264
	}
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   265
}
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   266
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   267
/** Build an aircraft.
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
   268
 * @param tile tile of depot where aircraft is built
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   269
 * @param flags for command
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   270
 * @param p1 aircraft type being built (engine)
3816
2cdb29b57c1f (svn r4826) -Fix: [autoreplace] fixed possible problem when autoreplacing and was number of vehicles (of a type, not total) was reached
bjarni
parents: 3722
diff changeset
   271
 * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   272
 * return result of operation.  Could be cost, error
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   273
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7139
diff changeset
   274
CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
{
6903
0b3d43bd1fdb (svn r9543) -Fix [FS#691]: Split up STR_ENGINE_NOT_BUILDABLE into four strings so it can be
maedhros
parents: 6890
diff changeset
   276
	if (!IsEngineBuildable(p1, VEH_AIRCRAFT, _current_player)) return_cmd_error(STR_AIRCRAFT_NOT_AVAILABLE);
1196
115f46e3807d (svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents: 1195
diff changeset
   277
6171
42ea86065d8d (svn r8548) -Fix
tron
parents: 6170
diff changeset
   278
	const AircraftVehicleInfo *avi = AircraftVehInfo(p1);
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7139
diff changeset
   279
	CommandCost value = EstimateAircraftCost(p1, avi);
1226
cbcaba80c31c (svn r1730) - Fix: Ships and Aircrafts have to be build in depots owned by _current_player (hacked client protection)
bjarni
parents: 1209
diff changeset
   280
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   281
	/* to just query the cost, it is not neccessary to have a valid tile (automation/AI) */
2423
84222db5a01a (svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents: 2422
diff changeset
   282
	if (flags & DC_QUERY_COST) return value;
84222db5a01a (svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents: 2422
diff changeset
   283
3338
2c60ed0dcce3 (svn r4120) Use the new station functions where appropriate
tron
parents: 3315
diff changeset
   284
	if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR;
1226
cbcaba80c31c (svn r1730) - Fix: Ships and Aircrafts have to be build in depots owned by _current_player (hacked client protection)
bjarni
parents: 1209
diff changeset
   285
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   286
	/* Prevent building aircraft types at places which can't handle them */
8179
1fa8cc3fbeb8 (svn r11214) -Fix [FS#1296]: planes can't use heliports so refuse these orders
glx
parents: 8138
diff changeset
   287
	if (!CanAircraftUseStation(p1, tile)) return CMD_ERROR;
4161
7b08131239f7 (svn r5594) Be more strict what's allowed to be built in a hangar: if the airport can't handle planes/helicopters don't present and disallow building planes/helicopters - the latter case wasn't covered yet.
tron
parents: 4111
diff changeset
   288
6105
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
   289
	/* Allocate 2 or 3 vehicle structs, depending on type
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
   290
	 * vl[0] = aircraft, vl[1] = shadow, [vl[2] = rotor] */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   291
	Vehicle *vl[3];
7894
dbe6e9295ec5 (svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents: 7762
diff changeset
   292
	if (!Vehicle::AllocateList(vl, avi->subtype & AIR_CTOL ? 2 : 3)) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   293
		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   294
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8419
diff changeset
   296
	UnitID unit_num = HasBit(p2, 0) ? 0 : GetFreeUnitNumber(VEH_AIRCRAFT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
	if (unit_num > _patches.max_aircraft)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
	if (flags & DC_EXEC) {
6105
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
   301
		Vehicle *v = vl[0]; // aircraft
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
   302
		Vehicle *u = vl[1]; // shadow
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
7048
06b931095b26 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 7046
diff changeset
   304
		v = new (v) Aircraft();
06b931095b26 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 7046
diff changeset
   305
		u = new (u) Aircraft();
8278
c10ecabf001d (svn r11332) -Fix: vehicles getting a value of 0 on construction.
rubidium
parents: 8196
diff changeset
   306
		v->unitnumber = unit_num;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5836
diff changeset
   307
		v->direction = DIR_SE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
		v->owner = u->owner = _current_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
		v->tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
//		u->tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   314
		uint x = TileX(tile) * TILE_SIZE + 5;
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   315
		uint y = TileY(tile) * TILE_SIZE + 3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
		v->x_pos = u->x_pos = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
		v->y_pos = u->y_pos = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
		u->z_pos = GetSlopeZ(x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
		v->z_pos = u->z_pos + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
9052
392f5995d323 (svn r12134) -Change: count the number of ticks a vehicle was running this day to calculate running cost
smatz
parents: 9030
diff changeset
   323
		v->running_ticks = 0;
392f5995d323 (svn r12134) -Change: count the number of ticks a vehicle was running this day to calculate running cost
smatz
parents: 9030
diff changeset
   324
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
//		u->delta_x = u->delta_y = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
		v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL;
4175
c0bcc65f36d4 (svn r5613) Rename VS_DISASTER to VS_SHADOW, because this is what this flag actually means
tron
parents: 4161
diff changeset
   328
		u->vehstatus = VS_HIDDEN | VS_UNCLICKABLE | VS_SHADOW;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
538
5dd99f3b7eca (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   330
		v->spritenum = avi->image_index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
//		v->cargo_count = u->number_of_pieces = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
922
fc040662bd43 (svn r1410) Replaced all occurences of 'passanger' by 'passenger' in the code
celestar
parents: 919
diff changeset
   333
		v->cargo_cap = avi->passenger_capacity;
538
5dd99f3b7eca (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   334
		u->cargo_cap = avi->mail_capacity;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
		v->cargo_type = CT_PASSENGERS;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
		u->cargo_type = CT_MAIL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
3870
766d7bd6c299 (svn r4910) - NewGRF: add and initialize cargo subtype for vehicle visual variations
peter1138
parents: 3816
diff changeset
   339
		v->cargo_subtype = 0;
766d7bd6c299 (svn r4910) - NewGRF: add and initialize cargo subtype for vehicle visual variations
peter1138
parents: 3816
diff changeset
   340
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   341
		v->name = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
//		v->next_order_param = v->next_order = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
//		v->load_unload_time_rem = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
//		v->progress = 0;
1266
9dc5638fe8cc (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1263
diff changeset
   346
		v->last_station_visited = INVALID_STATION;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
//		v->destination_coords = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
538
5dd99f3b7eca (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   349
		v->max_speed = avi->max_speed;
5dd99f3b7eca (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   350
		v->acceleration = avi->acceleration;
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2475
diff changeset
   351
		v->engine_type = p1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
6105
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
   353
		v->subtype = (avi->subtype & AIR_CTOL ? AIR_AIRCRAFT : AIR_HELICOPTER);
7054
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
   354
		v->UpdateDeltaXY(INVALID_DIR);
7486
d130c10f4dab (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 7476
diff changeset
   355
		v->value = value.GetCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
6105
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
   357
		u->subtype = AIR_SHADOW;
7054
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
   358
		u->UpdateDeltaXY(INVALID_DIR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
3973
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   360
		/* Danger, Will Robinson!
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   361
		 * If the aircraft is refittable, but cannot be refitted to
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   362
		 * passengers, we select the cargo type from the refit mask.
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   363
		 * This is a fairly nasty hack to get around the fact that TTD
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   364
		 * has no default cargo type specifier for planes... */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   365
		CargoID cargo = FindFirstRefittableCargo(p1);
3973
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   366
		if (cargo != CT_INVALID && cargo != CT_PASSENGERS) {
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   367
			uint16 callback = CALLBACK_FAILED;
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   368
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   369
			v->cargo_type = cargo;
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   370
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8419
diff changeset
   371
			if (HasBit(EngInfo(p1)->callbackmask, CBM_VEHICLE_REFIT_CAPACITY)) {
3973
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   372
				callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v);
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   373
			}
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   374
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   375
			if (callback == CALLBACK_FAILED) {
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   376
				/* Callback failed, or not executed; use the default cargo capacity */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   377
				v->cargo_cap = AircraftDefaultCargoCapacity(v->cargo_type, avi);
3973
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   378
			} else {
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   379
				v->cargo_cap = callback;
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   380
			}
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   381
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   382
			/* Set the 'second compartent' capacity to none */
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   383
			u->cargo_cap = 0;
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   384
		}
7624a250577b (svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents: 3963
diff changeset
   385
6105
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
   386
		const Engine *e = GetEngine(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
		v->reliability = e->reliability;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
		v->reliability_spd_dec = e->reliability_spd_dec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
		v->max_age = e->lifelength * 366;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
2564
371e0fa97e1e (svn r3101) -Codechange: added _new_vehicle_id
bjarni
parents: 2561
diff changeset
   391
		_new_vehicle_id = v->index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
2423
84222db5a01a (svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents: 2422
diff changeset
   393
		/* When we click on hangar we know the tile it is on. By that we know
84222db5a01a (svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents: 2422
diff changeset
   394
		 * its position in the array of depots the airport has.....we can search
84222db5a01a (svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents: 2422
diff changeset
   395
		 * layout for #th position of depot. Since layout must start with a listing
84222db5a01a (svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents: 2422
diff changeset
   396
		 * of all depots, it is simple */
6172
df973b5f6190 (svn r8549) -Fix
tron
parents: 6171
diff changeset
   397
		for (uint i = 0;; i++) {
6563
d08d813ecd42 (svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents: 6519
diff changeset
   398
			const Station *st = GetStationByTile(tile);
d08d813ecd42 (svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents: 6519
diff changeset
   399
			const AirportFTAClass *apc = st->Airport();
d08d813ecd42 (svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents: 6519
diff changeset
   400
6172
df973b5f6190 (svn r8549) -Fix
tron
parents: 6171
diff changeset
   401
			assert(i != apc->nof_depots);
df973b5f6190 (svn r8549) -Fix
tron
parents: 6171
diff changeset
   402
			if (st->airport_tile + ToTileIndexDiff(apc->airport_depots[i]) == tile) {
df973b5f6190 (svn r8549) -Fix
tron
parents: 6171
diff changeset
   403
				assert(apc->layout[i].heading == HANGAR);
df973b5f6190 (svn r8549) -Fix
tron
parents: 6171
diff changeset
   404
				v->u.air.pos = apc->layout[i].position;
df973b5f6190 (svn r8549) -Fix
tron
parents: 6171
diff changeset
   405
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
		v->u.air.state = HANGAR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
		v->u.air.previous_pos = v->u.air.pos;
3315
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3186
diff changeset
   411
		v->u.air.targetairport = GetStationIndex(tile);
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
   412
		v->SetNext(u);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
		v->service_interval = _patches.servint_aircraft;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
		v->date_of_last_service = _date;
4329
9759d5c52010 (svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents: 4293
diff changeset
   417
		v->build_year = u->build_year = _cur_year;
0
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
		v->cur_image = u->cur_image = 0xEA0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
2804
b932fe148d36 (svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents: 2752
diff changeset
   421
		v->random_bits = VehicleRandomBits();
b932fe148d36 (svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents: 2752
diff changeset
   422
		u->random_bits = VehicleRandomBits();
b932fe148d36 (svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents: 2752
diff changeset
   423
6502
7ca154aca2b7 (svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents: 6501
diff changeset
   424
		v->vehicle_flags = 0;
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
   425
		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
6502
7ca154aca2b7 (svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents: 6501
diff changeset
   426
6986
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   427
		UpdateAircraftCache(v);
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   428
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
		VehiclePositionChanged(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   432
		/* Aircraft with 3 vehicles (chopper)? */
6105
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
   433
		if (v->subtype == AIR_HELICOPTER) {
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
   434
			Vehicle *w = vl[2];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
7048
06b931095b26 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 7046
diff changeset
   436
			w = new (w) Aircraft();
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5836
diff changeset
   437
			w->direction = DIR_N;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
			w->owner = _current_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
			w->x_pos = v->x_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
			w->y_pos = v->y_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
			w->z_pos = v->z_pos + 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
			w->vehstatus = VS_HIDDEN | VS_UNCLICKABLE;
3710
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   443
			w->spritenum = 0xFF;
6105
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
   444
			w->subtype = AIR_ROTOR;
2517
b90693227193 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2504
diff changeset
   445
			w->cur_image = SPR_ROTOR_STOPPED;
2804
b932fe148d36 (svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents: 2752
diff changeset
   446
			w->random_bits = VehicleRandomBits();
3710
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   447
			/* Use rotor's air.state to store the rotor animation frame */
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   448
			w->u.air.state = HRS_ROTOR_STOPPED;
7054
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
   449
			w->UpdateDeltaXY(INVALID_DIR);
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
   450
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
   451
			u->SetNext(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
			VehiclePositionChanged(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4732
diff changeset
   455
		InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 578
diff changeset
   456
		RebuildVehicleLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
		InvalidateWindow(WC_COMPANY, v->owner);
2618
7546b838230b (svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents: 2601
diff changeset
   458
		if (IsLocalPlayer())
7921
f99d5c351e75 (svn r10823) -Fix r8610 [FS#1097]: the autoreplace window vehicle count didn't always update correctly) (Matthias)
bjarni
parents: 7894
diff changeset
   459
			InvalidateAutoreplaceWindow(v->engine_type, v->group_id); //updates the replace Aircraft window
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6175
diff changeset
   460
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6175
diff changeset
   461
		GetPlayer(_current_player)->num_engines[p1]++;
0
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
	return value;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 381
diff changeset
   468
static void DoDeleteAircraft(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
	DeleteWindowById(WC_VEHICLE_VIEW, v->index);
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 578
diff changeset
   471
	RebuildVehicleLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
	InvalidateWindow(WC_COMPANY, v->owner);
5256
90226d8da8fb (svn r7386) -Codechange r7385: moved deletion of the vehicle highlight from DeleteVehicle to the sell commands as they are not called as often
bjarni
parents: 5215
diff changeset
   473
	DeleteDepotHighlightOfVehicle(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
	DeleteVehicleChain(v);
1055
3aae1d6f12aa (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
   475
	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1752
diff changeset
   478
/** Sell an aircraft.
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
   479
 * @param tile unused
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   480
 * @param flags for command type
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1752
diff changeset
   481
 * @param p1 vehicle ID to be sold
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1752
diff changeset
   482
 * @param p2 unused
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   483
 * @return result of operation.  Error or sold value
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1752
diff changeset
   484
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7139
diff changeset
   485
CommandCost CmdSellAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
{
4352
8ddb01bc6075 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4351
diff changeset
   487
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   489
	Vehicle *v = GetVehicle(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
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
   491
	if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR;
7986
881998b115c2 (svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents: 7921
diff changeset
   492
	if (!v->IsStoppedInDepot()) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
8191
3ffc17ef4ff5 (svn r11229) -Fix [FS#1307]: one could sell vehicles that were crashed in a depot, which would still yield money.
rubidium
parents: 8179
diff changeset
   494
	if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
3ffc17ef4ff5 (svn r11229) -Fix [FS#1307]: one could sell vehicles that were crashed in a depot, which would still yield money.
rubidium
parents: 8179
diff changeset
   495
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8722
diff changeset
   496
	CommandCost ret(EXPENSES_NEW_VEHICLES, -v->value);
8278
c10ecabf001d (svn r11332) -Fix: vehicles getting a value of 0 on construction.
rubidium
parents: 8196
diff changeset
   497
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
		// Invalidate depot
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
		DoDeleteAircraft(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
8278
c10ecabf001d (svn r11332) -Fix: vehicles getting a value of 0 on construction.
rubidium
parents: 8196
diff changeset
   504
	return ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1752
diff changeset
   507
/** Start/Stop an aircraft.
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
   508
 * @param tile unused
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   509
 * @param flags for command type
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   510
 * @param p1 aircraft ID to start/stop
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1752
diff changeset
   511
 * @param p2 unused
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   512
 * @return result of operation.  Nothing if everything went well
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1752
diff changeset
   513
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7139
diff changeset
   514
CommandCost CmdStartStopAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
{
4352
8ddb01bc6075 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4351
diff changeset
   516
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
1237
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   517
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   518
	Vehicle *v = GetVehicle(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
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
   520
	if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   522
	/* cannot stop airplane when in flight, or when taking off / landing */
4059
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4056
diff changeset
   523
	if (v->u.air.state >= STARTTAKEOFF && v->u.air.state < TERM7)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
		return_cmd_error(STR_A017_AIRCRAFT_IS_IN_FLIGHT);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
4338
cc4648e8e529 (svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents: 4329
diff changeset
   526
	/* Check if this aircraft can be started/stopped. The callback will fail or
cc4648e8e529 (svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents: 4329
diff changeset
   527
	 * return 0xFF if it can. */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   528
	uint16 callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v);
4338
cc4648e8e529 (svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents: 4329
diff changeset
   529
	if (callback != CALLBACK_FAILED && callback != 0xFF) {
cc4648e8e529 (svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents: 4329
diff changeset
   530
		StringID error = GetGRFStringID(GetEngineGRFID(v->engine_type), 0xD000 + callback);
cc4648e8e529 (svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents: 4329
diff changeset
   531
		return_cmd_error(error);
cc4648e8e529 (svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents: 4329
diff changeset
   532
	}
cc4648e8e529 (svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents: 4329
diff changeset
   533
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
	if (flags & DC_EXEC) {
7986
881998b115c2 (svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents: 7921
diff changeset
   535
		if (v->IsStoppedInDepot()) {
3139
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 3008
diff changeset
   536
			DeleteVehicleNews(p1, STR_A014_AIRCRAFT_IS_WAITING_IN);
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 3008
diff changeset
   537
		}
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 3008
diff changeset
   538
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
		v->vehstatus ^= VS_STOPPED;
8311
058851bb0b5e (svn r11365) -Fix [FS#1288]: when stopping a ship or aircraft, set their speed to 0 so they won't continue at the speed where they were stopped at.
rubidium
parents: 8278
diff changeset
   540
		v->cur_speed = 0;
8846
f3e877a92e2b (svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz
parents: 8825
diff changeset
   541
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
1055
3aae1d6f12aa (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
   543
		InvalidateWindowClasses(WC_AIRCRAFT_LIST);
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
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   546
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   549
/** Send an aircraft to the hangar.
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
   550
 * @param tile unused
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   551
 * @param flags for command type
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   552
 * @param p1 vehicle ID to send to the hangar
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   553
 * @param p2 various bitmasked elements
4506
0d8fcc0a4e49 (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4463
diff changeset
   554
 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
0d8fcc0a4e49 (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4463
diff changeset
   555
 * - p2 bit 8-10 - VLW flag (for mass goto depot)
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   556
 * @return o if everything went well
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   557
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7139
diff changeset
   558
CommandCost CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
{
4506
0d8fcc0a4e49 (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4463
diff changeset
   560
	if (p2 & DEPOT_MASS_SEND) {
0d8fcc0a4e49 (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4463
diff changeset
   561
		/* Mass goto depot requested */
4546
9345e0569655 (svn r6378) -Codechange: Rename VLW_FLAGS to VLW_MASK as it is a mask
Darkvater
parents: 4544
diff changeset
   562
		if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR;
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
   563
		return SendAllVehiclesToDepot(VEH_AIRCRAFT, flags, p2 & DEPOT_SERVICE, _current_player, (p2 & VLW_MASK), p1);
4463
3a70624c40eb (svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents: 4451
diff changeset
   564
	}
3a70624c40eb (svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents: 4451
diff changeset
   565
4506
0d8fcc0a4e49 (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4463
diff changeset
   566
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
1237
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   567
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   568
	Vehicle *v = GetVehicle(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
7986
881998b115c2 (svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents: 7921
diff changeset
   570
	if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner) || v->IsInDepot()) return CMD_ERROR;
4451
66603f0f732e (svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents: 4434
diff changeset
   571
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
   572
	if (v->current_order.IsType(OT_GOTO_DEPOT) && !(p2 & DEPOT_LOCATE_HANGAR)) {
9339
daaa2adbaf99 (svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents: 9338
diff changeset
   573
		bool halt_in_depot = HasBit(v->current_order.GetDepotActionType(), OF_HALT_IN_DEPOT);
daaa2adbaf99 (svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents: 9338
diff changeset
   574
		if (!!(p2 & DEPOT_SERVICE) == halt_in_depot) {
4510
071bca98c577 (svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents: 4506
diff changeset
   575
			/* We called with a different DEPOT_SERVICE setting.
071bca98c577 (svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents: 4506
diff changeset
   576
			 * Now we change the setting to apply the new one and let the vehicle head for the same hangar.
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4546
diff changeset
   577
			 * Note: the if is (true for requesting service == true for ordered to stop in hangar) */
4510
071bca98c577 (svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents: 4506
diff changeset
   578
			if (flags & DC_EXEC) {
9339
daaa2adbaf99 (svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents: 9338
diff changeset
   579
				v->current_order.SetDepotOrderType(OFB_MANUAL_ORDER);
daaa2adbaf99 (svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents: 9338
diff changeset
   580
				v->current_order.SetDepotActionType(halt_in_depot ? OFB_NORMAL_ACTION : OFB_HALT_IN_DEPOT);
8846
f3e877a92e2b (svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz
parents: 8825
diff changeset
   581
				InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
4510
071bca98c577 (svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents: 4506
diff changeset
   582
			}
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   583
			return CommandCost();
4510
071bca98c577 (svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents: 4506
diff changeset
   584
		}
071bca98c577 (svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents: 4506
diff changeset
   585
4506
0d8fcc0a4e49 (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4463
diff changeset
   586
		if (p2 & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of hangar orders
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
		if (flags & DC_EXEC) {
9339
daaa2adbaf99 (svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents: 9338
diff changeset
   588
			/* If the orders to 'goto depot' are in the orders list (forced servicing),
daaa2adbaf99 (svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents: 9338
diff changeset
   589
			 * then skip to the next order; effectively cancelling this forced service */
daaa2adbaf99 (svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents: 9338
diff changeset
   590
			if (v->current_order.GetDepotOrderType() & OFB_PART_OF_ORDERS) v->cur_order_index++;
daaa2adbaf99 (svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents: 9338
diff changeset
   591
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
   592
			v->current_order.MakeDummy();
8846
f3e877a92e2b (svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz
parents: 8825
diff changeset
   593
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
	} else {
1262
b232a05f37e4 (svn r1766) - Feature: Aircrafts will now go to the nearest hangar if the next airport in the orders do not have one (helipads)
bjarni
parents: 1245
diff changeset
   596
		bool next_airport_has_hangar = true;
4412
945e8a9bb89a (svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents: 4389
diff changeset
   597
		StationID next_airport_index = v->u.air.targetairport;
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   598
		const Station *st = GetStation(next_airport_index);
4111
8efd85ca4b76 (svn r5454) -Fix: [ 1394231 ] Autorenew glitch on helicopters
bjarni
parents: 4095
diff changeset
   599
		/* If the station is not a valid airport or if it has no hangars */
6358
e7997742bf02 (svn r8755) -Fix
tron
parents: 6353
diff changeset
   600
		if (!st->IsValid() || st->airport_tile == 0 || st->Airport()->nof_depots == 0) {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   601
			/* the aircraft has to search for a hangar on its own */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   602
			StationID station = FindNearestHangar(v);
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   603
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   604
			next_airport_has_hangar = false;
4506
0d8fcc0a4e49 (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4463
diff changeset
   605
			if (station == INVALID_STATION) return CMD_ERROR;
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   606
			next_airport_index = station;
1262
b232a05f37e4 (svn r1766) - Feature: Aircrafts will now go to the nearest hangar if the next airport in the orders do not have one (helipads)
bjarni
parents: 1245
diff changeset
   607
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
		if (flags & DC_EXEC) {
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
   610
			if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
6998
403314de0154 (svn r9685) -Fix (r9683): Call v->LeaveStation() when a vehicle in a station is sent to a depot.
maedhros
parents: 6997
diff changeset
   611
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
   612
			v->current_order.MakeGoToDepot(next_airport_index, false);
9339
daaa2adbaf99 (svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents: 9338
diff changeset
   613
			if (!(p2 & DEPOT_SERVICE)) v->current_order.SetDepotActionType(OFB_HALT_IN_DEPOT);
8846
f3e877a92e2b (svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz
parents: 8825
diff changeset
   614
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
5689
430135ca34f3 (svn r7657) -Fix (r6291): 'Goto Depot' did not work for helicopters going to an airport without depot (mart3p).
rubidium
parents: 5568
diff changeset
   615
			if (v->u.air.state == FLYING && !next_airport_has_hangar) {
4506
0d8fcc0a4e49 (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4463
diff changeset
   616
				/* The aircraft is now heading for a different hangar than the next in the orders */
1194
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   617
				AircraftNextAirportPos_and_Order(v);
616dddfc77f3 (svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents: 1151
diff changeset
   618
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   622
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
}
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
1802
448f187042d3 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1793
diff changeset
   626
/** Refits an aircraft to the specified cargo type.
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
   627
 * @param tile unused
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   628
 * @param flags for command type
1802
448f187042d3 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1793
diff changeset
   629
 * @param p1 vehicle ID of the aircraft to refit
448f187042d3 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1793
diff changeset
   630
 * @param p2 various bitstuffed elements
2635
88b8b74c01ac (svn r3177) GB, CLRBIT, HASBIT, TOGGLEBIT
tron
parents: 2630
diff changeset
   631
 * - p2 = (bit 0-7) - the new cargo type to refit to
3954
634cd5e35803 (svn r5103) - Add cargo subtype parameter to refit commands (mart3p)
peter1138
parents: 3948
diff changeset
   632
 * - p2 = (bit 8-15) - the new cargo subtype to refit to
7042
d841fb0d8e9a (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6998
diff changeset
   633
 * - p2 = (bit 16) - refit only this vehicle (ignored)
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   634
 * @return cost of refit or error
1802
448f187042d3 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1793
diff changeset
   635
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7139
diff changeset
   636
CommandCost CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
{
3954
634cd5e35803 (svn r5103) - Add cargo subtype parameter to refit commands (mart3p)
peter1138
parents: 3948
diff changeset
   638
	byte new_subtype = GB(p2, 8, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
4352
8ddb01bc6075 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4351
diff changeset
   640
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   642
	Vehicle *v = GetVehicle(p1);
1237
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   643
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
   644
	if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR;
7986
881998b115c2 (svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents: 7921
diff changeset
   645
	if (!v->IsStoppedInDepot()) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
8641
966d79f41865 (svn r11707) -Fix: do not allow refitting flooded (destroyed) vehicles
smatz
parents: 8640
diff changeset
   646
	if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_REFIT_DESTROYED_VEHICLE);
1237
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   647
1802
448f187042d3 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1793
diff changeset
   648
	/* Check cargo */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   649
	CargoID new_cid = GB(p2, 0, 8);
6642
2e690e6fdc03 (svn r9259) -Codechange: NUM_CARGO isn't a valid cargo type...
peter1138
parents: 6589
diff changeset
   650
	if (new_cid >= NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
3974
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   652
	/* Check the refit capacity callback */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   653
	uint16 callback = CALLBACK_FAILED;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8419
diff changeset
   654
	if (HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_REFIT_CAPACITY)) {
3974
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   655
		/* Back up the existing cargo type */
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   656
		CargoID temp_cid = v->cargo_type;
3988
b76291f6ce29 (svn r5187) - NewGRF: temporarily change a vehicle's cargo subtype when calling the refit capacity callback.
peter1138
parents: 3987
diff changeset
   657
		byte temp_subtype = v->cargo_subtype;
3974
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   658
		v->cargo_type = new_cid;
3988
b76291f6ce29 (svn r5187) - NewGRF: temporarily change a vehicle's cargo subtype when calling the refit capacity callback.
peter1138
parents: 3987
diff changeset
   659
		v->cargo_subtype = new_subtype;
3974
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   660
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   661
		callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v);
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   662
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   663
		/* Restore the cargo type */
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   664
		v->cargo_type = temp_cid;
3988
b76291f6ce29 (svn r5187) - NewGRF: temporarily change a vehicle's cargo subtype when calling the refit capacity callback.
peter1138
parents: 3987
diff changeset
   665
		v->cargo_subtype = temp_subtype;
3974
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   666
	}
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   667
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   668
	const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   669
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   670
	uint pass;
3974
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   671
	if (callback == CALLBACK_FAILED) {
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   672
		/* If the callback failed, or wasn't executed, use the aircraft's
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   673
		 * default cargo capacity */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   674
		pass = AircraftDefaultCargoCapacity(new_cid, avi);
3974
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   675
	} else {
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   676
		pass = callback;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
	}
3008
7b519db78ce2 (svn r3588) - Refit: Use only one global to return the refit capacity rather than one per vehicle type.
peter1138
parents: 3005
diff changeset
   678
	_returned_refit_capacity = pass;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   680
	CommandCost cost;
4845
49105d3b5a9a (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4843
diff changeset
   681
	if (IsHumanPlayer(v->owner) && new_cid != v->cargo_type) {
4544
b2d5ad597e4d (svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents: 4529
diff changeset
   682
		cost = GetRefitCost(v->engine_type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
	}
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
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
		v->cargo_cap = pass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
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: 7986
diff changeset
   688
		Vehicle *u = v->Next();
6666
88f1598fafb3 (svn r9352) -Codechange: Use cargo class to determine if an aircraft should carry mail
peter1138
parents: 6660
diff changeset
   689
		uint mail = IsCargoInClass(new_cid, CC_PASSENGERS) ? avi->mail_capacity : 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
		u->cargo_cap = mail;
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
   691
		v->cargo.Truncate(v->cargo_type == new_cid ? pass : 0);
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
   692
		u->cargo.Truncate(v->cargo_type == new_cid ? mail : 0);
1802
448f187042d3 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1793
diff changeset
   693
		v->cargo_type = new_cid;
3954
634cd5e35803 (svn r5103) - Add cargo subtype parameter to refit commands (mart3p)
peter1138
parents: 3948
diff changeset
   694
		v->cargo_subtype = new_subtype;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
3722
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
   696
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
   697
		RebuildVehicleLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
static void CheckIfAircraftNeedsService(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
{
7998
f1a308b61b8f (svn r11017) -Codechange: unify determining whether a vehicle needs/can be service a little more.
rubidium
parents: 7989
diff changeset
   706
	if (_patches.servint_aircraft == 0 || !VehicleNeedsService(v)) return;
f1a308b61b8f (svn r11017) -Codechange: unify determining whether a vehicle needs/can be service a little more.
rubidium
parents: 7989
diff changeset
   707
	if (v->IsInDepot()) {
4529
2bfac24af02a (svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents: 4527
diff changeset
   708
		VehicleServiceInDepot(v);
2bfac24af02a (svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents: 4527
diff changeset
   709
		return;
2bfac24af02a (svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents: 4527
diff changeset
   710
	}
2bfac24af02a (svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents: 4527
diff changeset
   711
9336
3f75a2c5e0d3 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 9332
diff changeset
   712
	const Station *st = GetStation(v->current_order.GetDestination());
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   713
	/* only goto depot if the target airport has terminals (eg. it is airport) */
6358
e7997742bf02 (svn r8755) -Fix
tron
parents: 6353
diff changeset
   714
	if (st->IsValid() && st->airport_tile != 0 && st->Airport()->terminals != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
//		printf("targetairport = %d, st->index = %d\n", v->u.air.targetairport, st->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
//		v->u.air.targetairport = st->index;
9338
5ce4c6612c7e (svn r12592) -Fix (r12580): aircraft's go-to-depot handling is a mess, which assumes destination to be a station even when it did not set a destination yet.
rubidium
parents: 9336
diff changeset
   717
		v->current_order.MakeGoToDepot(0, false);
8846
f3e877a92e2b (svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz
parents: 8825
diff changeset
   718
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
   719
	} else if (v->current_order.IsType(OT_GOTO_DEPOT)) {
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
   720
		v->current_order.MakeDummy();
8846
f3e877a92e2b (svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz
parents: 8825
diff changeset
   721
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
8963
4b41ed1df7e5 (svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx
parents: 8865
diff changeset
   725
void Aircraft::OnNewDay()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
{
8963
4b41ed1df7e5 (svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx
parents: 8865
diff changeset
   727
	if (!IsNormalAircraft(this)) return;
19
6080d2b6a959 (svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents: 11
diff changeset
   728
8963
4b41ed1df7e5 (svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx
parents: 8865
diff changeset
   729
	if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
8963
4b41ed1df7e5 (svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx
parents: 8865
diff changeset
   731
	CheckOrders(this);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
8963
4b41ed1df7e5 (svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx
parents: 8865
diff changeset
   733
	CheckVehicleBreakdown(this);
4b41ed1df7e5 (svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx
parents: 8865
diff changeset
   734
	AgeVehicle(this);
4b41ed1df7e5 (svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx
parents: 8865
diff changeset
   735
	CheckIfAircraftNeedsService(this);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
9052
392f5995d323 (svn r12134) -Change: count the number of ticks a vehicle was running this day to calculate running cost
smatz
parents: 9030
diff changeset
   737
	if (this->running_ticks == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
9052
392f5995d323 (svn r12134) -Change: count the number of ticks a vehicle was running this day to calculate running cost
smatz
parents: 9030
diff changeset
   739
	CommandCost cost(EXPENSES_AIRCRAFT_RUN, GetVehicleProperty(this, 0x0E, AircraftVehInfo(this->engine_type)->running_cost) * _price.aircraft_running * this->running_ticks / (364 * DAY_TICKS));
8963
4b41ed1df7e5 (svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx
parents: 8865
diff changeset
   740
9052
392f5995d323 (svn r12134) -Change: count the number of ticks a vehicle was running this day to calculate running cost
smatz
parents: 9030
diff changeset
   741
	this->profit_this_year -= cost.GetCost();
392f5995d323 (svn r12134) -Change: count the number of ticks a vehicle was running this day to calculate running cost
smatz
parents: 9030
diff changeset
   742
	this->running_ticks = 0;
8963
4b41ed1df7e5 (svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx
parents: 8865
diff changeset
   743
4b41ed1df7e5 (svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx
parents: 8865
diff changeset
   744
	SubtractMoneyFromPlayerFract(this->owner, cost);
4b41ed1df7e5 (svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx
parents: 8865
diff changeset
   745
4b41ed1df7e5 (svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx
parents: 8865
diff changeset
   746
	InvalidateWindow(WC_VEHICLE_DETAILS, this->index);
1055
3aae1d6f12aa (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
   747
	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
0
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
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6563
diff changeset
   750
void AircraftYearlyLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
	FOR_ALL_VEHICLES(v) {
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
   755
		if (v->type == VEH_AIRCRAFT && IsNormalAircraft(v)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
			v->profit_last_year = v->profit_this_year;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
			v->profit_this_year = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
			InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
static void AgeAircraftCargo(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   765
	if (_age_cargo_skip_counter != 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
	do {
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
   768
		v->cargo.AgeCargo();
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: 7986
diff changeset
   769
		v = v->Next();
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   770
	} while (v != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
static void HelicopterTickHandler(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
{
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: 7986
diff changeset
   775
	Vehicle *u = v->Next()->Next();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   777
	if (u->vehstatus & VS_HIDDEN) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   779
	/* if true, helicopter rotors do not rotate. This should only be the case if a helicopter is
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   780
	 * loading/unloading at a terminal or stopped */
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
   781
	if (v->current_order.IsType(OT_LOADING) || (v->vehstatus & VS_STOPPED)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
		if (u->cur_speed != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
			u->cur_speed++;
3710
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   784
			if (u->cur_speed >= 0x80 && u->u.air.state == HRS_ROTOR_MOVING_3) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
				u->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
			}
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
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
		if (u->cur_speed == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
			u->cur_speed = 0x70;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
		if (u->cur_speed >= 0x50)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
			u->cur_speed--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   796
	int tick = ++u->tick_counter;
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   797
	int spd = u->cur_speed >> 4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   799
	SpriteID img;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
	if (spd == 0) {
3710
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   801
		u->u.air.state = HRS_ROTOR_STOPPED;
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   802
		img = GetRotorImage(v);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
   803
		if (u->cur_image == img) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
	} else if (tick >= spd) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
		u->tick_counter = 0;
3710
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   806
		u->u.air.state++;
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   807
		if (u->u.air.state > HRS_ROTOR_MOVING_3) u->u.air.state = HRS_ROTOR_MOVING_1;
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   808
		img = GetRotorImage(v);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
   809
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
		return;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
   811
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
   813
	u->cur_image = img;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
	BeginVehicleMove(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
	VehiclePositionChanged(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
	EndVehicleMove(u);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
static void SetAircraftPosition(Vehicle *v, int x, int y, int z)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
	v->x_pos = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
	v->y_pos = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
	v->z_pos = z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
7630
2cd754d7dfa4 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 7592
diff changeset
   826
	v->cur_image = v->GetImage(v->direction);
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: 7986
diff changeset
   827
	if (v->subtype == AIR_HELICOPTER) v->Next()->Next()->cur_image = GetRotorImage(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
	BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
	VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
	EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
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: 7986
diff changeset
   833
	Vehicle *u = v->Next();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8396
diff changeset
   835
	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: 8396
diff changeset
   836
	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
   837
	u->x_pos = x;
4259
71b8dba85ce1 (svn r5883) -Fix [FS#272]: use the height of the edge of the map for shadows of aircrafts that are outside the map; similar to r5841, caused by r5794.
rubidium
parents: 4244
diff changeset
   838
	u->y_pos = y - ((v->z_pos-GetSlopeZ(safe_x, safe_y)) >> 3);;
71b8dba85ce1 (svn r5883) -Fix [FS#272]: use the height of the edge of the map for shadows of aircrafts that are outside the map; similar to r5841, caused by r5794.
rubidium
parents: 4244
diff changeset
   839
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8396
diff changeset
   840
	safe_y = Clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE);
4259
71b8dba85ce1 (svn r5883) -Fix [FS#272]: use the height of the edge of the map for shadows of aircrafts that are outside the map; similar to r5841, caused by r5794.
rubidium
parents: 4244
diff changeset
   841
	u->z_pos = GetSlopeZ(safe_x, safe_y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
	u->cur_image = v->cur_image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
	BeginVehicleMove(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
	VehiclePositionChanged(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
	EndVehicleMove(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
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: 7986
diff changeset
   848
	u = u->Next();
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   849
	if (u != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
		u->x_pos = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
		u->y_pos = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
		u->z_pos = z + 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
		BeginVehicleMove(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
		VehiclePositionChanged(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
		EndVehicleMove(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
4725
f7284b86833f (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
   860
/** Handle Aircraft specific tasks when a an Aircraft enters a hangar
f7284b86833f (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
   861
 * @param *v Vehicle that enters the hangar
f7284b86833f (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
   862
 */
4732
da9d305d1c94 (svn r6644) -Fix(r6637): remove inline to allow MSVC compilation
belugas
parents: 4725
diff changeset
   863
void HandleAircraftEnterHangar(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
	v->subspeed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
	v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
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: 7986
diff changeset
   868
	Vehicle *u = v->Next();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
	u->vehstatus |= VS_HIDDEN;
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: 7986
diff changeset
   870
	u = u->Next();
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   871
	if (u != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
		u->vehstatus |= VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
		u->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
	SetAircraftPosition(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
   877
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
   879
static void PlayAircraftSound(const Vehicle* v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
{
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4574
diff changeset
   881
	if (!PlayVehicleSound(v, VSE_START)) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4574
diff changeset
   882
		SndPlayVehicleFx(AircraftVehInfo(v->engine_type)->sfx, v);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4574
diff changeset
   883
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
6986
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   886
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   887
void UpdateAircraftCache(Vehicle *v)
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   888
{
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   889
	uint max_speed = GetVehicleProperty(v, 0x0C, 0);
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   890
	if (max_speed != 0) {
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   891
		/* Convert from original units to (approx) km/h */
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   892
		max_speed = (max_speed * 129) / 10;
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   893
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   894
		v->u.air.cached_max_speed = max_speed;
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   895
	} else {
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   896
		v->u.air.cached_max_speed = 0xFFFF;
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   897
	}
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   898
}
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   899
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   900
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   901
/**
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   902
 * Special velocities for aircraft
6196
93978efa62c4 (svn r8611) -Fix: Moved the aircraft speed limiting into UpdateAircraftSpeed and enummed some speed limits. This should give a more steady display in the status bar during taxiing
celestar
parents: 6195
diff changeset
   903
 */
93978efa62c4 (svn r8611) -Fix: Moved the aircraft speed limiting into UpdateAircraftSpeed and enummed some speed limits. This should give a more steady display in the status bar during taxiing
celestar
parents: 6195
diff changeset
   904
enum AircraftSpeedLimits {
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   905
	SPEED_LIMIT_TAXI     =     50,  ///< Maximum speed of an aircraft while taxiing
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   906
	SPEED_LIMIT_APPROACH =    230,  ///< Maximum speed of an aircraft on finals
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   907
	SPEED_LIMIT_BROKEN   =    320,  ///< Maximum speed of an aircraft that is broken
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   908
	SPEED_LIMIT_HOLD     =    425,  ///< Maximum speed of an aircraft that flies the holding pattern
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   909
	SPEED_LIMIT_NONE     = 0xFFFF   ///< No environmental speed limit. Speed limit is type dependent
6196
93978efa62c4 (svn r8611) -Fix: Moved the aircraft speed limiting into UpdateAircraftSpeed and enummed some speed limits. This should give a more steady display in the status bar during taxiing
celestar
parents: 6195
diff changeset
   910
};
93978efa62c4 (svn r8611) -Fix: Moved the aircraft speed limiting into UpdateAircraftSpeed and enummed some speed limits. This should give a more steady display in the status bar during taxiing
celestar
parents: 6195
diff changeset
   911
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   912
/**
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   913
 * Sets the new speed for an aircraft
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   914
 * @param v The vehicle for which the speed should be obtained
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   915
 * @param speed_limit The maximum speed the vehicle may have.
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   916
 * @param hard_limit If true, the limit is directly enforced, otherwise the plane is slowed down gradually
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   917
 * @return The number of position updates needed within the tick
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   918
 */
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   919
static int UpdateAircraftSpeed(Vehicle *v, uint speed_limit = SPEED_LIMIT_NONE, bool hard_limit = true)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
{
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   921
	uint spd = v->acceleration * 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
	byte t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
9144
3e82211b57c5 (svn r12293) -Feature: Ability to change aircraft speed factor, from so
peter1138
parents: 9124
diff changeset
   924
	/* Adjust speed limits by plane speed factor to prevent taxiing
3e82211b57c5 (svn r12293) -Feature: Ability to change aircraft speed factor, from so
peter1138
parents: 9124
diff changeset
   925
	 * and take-off speeds being too low. */
3e82211b57c5 (svn r12293) -Feature: Ability to change aircraft speed factor, from so
peter1138
parents: 9124
diff changeset
   926
	speed_limit *= _patches.plane_speed;
3e82211b57c5 (svn r12293) -Feature: Ability to change aircraft speed factor, from so
peter1138
parents: 9124
diff changeset
   927
6986
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   928
	if (v->u.air.cached_max_speed < speed_limit) {
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   929
		if (v->cur_speed < speed_limit) hard_limit = false;
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   930
		speed_limit = v->u.air.cached_max_speed;
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   931
	}
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
   932
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   933
	speed_limit = min(speed_limit, v->max_speed);
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   934
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
	v->subspeed = (t=v->subspeed) + (byte)spd;
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   936
9062
cfef22f7dd66 (svn r12144) -Codechange: Adjust aircraft slowing algorithm so that very fast
peter1138
parents: 9052
diff changeset
   937
	/* Aircraft's current speed is used twice so that very fast planes are
cfef22f7dd66 (svn r12144) -Codechange: Adjust aircraft slowing algorithm so that very fast
peter1138
parents: 9052
diff changeset
   938
	 * forced to slow down rapidly in the short distance needed. The magic
cfef22f7dd66 (svn r12144) -Codechange: Adjust aircraft slowing algorithm so that very fast
peter1138
parents: 9052
diff changeset
   939
	 * value 16384 was determined to give similar results to the old speed/48
cfef22f7dd66 (svn r12144) -Codechange: Adjust aircraft slowing algorithm so that very fast
peter1138
parents: 9052
diff changeset
   940
	 * method at slower speeds. This also results in less reduction at slow
cfef22f7dd66 (svn r12144) -Codechange: Adjust aircraft slowing algorithm so that very fast
peter1138
parents: 9052
diff changeset
   941
	 * speeds to that aircraft do not get to taxi speed straight after
cfef22f7dd66 (svn r12144) -Codechange: Adjust aircraft slowing algorithm so that very fast
peter1138
parents: 9052
diff changeset
   942
	 * touchdown. */
9144
3e82211b57c5 (svn r12293) -Feature: Ability to change aircraft speed factor, from so
peter1138
parents: 9124
diff changeset
   943
	if (!hard_limit && v->cur_speed > speed_limit) {
3e82211b57c5 (svn r12293) -Feature: Ability to change aircraft speed factor, from so
peter1138
parents: 9124
diff changeset
   944
		speed_limit = v->cur_speed - max(1, ((v->cur_speed * v->cur_speed) / 16384) / _patches.plane_speed);
3e82211b57c5 (svn r12293) -Feature: Ability to change aircraft speed factor, from so
peter1138
parents: 9124
diff changeset
   945
	}
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   946
6196
93978efa62c4 (svn r8611) -Fix: Moved the aircraft speed limiting into UpdateAircraftSpeed and enummed some speed limits. This should give a more steady display in the status bar during taxiing
celestar
parents: 6195
diff changeset
   947
	spd = min(v->cur_speed + (spd >> 8) + (v->subspeed < t), speed_limit);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   948
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   949
	/* adjust speed for broken vehicles */
6196
93978efa62c4 (svn r8611) -Fix: Moved the aircraft speed limiting into UpdateAircraftSpeed and enummed some speed limits. This should give a more steady display in the status bar during taxiing
celestar
parents: 6195
diff changeset
   950
	if (v->vehstatus & VS_AIRCRAFT_BROKEN) spd = min(spd, SPEED_LIMIT_BROKEN);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   952
	/* updates statusbar only if speed have changed to save CPU time */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
	if (spd != v->cur_speed) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
		v->cur_speed = spd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
		if (_patches.vehicle_speed)
8846
f3e877a92e2b (svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz
parents: 8825
diff changeset
   956
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
9144
3e82211b57c5 (svn r12293) -Feature: Ability to change aircraft speed factor, from so
peter1138
parents: 9124
diff changeset
   959
	/* Adjust distance moved by plane speed setting */
3e82211b57c5 (svn r12293) -Feature: Ability to change aircraft speed factor, from so
peter1138
parents: 9124
diff changeset
   960
	if (_patches.plane_speed > 1) spd /= _patches.plane_speed;
3e82211b57c5 (svn r12293) -Feature: Ability to change aircraft speed factor, from so
peter1138
parents: 9124
diff changeset
   961
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   962
	if (!(v->direction & 1)) spd = spd * 3 / 4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   964
	spd += v->progress;
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   965
	v->progress = (byte)spd;
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   966
	return spd >> 8;
0
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
6159
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   969
/**
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   970
 * Gets the cruise altitude of an aircraft.
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   971
 * The cruise altitude is determined by the velocity of the vehicle
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   972
 * and the direction it is moving
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   973
 * @param v The vehicle. Should be an aircraft
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   974
 * @returns Altitude in pixel units
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   975
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
static byte GetAircraftFlyingAltitude(const Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
{
6159
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   978
	/* Make sure Aircraft fly no lower so that they don't conduct
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   979
	 * CFITs (controlled flight into terrain)
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   980
	 */
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   981
	byte base_altitude = 150;
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   982
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   983
	/* Make sure eastbound and westbound planes do not "crash" into each
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   984
	 * other by providing them with vertical seperation
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   985
	 */
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   986
	switch (v->direction) {
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   987
		case DIR_N:
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   988
		case DIR_NE:
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   989
		case DIR_E:
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   990
		case DIR_SE:
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   991
			base_altitude += 10;
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   992
			break;
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   993
6159
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   994
		default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
	}
6159
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   996
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   997
	/* Make faster planes fly higher so that they can overtake slower ones */
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
   998
	base_altitude += min(20 * (v->max_speed / 200), 90);
6159
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   999
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
  1000
	return base_altitude;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1003
/**
6890
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1004
 * Find the entry point to an airport depending on direction which
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1005
 * the airport is being approached from. Each airport can have up to
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1006
 * four entry points for its approach system so that approaching
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1007
 * aircraft do not fly through each other or are forced to do 180
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1008
 * degree turns during the approach. The arrivals are grouped into
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1009
 * four sectors dependent on the DiagDirection from which the airport
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1010
 * is approached.
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1011
 *
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1012
 * @param v   The vehicle that is approaching the airport
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1013
 * @param apc The Airport Class being approached.
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1014
 * @returns   The index of the entry point
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1015
 */
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1016
static byte AircraftGetEntryPoint(const Vehicle *v, const AirportFTAClass *apc)
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1017
{
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1018
	assert(v != NULL);
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1019
	assert(apc != NULL);
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1020
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1021
	const Station *st = GetStation(v->u.air.targetairport);
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1022
	/* Make sure we don't go to 0,0 if the airport has been removed. */
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1023
	TileIndex tile = (st->airport_tile != 0) ? st->airport_tile : st->xy;
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1024
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1025
	int delta_x = v->x_pos - TileX(tile) * TILE_SIZE;
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1026
	int delta_y = v->y_pos - TileY(tile) * TILE_SIZE;
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1027
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1028
	DiagDirection dir;
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1029
	if (abs(delta_y) < abs(delta_x)) {
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1030
		/* We are northeast or southwest of the airport */
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1031
		dir = delta_x < 0 ? DIAGDIR_NE : DIAGDIR_SW;
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1032
	} else {
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1033
		/* We are northwest or southeast of the airport */
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1034
		dir = delta_y < 0 ? DIAGDIR_NW : DIAGDIR_SE;
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1035
	}
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1036
	return apc->entry_points[dir];
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1037
}
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1038
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1039
/**
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1040
 * Controls the movement of an aircraft. This function actually moves the vehicle
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1041
 * on the map and takes care of minor things like sound playback.
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1042
 * @todo    De-mystify the cur_speed values for helicopter rotors.
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1043
 * @param v The vehicle that is moved. Must be the first vehicle of the chain
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1044
 * @return  Whether the position requested by the State Machine has been reached
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1045
 */
1401
56d372a75b74 (svn r1905) - Fix: [ 1118810 ] openttd: ship_cmd.c:642 ... Assertion failed. Mapwrap fixed in ship_cmd.c (was implicitely ok before biggermaps).
Darkvater
parents: 1359
diff changeset
  1046
static bool AircraftController(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
{
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1048
	int count;
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1049
	const Station *st = GetStation(v->u.air.targetairport);
6890
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1050
	const AirportFTAClass *afc = st->Airport();
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1051
	const AirportMovingData *amd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1053
	/* prevent going to 0,0 if airport is deleted. */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1054
	TileIndex tile = st->airport_tile;
6890
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1055
	if (tile == 0) {
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1056
		tile = st->xy;
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1057
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1058
		/* Jump into our "holding pattern" state machine if possible */
8486
27a9903a60cb (svn r11546) -Fix[FS#1496]: If ever the air/heli port is suddenly not available while the "chopper" is descending, just go back into flying.
belugas
parents: 8463
diff changeset
  1059
		if (v->u.air.pos >= afc->nofelements) {
27a9903a60cb (svn r11546) -Fix[FS#1496]: If ever the air/heli port is suddenly not available while the "chopper" is descending, just go back into flying.
belugas
parents: 8463
diff changeset
  1060
			v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, afc);
9336
3f75a2c5e0d3 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 9332
diff changeset
  1061
		} else if (v->u.air.targetairport != v->current_order.GetDestination()) {
8486
27a9903a60cb (svn r11546) -Fix[FS#1496]: If ever the air/heli port is suddenly not available while the "chopper" is descending, just go back into flying.
belugas
parents: 8463
diff changeset
  1062
			/* If not possible, just get out of here fast */
27a9903a60cb (svn r11546) -Fix[FS#1496]: If ever the air/heli port is suddenly not available while the "chopper" is descending, just go back into flying.
belugas
parents: 8463
diff changeset
  1063
			v->u.air.state = FLYING;
27a9903a60cb (svn r11546) -Fix[FS#1496]: If ever the air/heli port is suddenly not available while the "chopper" is descending, just go back into flying.
belugas
parents: 8463
diff changeset
  1064
			UpdateAircraftCache(v);
27a9903a60cb (svn r11546) -Fix[FS#1496]: If ever the air/heli port is suddenly not available while the "chopper" is descending, just go back into flying.
belugas
parents: 8463
diff changeset
  1065
			AircraftNextAirportPos_and_Order(v);
27a9903a60cb (svn r11546) -Fix[FS#1496]: If ever the air/heli port is suddenly not available while the "chopper" is descending, just go back into flying.
belugas
parents: 8463
diff changeset
  1066
			/* get aircraft back on running altitude */
27a9903a60cb (svn r11546) -Fix[FS#1496]: If ever the air/heli port is suddenly not available while the "chopper" is descending, just go back into flying.
belugas
parents: 8463
diff changeset
  1067
			SetAircraftPosition(v, v->x_pos, v->y_pos, GetAircraftFlyingAltitude(v));
27a9903a60cb (svn r11546) -Fix[FS#1496]: If ever the air/heli port is suddenly not available while the "chopper" is descending, just go back into flying.
belugas
parents: 8463
diff changeset
  1068
			return false;
27a9903a60cb (svn r11546) -Fix[FS#1496]: If ever the air/heli port is suddenly not available while the "chopper" is descending, just go back into flying.
belugas
parents: 8463
diff changeset
  1069
		}
6890
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1070
	}
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1071
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1072
	/*  get airport moving data */
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1073
	amd = afc->MovingData(v->u.air.pos);
6c53cd7ce903 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6676
diff changeset
  1074
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1075
	int x = TileX(tile) * TILE_SIZE;
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1076
	int y = TileY(tile) * TILE_SIZE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1078
	/* Helicopter raise */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
	if (amd->flag & AMED_HELI_RAISE) {
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: 7986
diff changeset
  1080
		Vehicle *u = v->Next()->Next();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1082
		/* Make sure the rotors don't rotate too fast */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
		if (u->cur_speed > 32) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
			v->cur_speed = 0;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1085
			if (--u->cur_speed == 32) SndPlayVehicleFx(SND_18_HELICOPTER, v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
			u->cur_speed = 32;
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1088
			count = UpdateAircraftSpeed(v);
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1089
			if (count > 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
				v->tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1092
				/* Reached altitude? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
				if (v->z_pos >= 184) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
					v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
					return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
				}
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1097
				SetAircraftPosition(v, v->x_pos, v->y_pos, min(v->z_pos + count, 184));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1103
	/* Helicopter landing. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
	if (amd->flag & AMED_HELI_LOWER) {
9173
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1105
		if (st->airport_tile == 0) {
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1106
			/* FIXME - AircraftController -> if station no longer exists, do not land
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1107
			 * helicopter will circle until sign disappears, then go to next order
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1108
			 * what to do when it is the only order left, right now it just stays in 1 place */
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1109
			v->u.air.state = FLYING;
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1110
			UpdateAircraftCache(v);
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1111
			AircraftNextAirportPos_and_Order(v);
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1112
			return false;
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1113
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
9173
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1115
		/* Vehicle is now at the airport. */
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1116
		v->tile = st->airport_tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
9173
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1118
		/* Find altitude of landing position. */
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1119
		int z = GetSlopeZ(x, y) + 1 + afc->delta_z;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
9173
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1121
		if (z == v->z_pos) {
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1122
			Vehicle *u = v->Next()->Next();
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1123
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1124
			/*  Increase speed of rotors. When speed is 80, we've landed. */
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1125
			if (u->cur_speed >= 80) return true;
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1126
			u->cur_speed += 4;
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1127
		} else {
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1128
			count = UpdateAircraftSpeed(v);
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1129
			if (count > 0) {
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1130
				if (v->z_pos > z) {
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1131
					SetAircraftPosition(v, v->x_pos, v->y_pos, max(v->z_pos - count, z));
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1132
				} else {
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1133
					SetAircraftPosition(v, v->x_pos, v->y_pos, min(v->z_pos + count, z));
057e340d2e26 (svn r12343) -Fix (r12293): Slow helicopters never got the 'chance' to finish the landing routine.
peter1138
parents: 9144
diff changeset
  1134
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1140
	/* Get distance from destination pos to current pos. */
8419
de9999f762d0 (svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
skidd13
parents: 8418
diff changeset
  1141
	uint dist = abs(x + amd->x - v->x_pos) +  abs(y + amd->y - v->y_pos);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1143
	/* Need exact position? */
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1144
	if (!(amd->flag & AMED_EXACTPOS) && dist <= (amd->flag & AMED_SLOWTURN ? 8U : 4U)) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1146
	/* At final pos? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
	if (dist == 0) {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1148
		/* Change direction smoothly to final direction. */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1149
		DirDiff dirdiff = DirDifference(amd->direction, v->direction);
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1150
		/* if distance is 0, and plane points in right direction, no point in calling
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1151
		 * UpdateAircraftSpeed(). So do it only afterwards */
3158
a821c8fec829 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
  1152
		if (dirdiff == DIRDIFF_SAME) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
			v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
			return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
6196
93978efa62c4 (svn r8611) -Fix: Moved the aircraft speed limiting into UpdateAircraftSpeed and enummed some speed limits. This should give a more steady display in the status bar during taxiing
celestar
parents: 6195
diff changeset
  1157
		if (!UpdateAircraftSpeed(v, SPEED_LIMIT_TAXI)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
3158
a821c8fec829 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
  1159
		v->direction = ChangeDir(v->direction, dirdiff > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
		v->cur_speed >>= 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
		SetAircraftPosition(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
  1163
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1166
	uint speed_limit = SPEED_LIMIT_TAXI;
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1167
	bool hard_limit = true;
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1168
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1169
	if (amd->flag & AMED_NOSPDCLAMP)   speed_limit = SPEED_LIMIT_NONE;
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1170
	if (amd->flag & AMED_HOLD)       { speed_limit = SPEED_LIMIT_HOLD;     hard_limit = false; }
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1171
	if (amd->flag & AMED_LAND)       { speed_limit = SPEED_LIMIT_APPROACH; hard_limit = false; }
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1172
	if (amd->flag & AMED_BRAKE)      { speed_limit = SPEED_LIMIT_TAXI;     hard_limit = false; }
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1173
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1174
	count = UpdateAircraftSpeed(v, speed_limit, hard_limit);
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1175
	if (count == 0) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1177
	if (v->load_unload_time_rem != 0) v->load_unload_time_rem--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1179
	do {
6653
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1180
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1181
		GetNewVehiclePosResult gp;
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1182
8396
38c1737936e6 (svn r11451) -Fix [FS#1287]: very fast aircraft would sometimes abruptly stop at the begin of the landing runway, turn a few times and then drive slowly to the end of the runway.
rubidium
parents: 8311
diff changeset
  1183
		if (dist < 4 || amd->flag & AMED_LAND) {
6653
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1184
			/* move vehicle one pixel towards target */
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1185
			gp.x = (v->x_pos != (x + amd->x)) ?
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1186
					v->x_pos + ((x + amd->x > v->x_pos) ? 1 : -1) :
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1187
					v->x_pos;
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1188
			gp.y = (v->y_pos != (y + amd->y)) ?
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1189
					v->y_pos + ((y + amd->y > v->y_pos) ? 1 : -1) :
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1190
					v->y_pos;
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1191
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1192
			/* Oilrigs must keep v->tile as st->airport_tile, since the landing pad is in a non-airport tile */
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1193
			gp.new_tile = (st->airport_type == AT_OILRIG) ? st->airport_tile : TileVirtXY(gp.x, gp.y);
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1194
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1195
		} else {
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1196
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1197
			/* Turn. Do it slowly if in the air. */
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1198
			Direction newdir = GetDirectionTowards(v, x + amd->x, y + amd->y);
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1199
			if (newdir != v->direction) {
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1200
				v->direction = newdir;
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1201
				if (amd->flag & AMED_SLOWTURN) {
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1202
					if (v->load_unload_time_rem == 0) v->load_unload_time_rem = 8;
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1203
				} else {
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1204
					v->cur_speed >>= 1;
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1205
				}
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1206
			}
6653
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1207
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1208
			/* Move vehicle. */
54d7d332d303 (svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents: 6642
diff changeset
  1209
			gp = GetNewVehiclePos(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1212
		v->tile = gp.new_tile;
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1213
		/* If vehicle is in the air, use tile coordinate 0. */
9030
23b6734d71dd (svn r12109) -Fix [FS#1745](r8973): use tile index 0 for planes in the air, so it cannot have an invalid tile index
smatz
parents: 8963
diff changeset
  1214
		if (amd->flag & (AMED_TAKEOFF | AMED_SLOWTURN | AMED_LAND)) v->tile = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1216
		/* Adjust Z for land or takeoff? */
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1217
		uint z = v->z_pos;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1219
		if (amd->flag & AMED_TAKEOFF) {
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1220
			z = min(z + 2, GetAircraftFlyingAltitude(v));
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1221
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1223
		if ((amd->flag & AMED_HOLD) && (z > 150)) z--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1225
		if (amd->flag & AMED_LAND) {
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1226
			if (st->airport_tile == 0) {
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1227
				/* Airport has been removed, abort the landing procedure */
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1228
				v->u.air.state = FLYING;
7086
466f738d31c7 (svn r9804) -Fix (r9761): Update aircraft cached information when its 'pos' changes, as well as 'state'. (Thanks to bulb)
peter1138
parents: 7076
diff changeset
  1229
				UpdateAircraftCache(v);
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1230
				AircraftNextAirportPos_and_Order(v);
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1231
				/* get aircraft back on running altitude */
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1232
				SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v));
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1233
				continue;
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1234
			}
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1235
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1236
			uint curz = GetSlopeZ(x, y) + 1;
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1237
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1238
			if (curz > z) {
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1239
				z++;
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1240
			} else {
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1241
				int t = max(1U, dist - 4);
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1242
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1243
				z -= ((z - curz) + t - 1) / t;
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1244
				if (z < curz) z = curz;
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1245
			}
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1246
		}
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1247
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1248
		/* We've landed. Decrase speed when we're reaching end of runway. */
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1249
		if (amd->flag & AMED_BRAKE) {
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1250
			uint curz = GetSlopeZ(x, y) + 1;
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1251
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1252
			if (z > curz) {
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1253
				z--;
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1254
			} else if (z < curz) {
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1255
				z++;
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1256
			}
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1257
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1258
		}
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1259
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1260
		SetAircraftPosition(v, gp.x, gp.y, z);
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  1261
	} while (--count != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1266
static void HandleCrashedAircraft(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
	v->u.air.crashed_counter++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1269
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1270
	Station *st = GetStation(v->u.air.targetairport);
899
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1271
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1272
	/* make aircraft crash down to the ground */
1150
9ff458b2e574 (svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents: 1139
diff changeset
  1273
	if (v->u.air.crashed_counter < 500 && st->airport_tile==0 && ((v->u.air.crashed_counter % 3) == 0) ) {
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1274
		uint z = GetSlopeZ(v->x_pos, v->y_pos);
899
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1275
		v->z_pos -= 1;
1150
9ff458b2e574 (svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents: 1139
diff changeset
  1276
		if (v->z_pos == z) {
9ff458b2e574 (svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents: 1139
diff changeset
  1277
			v->u.air.crashed_counter = 500;
9ff458b2e574 (svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents: 1139
diff changeset
  1278
			v->z_pos++;
9ff458b2e574 (svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents: 1139
diff changeset
  1279
		}
899
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1280
	}
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1281
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
	if (v->u.air.crashed_counter < 650) {
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1283
		uint32 r;
8463
3920ac0ab803 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 8428
diff changeset
  1284
		if (Chance16R(1,32,r)) {
3160
9201d3f304e0 (svn r3786) More work for DirDiff
tron
parents: 3158
diff changeset
  1285
			static const DirDiff delta[] = {
9201d3f304e0 (svn r3786) More work for DirDiff
tron
parents: 3158
diff changeset
  1286
				DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT
9201d3f304e0 (svn r3786) More work for DirDiff
tron
parents: 3158
diff changeset
  1287
			};
9201d3f304e0 (svn r3786) More work for DirDiff
tron
parents: 3158
diff changeset
  1288
9201d3f304e0 (svn r3786) More work for DirDiff
tron
parents: 3158
diff changeset
  1289
			v->direction = ChangeDir(v->direction, delta[GB(r, 16, 2)]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
			SetAircraftPosition(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
  1291
			r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
			CreateEffectVehicleRel(v,
8196
ce66e31a152c (svn r11234) -Fix [FS#1312]: the explosion vehicles were placed too far to the south.
rubidium
parents: 8191
diff changeset
  1293
				GB(r, 0, 4) - 4,
ce66e31a152c (svn r11234) -Fix [FS#1312]: the explosion vehicles were placed too far to the south.
rubidium
parents: 8191
diff changeset
  1294
				GB(r, 4, 4) - 4,
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: 2133
diff changeset
  1295
				GB(r, 8, 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: 1299
diff changeset
  1296
				EV_EXPLOSION_SMALL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
	} else if (v->u.air.crashed_counter >= 10000) {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1299
		/*  remove rubble of crashed airplane */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1301
		/* clear runway-in on all airports, set by crashing plane
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1302
		 * small airports use AIRPORT_BUSY, city airports use RUNWAY_IN_OUT_block, etc.
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1303
		 * but they all share the same number */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
		CLRBITS(st->airport_flags, RUNWAY_IN_block);
4059
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4056
diff changeset
  1305
		CLRBITS(st->airport_flags, RUNWAY_IN_OUT_block); // commuter airport
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1306
		CLRBITS(st->airport_flags, RUNWAY_IN2_block);    // intercontinental
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
8813
6d054db96ede (svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents: 8806
diff changeset
  1308
		MarkSingleVehicleDirty(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1310
		DoDeleteAircraft(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1312
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1313
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
static void HandleBrokenAircraft(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1315
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1316
	if (v->breakdown_ctr != 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1317
		v->breakdown_ctr = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1318
		v->vehstatus |= VS_AIRCRAFT_BROKEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1319
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1320
		if (v->breakdowns_since_last_service != 255)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1321
			v->breakdowns_since_last_service++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1322
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1323
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1326
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1328
static void HandleAircraftSmoke(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1329
{
2654
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1330
	static const struct {
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1331
		int8 x;
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1332
		int8 y;
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1333
	} smoke_pos[] = {
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1334
		{  5,  5 },
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1335
		{  6,  0 },
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1336
		{  5, -5 },
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1337
		{  0, -6 },
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1338
		{ -5, -5 },
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1339
		{ -6,  0 },
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1340
		{ -5,  5 },
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1341
		{  0,  6 }
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1342
	};
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1343
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1344
	if (!(v->vehstatus & VS_AIRCRAFT_BROKEN)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1345
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1346
	if (v->cur_speed < 10) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
		v->vehstatus &= ~VS_AIRCRAFT_BROKEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1348
		v->breakdown_ctr = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1349
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
	if ((v->tick_counter & 0x1F) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
		CreateEffectVehicleRel(v,
2654
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1354
			smoke_pos[v->direction].x,
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1355
			smoke_pos[v->direction].y,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1356
			2,
1359
8ba976aed634 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1299
diff changeset
  1357
			EV_SMOKE
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1358
		);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
9326
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1362
void HandleMissingAircraftOrders(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1363
{
9326
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1364
	/*
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1365
	 * We do not have an order. This can be divided into two cases:
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1366
	 * 1) we are heading to an invalid station. In this case we must
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1367
	 *    find another airport to go to. If there is nowhere to go,
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1368
	 *    we will destroy the aircraft as it otherwise will enter
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1369
	 *    the holding pattern for the first airport, which can cause
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1370
	 *    the plane to go into an undefined state when building an
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1371
	 *    airport with the same StationID.
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1372
	 * 2) we are (still) heading to a (still) valid airport, then we
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1373
	 *    can continue going there. This can happen when you are
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1374
	 *    changing the aircraft's orders while in-flight or in for
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1375
	 *    example a depot. However, when we have a current order to
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1376
	 *    go to a depot, we have to keep that order so the aircraft
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1377
	 *    actually stops.
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1378
	 */
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1379
	const Station *st = GetStation(v->u.air.targetairport);
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1380
	if (!st->IsValid() || st->airport_tile == 0) {
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1381
		CommandCost ret;
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1382
		PlayerID old_player = _current_player;
3005
db4007baa0ab (svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents: 2989
diff changeset
  1383
9326
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1384
		_current_player = v->owner;
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1385
		ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1386
		_current_player = old_player;
4351
63ae31104f07 (svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents: 4346
diff changeset
  1387
9326
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1388
		if (CmdFailed(ret)) CrashAirplane(v);
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
  1389
	} else if (!v->current_order.IsType(OT_GOTO_DEPOT)) {
9326
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1390
		v->current_order.Free();
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1391
	}
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1392
}
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1393
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1394
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1395
TileIndex Aircraft::GetOrderStationLocation(StationID station)
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1396
{
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1397
	/* Orders are changed in flight, ensure going to the right station. */
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1398
	if (this->u.air.state == FLYING) {
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1399
		AircraftNextAirportPos_and_Order(this);
1151
614cbcb5b9fe (svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents: 1150
diff changeset
  1400
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1401
9326
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1402
	/* Aircraft do not use dest-tile */
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  1403
	return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
7049
01825af2ce90 (svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium
parents: 7048
diff changeset
  1406
void Aircraft::MarkDirty()
3722
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
  1407
{
7630
2cd754d7dfa4 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 7592
diff changeset
  1408
		this->cur_image = this->GetImage(this->direction);
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: 7986
diff changeset
  1409
		if (this->subtype == AIR_HELICOPTER) this->Next()->Next()->cur_image = GetRotorImage(this);
8813
6d054db96ede (svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents: 8806
diff changeset
  1410
		MarkSingleVehicleDirty(this);
3722
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
  1411
}
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
  1412
899
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1413
static void CrashAirplane(Vehicle *v)
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1414
{
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1415
	v->vehstatus |= VS_CRASHED;
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1416
	v->u.air.crashed_counter = 0;
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1417
1359
8ba976aed634 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1299
diff changeset
  1418
	CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
899
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1419
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1420
	InvalidateWindow(WC_VEHICLE_VIEW, v->index);
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1421
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1422
	uint amt = 2;
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
  1423
	if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) amt += v->cargo.Count();
899
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1424
	SetDParam(0, amt);
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1425
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
  1426
	v->cargo.Truncate(0);
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: 7986
diff changeset
  1427
	v->Next()->cargo.Truncate(0);
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1428
	const Station *st = GetStation(v->u.air.targetairport);
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1429
	StringID newsitem;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1430
	if (st->airport_tile == 0) {
899
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1431
		newsitem = STR_PLANE_CRASH_OUT_OF_FUEL;
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1432
	} else {
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1433
		SetDParam(1, st->index);
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1434
		newsitem = STR_A034_PLANE_CRASH_DIE_IN_FIREBALL;
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1435
	}
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1436
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1437
	SetDParam(1, st->index);
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1438
	AddNewsItem(newsitem,
9259
088d3649dd4f (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 9173
diff changeset
  1439
		NM_THIN, NF_VIEWPORT | NF_VEHICLE, NT_ACCIDENT, DNC_NONE,
899
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1440
		v->index,
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1441
		0);
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1442
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1443
	SndPlayVehicleFx(SND_12_EXPLOSION, v);
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1444
}
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1445
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
static void MaybeCrashAirplane(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
{
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1448
	Station *st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1449
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1450
	/* FIXME -- MaybeCrashAirplane -> increase crashing chances of very modern airplanes on smaller than AT_METROPOLITAN airports */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1451
	uint16 prob = 0x10000 / 1500;
6358
e7997742bf02 (svn r8755) -Fix
tron
parents: 6353
diff changeset
  1452
	if (st->Airport()->flags & AirportFTAClass::SHORT_STRIP &&
6351
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
  1453
			AircraftVehInfo(v->engine_type)->subtype & AIR_FAST &&
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
  1454
			!_cheats.no_jetcrash.value) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1455
		prob = 0x10000 / 20;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1456
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1457
2484
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2477
diff changeset
  1458
	if (GB(Random(), 0, 16) > prob) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1460
	/* Crash the airplane. Remove all goods stored at the station. */
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6666
diff changeset
  1461
	for (CargoID i = 0; i < NUM_CARGO; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1462
		st->goods[i].rating = 1;
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7486
diff changeset
  1463
		st->goods[i].cargo.Truncate(0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
899
93b0626ddfce (svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents: 842
diff changeset
  1466
	CrashAirplane(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1469
/** we've landed and just arrived at a terminal */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1470
static void AircraftEntersTerminal(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
{
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
  1472
	if (v->current_order.IsType(OT_GOTO_DEPOT)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1473
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1474
	Station *st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
	v->last_station_visited = v->u.air.targetairport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1476
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
	/* Check if station was ever visited before */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
	if (!(st->had_vehicle_of_type & HVOT_AIRCRAFT)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1479
		st->had_vehicle_of_type |= HVOT_AIRCRAFT;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1480
		SetDParam(0, st->index);
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1481
		/* show newsitem of celebrating citizens */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
		AddNewsItem(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1483
			STR_A033_CITIZENS_CELEBRATE_FIRST,
9259
088d3649dd4f (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 9173
diff changeset
  1484
			NM_THIN, NF_VIEWPORT | NF_VEHICLE, (v->owner == _local_player) ? NT_ARRIVAL_PLAYER : NT_ARRIVAL_OTHER, DNC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1485
			v->index,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1486
			0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1487
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1488
5902
906fea1535ab (svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents: 5852
diff changeset
  1489
	v->BeginLoading();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1490
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1491
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1492
static void AircraftLandAirplane(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1493
{
7054
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
  1494
	v->UpdateDeltaXY(INVALID_DIR);
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
  1495
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4574
diff changeset
  1496
	if (!PlayVehicleSound(v, VSE_TOUCHDOWN)) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4574
diff changeset
  1497
		SndPlayVehicleFx(SND_17_SKID_PLANE, v);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4574
diff changeset
  1498
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1499
	MaybeCrashAirplane(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1500
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1501
6362
f4de72f0abea (svn r8759) -Feature: Allow airports to have up to 4 entry points depending on approach direction. Note: they're not yet used, but will be soon
celestar
parents: 6358
diff changeset
  1502
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1503
/** set the right pos when heading to other airports after takeoff */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1504
static void AircraftNextAirportPos_and_Order(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1505
{
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
  1506
	if (v->current_order.IsType(OT_GOTO_STATION) ||
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
  1507
			v->current_order.IsType(OT_GOTO_DEPOT))
9336
3f75a2c5e0d3 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 9332
diff changeset
  1508
		v->u.air.targetairport = v->current_order.GetDestination();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1509
6358
e7997742bf02 (svn r8755) -Fix
tron
parents: 6353
diff changeset
  1510
	const AirportFTAClass *apc = GetStation(v->u.air.targetairport)->Airport();
6362
f4de72f0abea (svn r8759) -Feature: Allow airports to have up to 4 entry points depending on approach direction. Note: they're not yet used, but will be soon
celestar
parents: 6358
diff changeset
  1511
	v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, apc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1512
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1513
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
static void AircraftLeaveHangar(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
	v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1517
	v->subspeed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1518
	v->progress = 0;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5836
diff changeset
  1519
	v->direction = DIR_SE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1520
	v->vehstatus &= ~VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1521
	{
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: 7986
diff changeset
  1522
		Vehicle *u = v->Next();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1523
		u->vehstatus &= ~VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1524
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1525
		/* Rotor blades */
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: 7986
diff changeset
  1526
		u = u->Next();
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1527
		if (u != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1528
			u->vehstatus &= ~VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1529
			u->cur_speed = 80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1530
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1531
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1532
578
86e352980acd (svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents: 555
diff changeset
  1533
	VehicleServiceInDepot(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1534
	SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos);
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4732
diff changeset
  1535
	InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
1055
3aae1d6f12aa (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
  1536
	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1537
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1538
8806
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1539
/** Checks if an aircraft should head towards a hangar because it needs replacement
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1540
 * @param *v the vehicle to test
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1541
 * @return true if the aircraft should head towards a hangar
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1542
 */
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1543
static inline bool CheckSendAircraftToHangarForReplacement(const Vehicle *v)
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1544
{
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1545
	EngineID new_engine;
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1546
	Player *p = GetPlayer(v->owner);
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1547
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1548
	if (VehicleHasDepotOrders(v)) return false; // The aircraft will end up in the hangar eventually on it's own
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1549
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1550
	new_engine = EngineReplacementForPlayer(p, v->engine_type, v->group_id);
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1551
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1552
	if (new_engine == INVALID_ENGINE) {
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1553
		/* There is no autoreplace assigned to this EngineID so we will set it to renew to the same type if needed */
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1554
		new_engine = v->engine_type;
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1555
9124
eea8af2b73a8 (svn r12230) -Codechange: [autoreplace] made a function to detect if a vehicle needs autorenewing
bjarni
parents: 9062
diff changeset
  1556
		if (!v->NeedsAutorenewing(p)) {
8806
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1557
			/* No need to replace the aircraft */
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1558
			return false;
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1559
		}
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1560
	}
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1561
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1562
	if (!HasBit(GetEngine(new_engine)->player_avail, v->owner)) {
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1563
		/* Engine is not buildable anymore */
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1564
		return false;
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1565
	}
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1566
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1567
	if (p->player_money < (p->engine_renew_money + (2 * DoCommand(0, new_engine, 0, DC_QUERY_COST, CMD_BUILD_AIRCRAFT).GetCost()))) {
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1568
		/* We lack enough money to request the replacement right away.
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1569
		 * We want 2*(the price of the new vehicle) and not looking at the value of the vehicle we are going to sell.
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1570
		 * The reason is that we don't want to send a whole lot of vehicles to the hangars when we only have enough money to replace a single one.
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1571
		 * Remember this happens in the background so the user can't stop this. */
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1572
		return false;
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1573
	}
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1574
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1575
	/* We found no reason NOT to send the aircraft to a hangar so we will send it there at once */
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1576
	return true;
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1577
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1578
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1579
////////////////////////////////////////////////////////////////////////////////
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1580
///////////////////   AIRCRAFT MOVEMENT SCHEME  ////////////////////////////////
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1581
////////////////////////////////////////////////////////////////////////////////
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1582
static void AircraftEventHandler_EnterTerminal(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1583
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1584
	AircraftEntersTerminal(v);
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1585
	v->u.air.state = apc->layout[v->u.air.pos].heading;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1586
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1587
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1588
static void AircraftEventHandler_EnterHangar(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1589
{
4725
f7284b86833f (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  1590
	VehicleEnterDepot(v);
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1591
	v->u.air.state = apc->layout[v->u.air.pos].heading;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1592
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1593
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1594
/** In an Airport Hangar */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1595
static void AircraftEventHandler_InHangar(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1596
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1597
	/* if we just arrived, execute EnterHangar first */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1598
	if (v->u.air.previous_pos != v->u.air.pos) {
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1599
		AircraftEventHandler_EnterHangar(v, apc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1600
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1601
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1602
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1603
	/* if we were sent to the depot, stay there */
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
  1604
	if (v->current_order.IsType(OT_GOTO_DEPOT) && (v->vehstatus & VS_STOPPED)) {
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
  1605
		v->current_order.Free();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1606
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1607
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1608
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
  1609
	if (!v->current_order.IsType(OT_GOTO_STATION) &&
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
  1610
			!v->current_order.IsType(OT_GOTO_DEPOT))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1611
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1612
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1613
	/* if the block of the next position is busy, stay put */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1614
	if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1615
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1616
	/* We are already at the target airport, we need to find a terminal */
9336
3f75a2c5e0d3 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 9332
diff changeset
  1617
	if (v->current_order.GetDestination() == v->u.air.targetairport) {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1618
		/* FindFreeTerminal:
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1619
		 * 1. Find a free terminal, 2. Occupy it, 3. Set the vehicle's state to that terminal */
6105
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
  1620
		if (v->subtype == AIR_HELICOPTER) {
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
  1621
			if (!AirportFindFreeHelipad(v, apc)) return; // helicopter
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
  1622
		} else {
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1623
			if (!AirportFindFreeTerminal(v, apc)) return; // airplane
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  1624
		}
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  1625
	} else { // Else prepare for launch.
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1626
		/* airplane goto state takeoff, helicopter to helitakeoff */
6105
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
  1627
		v->u.air.state = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : TAKEOFF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1628
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1629
	AircraftLeaveHangar(v);
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1630
	AirportMove(v, apc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1631
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1632
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1633
/** At one of the Airport's Terminals */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1634
static void AircraftEventHandler_AtTerminal(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1635
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1636
	/* if we just arrived, execute EnterTerminal first */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1637
	if (v->u.air.previous_pos != v->u.air.pos) {
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1638
		AircraftEventHandler_EnterTerminal(v, apc);
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1639
		/* on an airport with helipads, a helicopter will always land there
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1640
		 * and get serviced at the same time - patch setting */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1641
		if (_patches.serviceathelipad) {
6105
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
  1642
			if (v->subtype == AIR_HELICOPTER && apc->helipads != NULL) {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1643
				/* an exerpt of ServiceAircraft, without the invisibility stuff */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
				v->date_of_last_service = _date;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
				v->breakdowns_since_last_service = 0;
1926
68d60188a22f (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1901
diff changeset
  1646
				v->reliability = GetEngine(v->engine_type)->reliability;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1647
				InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1648
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1649
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1650
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1651
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1652
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
  1653
	if (!v->current_order.IsValid()) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1654
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1655
	/* if the block of the next position is busy, stay put */
4843
724322df355a (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
  1656
	if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1657
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1658
	/* airport-road is free. We either have to go to another airport, or to the hangar
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1659
	 * ---> start moving */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1660
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
  1661
	switch (v->current_order.GetType()) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1662
		case OT_GOTO_STATION: // ready to fly to another airport
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1663
			/* airplane goto state takeoff, helicopter to helitakeoff */
6105
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
  1664
			v->u.air.state = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : TAKEOFF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1665
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1666
		case OT_GOTO_DEPOT:   // visit hangar for serivicing, sale, etc.
9336
3f75a2c5e0d3 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 9332
diff changeset
  1667
			if (v->current_order.GetDestination() == v->u.air.targetairport) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1668
				v->u.air.state = HANGAR;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1669
			} else {
6105
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6005
diff changeset
  1670
				v->u.air.state = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : TAKEOFF;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1671
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1672
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1673
		default:  // orders have been deleted (no orders), goto depot and don't bother us
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
  1674
			v->current_order.Free();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1675
			v->u.air.state = HANGAR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1676
	}
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1677
	AirportMove(v, apc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1678
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1679
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1680
static void AircraftEventHandler_General(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1681
{
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5259
diff changeset
  1682
	assert("OK, you shouldn't be here, check your Airport Scheme!" && 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1683
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1684
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1685
static void AircraftEventHandler_TakeOff(Vehicle *v, const AirportFTAClass *apc)
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1686
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1687
	PlayAircraftSound(v); // play takeoffsound for airplanes
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1688
	v->u.air.state = STARTTAKEOFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1689
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1690
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1691
static void AircraftEventHandler_StartTakeOff(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1692
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1693
	v->u.air.state = ENDTAKEOFF;
7054
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
  1694
	v->UpdateDeltaXY(INVALID_DIR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1695
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1696
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1697
static void AircraftEventHandler_EndTakeOff(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1698
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1699
	v->u.air.state = FLYING;
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1700
	/* get the next position to go to, differs per airport */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1701
	AircraftNextAirportPos_and_Order(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1702
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1703
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1704
static void AircraftEventHandler_HeliTakeOff(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1705
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1706
	v->u.air.state = FLYING;
7054
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
  1707
	v->UpdateDeltaXY(INVALID_DIR);
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
  1708
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1709
	/* get the next position to go to, differs per airport */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1710
	AircraftNextAirportPos_and_Order(v);
1135
b939a3c018eb (svn r1636) fix: helicopters now go to a hangar if they are set for replacement or needs to be renewed
bjarni
parents: 1128
diff changeset
  1711
8806
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1712
	/* Send the helicopter to a hangar if needed for replacement */
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1713
	if (CheckSendAircraftToHangarForReplacement(v)) {
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1714
		_current_player = v->owner;
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1715
		DoCommand(v->tile, v->index, DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
1520
c85dc79795e0 (svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents: 1401
diff changeset
  1716
		_current_player = OWNER_NONE;
1135
b939a3c018eb (svn r1636) fix: helicopters now go to a hangar if they are set for replacement or needs to be renewed
bjarni
parents: 1128
diff changeset
  1717
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1718
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1719
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1720
static void AircraftEventHandler_Flying(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1721
{
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1722
	Station *st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1723
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1724
	/* runway busy or not allowed to use this airstation, circle */
6353
75b086ef8ef1 (svn r8750) -Fix (r8747): PLANES defined in wingdi.h caused compilation error under Win32. Changed to AIRPLANES
KUDr
parents: 6351
diff changeset
  1725
	if (apc->flags & (v->subtype == AIR_HELICOPTER ? AirportFTAClass::HELICOPTERS : AirportFTAClass::AIRPLANES) &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1726
			st->airport_tile != 0 &&
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1727
			(st->owner == OWNER_NONE || st->owner == v->owner)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1728
		// {32,FLYING,NOTHING_block,37}, {32,LANDING,N,33}, {32,HELILANDING,N,41},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1729
		// if it is an airplane, look for LANDING, for helicopter HELILANDING
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1730
		// it is possible to choose from multiple landing runways, so loop until a free one is found
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1731
		byte landingtype = (v->subtype == AIR_HELICOPTER) ? HELILANDING : LANDING;
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1732
		const AirportFTA *current = apc->layout[v->u.air.pos].next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1733
		while (current != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1734
			if (current->heading == landingtype) {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1735
				/* save speed before, since if AirportHasBlock is false, it resets them to 0
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1736
				 * we don't want that for plane in air
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1737
				 * hack for speed thingie */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1738
				uint16 tcur_speed = v->cur_speed;
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1739
				uint16 tsubspeed = v->subspeed;
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1740
				if (!AirportHasBlock(v, current, apc)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1741
					v->u.air.state = landingtype; // LANDING / HELILANDING
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1742
					/* it's a bit dirty, but I need to set position to next position, otherwise
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1743
					 * if there are multiple runways, plane won't know which one it took (because
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1744
					 * they all have heading LANDING). And also occupy that block! */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1745
					v->u.air.pos = current->next_position;
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1746
					SETBITS(st->airport_flags, apc->layout[v->u.air.pos].block);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1747
					return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1748
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1749
				v->cur_speed = tcur_speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1750
				v->subspeed = tsubspeed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
			}
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1752
			current = current->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1753
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1754
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1755
	v->u.air.state = FLYING;
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1756
	v->u.air.pos = apc->layout[v->u.air.pos].next_position;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1757
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1758
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1759
static void AircraftEventHandler_Landing(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
{
7054
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
  1761
	v->u.air.state = ENDLANDING;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1762
	AircraftLandAirplane(v);  // maybe crash airplane
7054
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
  1763
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1764
	/* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */
8806
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1765
	if (CheckSendAircraftToHangarForReplacement(v)) {
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1766
		_current_player = v->owner;
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1767
		DoCommand(v->tile, v->index, DEPOT_SERVICE, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
221b42031684 (svn r11875) -Fix: automatically sending aircraft to depot for autoreplace/renew is now triggered by the correct conditions
bjarni
parents: 8798
diff changeset
  1768
		_current_player = OWNER_NONE;
1195
95bbeb74ca13 (svn r1699) - Feature [autoreplace] a plane will now go to the hangar right after landing if it needs to be replaced
bjarni
parents: 1194
diff changeset
  1769
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1770
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1771
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1772
static void AircraftEventHandler_HeliLanding(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1773
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1774
	v->u.air.state = HELIENDLANDING;
7054
edbb4d7765f2 (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 7049
diff changeset
  1775
	v->UpdateDeltaXY(INVALID_DIR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1776
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1777
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1778
static void AircraftEventHandler_EndLanding(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1779
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1780
	/* next block busy, don't do a thing, just wait */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1781
	if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1782
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1783
	/* if going to terminal (OT_GOTO_STATION) choose one
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1784
	 * 1. in case all terminals are busy AirportFindFreeTerminal() returns false or
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1785
	 * 2. not going for terminal (but depot, no order),
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1786
	 * --> get out of the way to the hangar. */
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
  1787
	if (v->current_order.IsType(OT_GOTO_STATION)) {
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1788
		if (AirportFindFreeTerminal(v, apc)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1789
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1790
	v->u.air.state = HANGAR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1791
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1792
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1793
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1794
static void AircraftEventHandler_HeliEndLanding(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1795
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1796
	/*  next block busy, don't do a thing, just wait */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1797
	if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1798
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1799
	/* if going to helipad (OT_GOTO_STATION) choose one. If airport doesn't have helipads, choose terminal
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1800
	 * 1. in case all terminals/helipads are busy (AirportFindFreeHelipad() returns false) or
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1801
	 * 2. not going for terminal (but depot, no order),
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1802
	 * --> get out of the way to the hangar IF there are terminals on the airport.
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1803
	 * --> else TAKEOFF
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1804
	 * the reason behind this is that if an airport has a terminal, it also has a hangar. Airplanes
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1805
	 * must go to a hangar. */
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
  1806
	if (v->current_order.IsType(OT_GOTO_STATION)) {
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1807
		if (AirportFindFreeHelipad(v, apc)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1808
	}
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1809
	v->u.air.state = (apc->nof_depots != 0) ? HANGAR : HELITAKEOFF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1810
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1811
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1812
typedef void AircraftStateHandler(Vehicle *v, const AirportFTAClass *apc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1813
static AircraftStateHandler * const _aircraft_state_handlers[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1814
	AircraftEventHandler_General,        // TO_ALL         =  0
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1815
	AircraftEventHandler_InHangar,       // HANGAR         =  1
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1816
	AircraftEventHandler_AtTerminal,     // TERM1          =  2
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1817
	AircraftEventHandler_AtTerminal,     // TERM2          =  3
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1818
	AircraftEventHandler_AtTerminal,     // TERM3          =  4
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1819
	AircraftEventHandler_AtTerminal,     // TERM4          =  5
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1820
	AircraftEventHandler_AtTerminal,     // TERM5          =  6
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1821
	AircraftEventHandler_AtTerminal,     // TERM6          =  7
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1822
	AircraftEventHandler_AtTerminal,     // HELIPAD1       =  8
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1823
	AircraftEventHandler_AtTerminal,     // HELIPAD2       =  9
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1824
	AircraftEventHandler_TakeOff,        // TAKEOFF        = 10
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1825
	AircraftEventHandler_StartTakeOff,   // STARTTAKEOFF   = 11
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1826
	AircraftEventHandler_EndTakeOff,     // ENDTAKEOFF     = 12
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1827
	AircraftEventHandler_HeliTakeOff,    // HELITAKEOFF    = 13
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1828
	AircraftEventHandler_Flying,         // FLYING         = 14
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1829
	AircraftEventHandler_Landing,        // LANDING        = 15
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1830
	AircraftEventHandler_EndLanding,     // ENDLANDING     = 16
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1831
	AircraftEventHandler_HeliLanding,    // HELILANDING    = 17
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1832
	AircraftEventHandler_HeliEndLanding, // HELIENDLANDING = 18
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1833
	AircraftEventHandler_AtTerminal,     // TERM7          = 19
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1834
	AircraftEventHandler_AtTerminal,     // TERM8          = 20
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1835
	AircraftEventHandler_AtTerminal,     // HELIPAD3       = 21
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1836
	AircraftEventHandler_AtTerminal,     // HELIPAD4       = 22
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1837
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1838
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1839
static void AirportClearBlock(const Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1840
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1841
	/* we have left the previous block, and entered the new one. Free the previous block */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1842
	if (apc->layout[v->u.air.previous_pos].block != apc->layout[v->u.air.pos].block) {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4338
diff changeset
  1843
		Station *st = GetStation(v->u.air.targetairport);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1844
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1845
		CLRBITS(st->airport_flags, apc->layout[v->u.air.previous_pos].block);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1846
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1847
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1848
6425
0af66a18da06 (svn r8834) -Fix
tron
parents: 6413
diff changeset
  1849
static void AirportGoToNextPosition(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1850
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1851
	/* if aircraft is not in position, wait until it is */
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  1852
	if (!AircraftController(v)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1853
6425
0af66a18da06 (svn r8834) -Fix
tron
parents: 6413
diff changeset
  1854
	const AirportFTAClass *apc = GetStation(v->u.air.targetairport)->Airport();
0af66a18da06 (svn r8834) -Fix
tron
parents: 6413
diff changeset
  1855
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1856
	AirportClearBlock(v, apc);
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1857
	AirportMove(v, apc); // move aircraft to next position
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1858
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1859
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1860
/* gets pos from vehicle and next orders */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1861
static bool AirportMove(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1862
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1863
	/* error handling */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1864
	if (v->u.air.pos >= apc->nofelements) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5259
diff changeset
  1865
		DEBUG(misc, 0, "[Ap] position %d is not valid for current airport. Max position is %d", v->u.air.pos, apc->nofelements-1);
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1866
		assert(v->u.air.pos < apc->nofelements);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1867
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1868
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1869
	const AirportFTA *current = &apc->layout[v->u.air.pos];
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1870
	/* we have arrived in an important state (eg terminal, hangar, etc.) */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1871
	if (current->heading == v->u.air.state) {
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1872
		byte prev_pos = v->u.air.pos; // location could be changed in state, so save it before-hand
6986
168d3add1f13 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6949
diff changeset
  1873
		byte prev_state = v->u.air.state;
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1874
		_aircraft_state_handlers[v->u.air.state](v, apc);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  1875
		if (v->u.air.state != FLYING) v->u.air.previous_pos = prev_pos;
7086
466f738d31c7 (svn r9804) -Fix (r9761): Update aircraft cached information when its 'pos' changes, as well as 'state'. (Thanks to bulb)
peter1138
parents: 7076
diff changeset
  1876
		if (v->u.air.state != prev_state || v->u.air.pos != prev_pos) UpdateAircraftCache(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1877
		return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1878
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1879
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1880
	v->u.air.previous_pos = v->u.air.pos; // save previous location
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1881
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1882
	/* there is only one choice to move to */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1883
	if (current->next == NULL) {
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1884
		if (AirportSetBlocks(v, current, apc)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1885
			v->u.air.pos = current->next_position;
7086
466f738d31c7 (svn r9804) -Fix (r9761): Update aircraft cached information when its 'pos' changes, as well as 'state'. (Thanks to bulb)
peter1138
parents: 7076
diff changeset
  1886
			UpdateAircraftCache(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1887
		} // move to next position
3579
8885d65a2ba7 (svn r4465) -Codechange (FS#60): Remove a variable no one really needs. (DaleStan)
celestar
parents: 3491
diff changeset
  1888
		return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1889
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1890
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1891
	/* there are more choices to choose from, choose the one that
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1892
	 * matches our heading */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1893
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1894
		if (v->u.air.state == current->heading || current->heading == TO_ALL) {
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1895
			if (AirportSetBlocks(v, current, apc)) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1896
				v->u.air.pos = current->next_position;
7086
466f738d31c7 (svn r9804) -Fix (r9761): Update aircraft cached information when its 'pos' changes, as well as 'state'. (Thanks to bulb)
peter1138
parents: 7076
diff changeset
  1897
				UpdateAircraftCache(v);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1898
			} // move to next position
3579
8885d65a2ba7 (svn r4465) -Codechange (FS#60): Remove a variable no one really needs. (DaleStan)
celestar
parents: 3491
diff changeset
  1899
			return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1900
		}
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1901
		current = current->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1902
	} while (current != NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1903
6362
f4de72f0abea (svn r8759) -Feature: Allow airports to have up to 4 entry points depending on approach direction. Note: they're not yet used, but will be soon
celestar
parents: 6358
diff changeset
  1904
	DEBUG(misc, 0, "[Ap] cannot move further on Airport! (pos %d state %d) for vehicle %d", v->u.air.pos, v->u.air.state, v->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1905
	assert(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1906
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1907
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1908
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1909
/*  returns true if the road ahead is busy, eg. you must wait before proceeding */
4843
724322df355a (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
  1910
static bool AirportHasBlock(Vehicle *v, const AirportFTA *current_pos, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1911
{
4843
724322df355a (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
  1912
	const AirportFTA *reference = &apc->layout[v->u.air.pos];
724322df355a (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
  1913
	const AirportFTA *next = &apc->layout[current_pos->next_position];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1915
	/* same block, then of course we can move */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1916
	if (apc->layout[current_pos->position].block != next->block) {
4843
724322df355a (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
  1917
		const Station *st = GetStation(v->u.air.targetairport);
6337
6f3f247870f1 (svn r8733) -Fix(r8705): Forgot to change some more places where airport blocks are stored
celestar
parents: 6322
diff changeset
  1918
		uint64 airport_flags = next->block;
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2618
diff changeset
  1919
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1920
		/* check additional possible extra blocks */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1921
		if (current_pos != reference && current_pos->block != NOTHING_block) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1922
			airport_flags |= current_pos->block;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1923
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1924
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
		if (HASBITS(st->airport_flags, airport_flags)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1926
			v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1927
			v->subspeed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1928
			return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1930
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1931
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1932
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1933
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1934
/**
6905
c0a93961678a (svn r9545) -Documentation: Some corrections to previous doxygen work
belugas
parents: 6903
diff changeset
  1935
 * "reserve" a block for the plane
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1936
 * @param v airplane that requires the operation
6905
c0a93961678a (svn r9545) -Documentation: Some corrections to previous doxygen work
belugas
parents: 6903
diff changeset
  1937
 * @param current_pos of the vehicle in the list of blocks
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1938
 * @param apc airport on which block is requsted to be set
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1939
 * @returns true on success. Eg, next block was free and we have occupied it
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1940
 */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1941
static bool AirportSetBlocks(Vehicle *v, const AirportFTA *current_pos, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1942
{
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1943
	const AirportFTA *next = &apc->layout[current_pos->next_position];
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1944
	const AirportFTA *reference = &apc->layout[v->u.air.pos];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1945
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1946
	/* if the next position is in another block, check it and wait until it is free */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1947
	if ((apc->layout[current_pos->position].block & next->block) != next->block) {
6337
6f3f247870f1 (svn r8733) -Fix(r8705): Forgot to change some more places where airport blocks are stored
celestar
parents: 6322
diff changeset
  1948
		uint64 airport_flags = next->block;
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1949
		/* search for all all elements in the list with the same state, and blocks != N
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1950
		 * this means more blocks should be checked/set */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1951
		const AirportFTA *current = current_pos;
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1952
		if (current == reference) current = current->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1953
		while (current != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1954
			if (current->heading == current_pos->heading && current->block != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1955
				airport_flags |= current->block;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1956
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1957
			}
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1958
			current = current->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1959
		};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1960
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1961
		/* if the block to be checked is in the next position, then exclude that from
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1962
		 * checking, because it has been set by the airplane before */
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  1963
		if (current_pos->block == next->block) airport_flags ^= next->block;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1964
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1965
		Station* st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1966
		if (HASBITS(st->airport_flags, airport_flags)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1967
			v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1968
			v->subspeed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1969
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1970
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1971
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1972
		if (next->block != NOTHING_block) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1973
			SETBITS(st->airport_flags, airport_flags); // occupy next block
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1974
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1975
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1976
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1977
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1978
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1979
static bool FreeTerminal(Vehicle *v, byte i, byte last_terminal)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1980
{
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1981
	Station *st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1982
	for (; i < last_terminal; i++) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8419
diff changeset
  1983
		if (!HasBit(st->airport_flags, _airport_terminal_flag[i])) {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1984
			/* TERMINAL# HELIPAD# */
4059
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4056
diff changeset
  1985
			v->u.air.state = _airport_terminal_state[i]; // start moving to that terminal/helipad
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  1986
			SetBit(st->airport_flags, _airport_terminal_flag[i]); // occupy terminal/helipad
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1987
			return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1988
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1989
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1990
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1991
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1992
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1993
static uint GetNumTerminals(const AirportFTAClass *apc)
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1994
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1995
	uint num = 0;
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1018
diff changeset
  1996
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1997
	for (uint i = apc->terminals[0]; i > 0; i--) num += apc->terminals[i];
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1018
diff changeset
  1998
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1999
	return num;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2000
}
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2001
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2002
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2003
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2004
	/* example of more terminalgroups
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4546
diff changeset
  2005
	 * {0,HANGAR,NOTHING_block,1}, {0,255,TERM_GROUP1_block,0}, {0,255,TERM_GROUP2_ENTER_block,1}, {0,0,N,1},
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4546
diff changeset
  2006
	 * Heading 255 denotes a group. We see 2 groups here:
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4546
diff changeset
  2007
	 * 1. group 0 -- TERM_GROUP1_block (check block)
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4546
diff changeset
  2008
	 * 2. group 1 -- TERM_GROUP2_ENTER_block (check block)
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4546
diff changeset
  2009
	 * First in line is checked first, group 0. If the block (TERM_GROUP1_block) is free, it
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4546
diff changeset
  2010
	 * looks at the corresponding terminals of that group. If no free ones are found, other
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4546
diff changeset
  2011
	 * possible groups are checked (in this case group 1, since that is after group 0). If that
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4546
diff changeset
  2012
	 * fails, then attempt fails and plane waits
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4546
diff changeset
  2013
	 */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2014
	if (apc->terminals[0] > 1) {
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2015
		const Station *st = GetStation(v->u.air.targetairport);
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2016
		const AirportFTA *temp = apc->layout[v->u.air.pos].next;
4843
724322df355a (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
  2017
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2018
		while (temp != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2019
			if (temp->heading == 255) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2020
				if (!HASBITS(st->airport_flags, temp->block)) {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2021
					/* read which group do we want to go to?
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2022
					 * (the first free group) */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2023
					uint target_group = temp->next_position + 1;
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2024
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2025
					/* at what terminal does the group start?
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2026
					 * that means, sum up all terminals of
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2027
					 * groups with lower number */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2028
					uint group_start = 0;
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2029
					for (uint i = 1; i < target_group; i++) {
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2030
						group_start += apc->terminals[i];
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2031
					}
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2032
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2033
					uint group_end = group_start + apc->terminals[target_group];
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2034
					if (FreeTerminal(v, group_start, group_end)) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2035
				}
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2036
			} else {
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2037
				/* once the heading isn't 255, we've exhausted the possible blocks.
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2038
				 * So we cannot move */
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2039
				return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2040
			}
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2041
			temp = temp->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2042
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2043
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2044
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2045
	/* if there is only 1 terminalgroup, all terminals are checked (starting from 0 to max) */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2046
	return FreeTerminal(v, 0, GetNumTerminals(apc));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2047
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2048
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2049
static uint GetNumHelipads(const AirportFTAClass *apc)
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2050
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  2051
	uint num = 0;
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1018
diff changeset
  2052
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2053
	for (uint i = apc->helipads[0]; i > 0; i--) num += apc->helipads[i];
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1018
diff changeset
  2054
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2055
	return num;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2056
}
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2057
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2058
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2059
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2060
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2061
	/* if an airport doesn't have helipads, use terminals */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2062
	if (apc->helipads == NULL) return AirportFindFreeTerminal(v, apc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2063
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2064
	/* if there are more helicoptergroups, pick one, just as in AirportFindFreeTerminal() */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2065
	if (apc->helipads[0] > 1) {
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4072
diff changeset
  2066
		const Station* st = GetStation(v->u.air.targetairport);
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2067
		const AirportFTA* temp = apc->layout[v->u.air.pos].next;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4072
diff changeset
  2068
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2069
		while (temp != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2070
			if (temp->heading == 255) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2071
				if (!HASBITS(st->airport_flags, temp->block)) {
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2072
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2073
					/* read which group do we want to go to?
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2074
					 * (the first free group) */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2075
					uint target_group = temp->next_position + 1;
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2076
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2077
					/* at what terminal does the group start?
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2078
					 * that means, sum up all terminals of
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2079
					 * groups with lower number */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2080
					uint group_start = 0;
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2081
					for (uint i = 1; i < target_group; i++) {
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2082
						group_start += apc->helipads[i];
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2083
					}
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2084
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2085
					uint group_end = group_start + apc->helipads[target_group];
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2086
					if (FreeTerminal(v, group_start, group_end)) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2087
				}
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2088
			} else {
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2089
				/* once the heading isn't 255, we've exhausted the possible blocks.
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2090
				 * So we cannot move */
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2091
				return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2092
			}
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2093
			temp = temp->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2094
		}
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2095
	} else {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2096
		/* only 1 helicoptergroup, check all helipads
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2097
		 * The blocks for helipads start after the last terminal (MAX_TERMINALS) */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2098
		return FreeTerminal(v, MAX_TERMINALS, GetNumHelipads(apc) + MAX_TERMINALS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2099
	}
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4412
diff changeset
  2100
	return false; // it shouldn't get here anytime, but just to be sure
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2101
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2102
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2103
static void AircraftEventHandler(Vehicle *v, int loop)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2104
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2105
	v->tick_counter++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2106
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2107
	if (v->vehstatus & VS_CRASHED) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2108
		HandleCrashedAircraft(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2109
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2110
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2111
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  2112
	if (v->vehstatus & VS_STOPPED) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2113
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2114
	/* aircraft is broken down? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2115
	if (v->breakdown_ctr != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2116
		if (v->breakdown_ctr <= 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2117
			HandleBrokenAircraft(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2118
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2119
			v->breakdown_ctr--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2120
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2121
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2122
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2123
	HandleAircraftSmoke(v);
9326
326baf219dda (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium
parents: 9289
diff changeset
  2124
	ProcessOrders(v);
7090
8e4a4ac64b2d (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 7088
diff changeset
  2125
	v->HandleLoading(loop != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2126
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9326
diff changeset
  2127
	if (v->current_order.IsType(OT_LOADING) || v->current_order.IsType(OT_LEAVESTATION)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2128
6425
0af66a18da06 (svn r8834) -Fix
tron
parents: 6413
diff changeset
  2129
	AirportGoToNextPosition(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2130
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2131
7631
e810ef25497e (svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium
parents: 7630
diff changeset
  2132
void Aircraft::Tick()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2133
{
7631
e810ef25497e (svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium
parents: 7630
diff changeset
  2134
	if (!IsNormalAircraft(this)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2135
9052
392f5995d323 (svn r12134) -Change: count the number of ticks a vehicle was running this day to calculate running cost
smatz
parents: 9030
diff changeset
  2136
	if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++;
392f5995d323 (svn r12134) -Change: count the number of ticks a vehicle was running this day to calculate running cost
smatz
parents: 9030
diff changeset
  2137
7631
e810ef25497e (svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium
parents: 7630
diff changeset
  2138
	if (this->subtype == AIR_HELICOPTER) HelicopterTickHandler(this);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2139
7631
e810ef25497e (svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium
parents: 7630
diff changeset
  2140
	AgeAircraftCargo(this);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2141
9274
ea5aab96fdcc (svn r12477) -Fix [FS#1883]: timetable times for aircraft were always doubled.
rubidium
parents: 9259
diff changeset
  2142
	this->current_order_time++;
ea5aab96fdcc (svn r12477) -Fix [FS#1883]: timetable times for aircraft were always doubled.
rubidium
parents: 9259
diff changeset
  2143
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6502
diff changeset
  2144
	for (uint i = 0; i != 2; i++) {
7631
e810ef25497e (svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium
parents: 7630
diff changeset
  2145
		AircraftEventHandler(this, i);
e810ef25497e (svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium
parents: 7630
diff changeset
  2146
		if (this->type != VEH_AIRCRAFT) // In case it was deleted
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2147
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2148
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2149
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2150
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2151
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2152
/** need to be called to load aircraft from old version */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6563
diff changeset
  2153
void UpdateOldAircraft()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2154
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2155
	/* set airport_flags to 0 for all airports just to be sure */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2156
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2157
	FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2158
		st->airport_flags = 0; // reset airport
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2159
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2160
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2161
	Vehicle *v_oldstyle;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2162
	FOR_ALL_VEHICLES(v_oldstyle) {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2163
	/* airplane has another vehicle with subtype 4 (shadow), helicopter also has 3 (rotor)
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2164
	 * skip those */
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
  2165
		if (v_oldstyle->type == VEH_AIRCRAFT && IsNormalAircraft(v_oldstyle)) {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2166
			/* airplane in terminal stopped doesn't hurt anyone, so goto next */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  2167
			if (v_oldstyle->vehstatus & VS_STOPPED && v_oldstyle->u.air.state == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2168
				v_oldstyle->u.air.state = HANGAR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2169
				continue;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2170
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2171
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2172
			AircraftLeaveHangar(v_oldstyle); // make airplane visible if it was in a depot for example
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2173
			v_oldstyle->vehstatus &= ~VS_STOPPED; // make airplane moving
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2174
			v_oldstyle->u.air.state = FLYING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2175
			AircraftNextAirportPos_and_Order(v_oldstyle); // move it to the entry point of the airport
6479
b228a94a1832 (svn r8897) -Fix
tron
parents: 6449
diff changeset
  2176
			GetNewVehiclePosResult gp = GetNewVehiclePos(v_oldstyle);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2177
			v_oldstyle->tile = 0; // aircraft in air is tile=0
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  2178
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2179
			/* correct speed of helicopter-rotors */
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: 7986
diff changeset
  2180
			if (v_oldstyle->subtype == AIR_HELICOPTER) v_oldstyle->Next()->Next()->cur_speed = 32;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2181
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2182
			/* set new position x,y,z */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2183
			SetAircraftPosition(v_oldstyle, gp.x, gp.y, GetAircraftFlyingAltitude(v_oldstyle));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2184
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2185
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2186
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2187
6911
ee97929ba49e (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6905
diff changeset
  2188
/**
ee97929ba49e (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6905
diff changeset
  2189
 * Updates the status of the Aircraft heading or in the station
ee97929ba49e (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6905
diff changeset
  2190
 * @param st Station been updated
ee97929ba49e (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6905
diff changeset
  2191
 */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2192
void UpdateAirplanesOnNewStation(const Station *st)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2193
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2194
	/* only 1 station is updated per function call, so it is enough to get entry_point once */
6358
e7997742bf02 (svn r8755) -Fix
tron
parents: 6353
diff changeset
  2195
	const AirportFTAClass *ap = st->Airport();
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2196
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2197
	Vehicle *v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2198
	FOR_ALL_VEHICLES(v) {
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
  2199
		if (v->type == VEH_AIRCRAFT && IsNormalAircraft(v)) {
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4412
diff changeset
  2200
			if (v->u.air.targetairport == st->index) { // if heading to this airport
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4412
diff changeset
  2201
				/* update position of airplane. If plane is not flying, landing, or taking off
6911
ee97929ba49e (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6905
diff changeset
  2202
				 * you cannot delete airport, so it doesn't matter */
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4412
diff changeset
  2203
				if (v->u.air.state >= FLYING) { // circle around
6362
f4de72f0abea (svn r8759) -Feature: Allow airports to have up to 4 entry points depending on approach direction. Note: they're not yet used, but will be soon
celestar
parents: 6358
diff changeset
  2204
					v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, ap);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2205
					v->u.air.state = FLYING;
7086
466f738d31c7 (svn r9804) -Fix (r9761): Update aircraft cached information when its 'pos' changes, as well as 'state'. (Thanks to bulb)
peter1138
parents: 7076
diff changeset
  2206
					UpdateAircraftCache(v);
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2207
					/* landing plane needs to be reset to flying height (only if in pause mode upgrade,
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2208
					 * in normal mode, plane is reset in AircraftController. It doesn't hurt for FLYING */
6479
b228a94a1832 (svn r8897) -Fix
tron
parents: 6449
diff changeset
  2209
					GetNewVehiclePosResult gp = GetNewVehiclePos(v);
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2210
					/* set new position x,y,z */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2211
					SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v));
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2212
				} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2213
					assert(v->u.air.state == ENDTAKEOFF || v->u.air.state == HELITAKEOFF);
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2214
					byte takeofftype = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : ENDTAKEOFF;
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2215
					/* search in airportdata for that heading
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2216
					 * easiest to do, since this doesn't happen a lot */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2217
					for (uint cnt = 0; cnt < ap->nofelements; cnt++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2218
						if (ap->layout[cnt].heading == takeofftype) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2219
							v->u.air.pos = ap->layout[cnt].position;
7086
466f738d31c7 (svn r9804) -Fix (r9761): Update aircraft cached information when its 'pos' changes, as well as 'state'. (Thanks to bulb)
peter1138
parents: 7076
diff changeset
  2220
							UpdateAircraftCache(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2221
							break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2222
						}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2223
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2224
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2225
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2226
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2227
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2228
}