src/aircraft_cmd.cpp
author celestar
Tue, 12 Jun 2007 11:56:35 +0000
branchgamebalance
changeset 9908 0fa543611bbe
parent 9906 6f41b8713b65
child 9910 0b2aebc8283e
permissions -rw-r--r--
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
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"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2140
diff changeset
    10
#include "functions.h"
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
    11
#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
    12
#include "station_map.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 458
diff changeset
    13
#include "table/strings.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 593
diff changeset
    14
#include "map.h"
1209
a1ac96655b79 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1206
diff changeset
    15
#include "tile.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "vehicle.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
    17
#include "depot.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "engine.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "news.h"
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    22
#include "sound.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
#include "player.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
    24
#include "aircraft.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
#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
    26
#include "vehicle_gui.h"
2517
b90693227193 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2504
diff changeset
    27
#include "table/sprites.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
    28
#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
    29
#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
    30
#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
    31
#include "newgrf_sound.h"
4261
2ec8f5a9747b (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4259
diff changeset
    32
#include "date.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
    33
#include "spritecache.h"
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
    34
#include "cargotype.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
    36
/** 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
    37
 *  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
    38
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
    39
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
    40
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
    41
static bool AirportMove(Vehicle *v, const AirportFTAClass *apc);
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
    42
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
    43
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
    44
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
    45
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
    46
static void CrashAirplane(Vehicle *v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
static void AircraftNextAirportPos_and_Order(Vehicle *v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
static byte GetAircraftFlyingAltitude(const Vehicle *v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
static const SpriteID _aircraft_sprite[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
	0x0EB5, 0x0EBD, 0x0EC5, 0x0ECD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
	0x0ED5, 0x0EDD, 0x0E9D, 0x0EA5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
	0x0EAD, 0x0EE5, 0x0F05, 0x0F0D,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
	0x0F15, 0x0F1D, 0x0F25, 0x0F2D,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
	0x0EED, 0x0EF5, 0x0EFD, 0x0F35,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
	0x0E9D, 0x0EA5, 0x0EAD, 0x0EB5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
	0x0EBD, 0x0EC5
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
    61
/** 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
    62
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
    63
	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
    64
	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
    65
	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
    66
	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
    67
};
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
    68
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
    69
/** 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
    70
 * 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
    71
 * 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
    72
 * @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
    73
 * @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
    74
 */
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
    75
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
    76
{
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
    77
	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
    78
	uint best = 0;
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
    79
	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
    80
	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
    81
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
    82
	FOR_ALL_STATIONS(st) {
6351
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
    83
		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
    84
6358
e7997742bf02 (svn r8755) -Fix
tron
parents: 6353
diff changeset
    85
		const AirportFTAClass *afc = st->Airport();
6351
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
    86
		if (afc->nof_depots == 0 || (
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
    87
					/* don't crash the plane if we know it can't land at the airport */
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
    88
					afc->flags & AirportFTAClass::SHORT_STRIP &&
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
    89
					AircraftVehInfo(v->engine_type)->subtype & AIR_FAST &&
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
    90
					!_cheats.no_jetcrash.value
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
    91
				)) {
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
    92
			continue;
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
    93
		}
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
    94
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
    95
		/* 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
    96
		uint distance = DistanceSquare(vtile, st->airport_tile);
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
    97
		if (distance < best || index == INVALID_STATION) {
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
    98
			best = distance;
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
    99
			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
   100
		}
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
   101
	}
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
   102
	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
   103
}
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
   104
1614
4ee38e74afd1 (svn r2118) - Fix: Fix compilation with network disabled, and comment out some of the warnings (unused function)
Darkvater
parents: 1533
diff changeset
   105
#if 0
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   106
/** 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
   107
 * @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
   108
 * @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
   109
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
   110
{
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
	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
   112
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
   113
	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
   114
		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
   115
		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
   116
			/* If an airport doesn't have a hangar, skip it */
6358
e7997742bf02 (svn r8755) -Fix
tron
parents: 6353
diff changeset
   117
			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
   118
				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
   119
		}
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
   120
	}
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
   121
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
   122
	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
   123
}
1614
4ee38e74afd1 (svn r2118) - Fix: Fix compilation with network disabled, and comment out some of the warnings (unused function)
Darkvater
parents: 1533
diff changeset
   124
#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
   125
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3140
diff changeset
   126
int GetAircraftImage(const Vehicle* v, Direction direction)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
	int spritenum = v->spritenum;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	if (is_custom_sprite(spritenum)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
		int sprite = GetCustomVehicleSprite(v, direction);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2962
diff changeset
   133
		if (sprite != 0) return sprite;
2464
3dee59d241c0 (svn r2990) Remove _engine_original_sprites and replace all uses with references to our (new) original engine/vehicle tables.
peter1138
parents: 2423
diff changeset
   134
		spritenum = orig_aircraft_vehicle_info[v->engine_type - AIRCRAFT_ENGINES_INDEX].image_index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
	return direction + _aircraft_sprite[spritenum];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
3710
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   139
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
   140
{
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
   141
	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
   142
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   143
	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
   144
	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
   145
		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
   146
		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
   147
	}
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   148
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   149
	/* 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
   150
	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
   151
}
a3db4dff570f (svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents: 3701
diff changeset
   152
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5902
diff changeset
   153
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
   154
{
4023
b65af90447d2 (svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
tron
parents: 3988
diff changeset
   155
	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
   156
	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
   157
	SpriteID sprite = (6 + _aircraft_sprite[spritenum]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
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
   159
	if (is_custom_sprite(spritenum)) {
3186
5798593c2d95 (svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents: 3183
diff changeset
   160
		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
   161
		if (sprite == 0) {
2464
3dee59d241c0 (svn r2990) Remove _engine_original_sprites and replace all uses with references to our (new) original engine/vehicle tables.
peter1138
parents: 2423
diff changeset
   162
			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
   163
			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
   164
		}
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
   165
	}
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
   166
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5902
diff changeset
   167
	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
   168
4023
b65af90447d2 (svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
tron
parents: 3988
diff changeset
   169
	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
   170
		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
   171
		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
   172
		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
   173
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
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
   176
/** 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
   177
 * @param engine The engine to get the sprite from
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   178
 * @param width The width of the sprite
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   179
 * @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
   180
 */
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
   181
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
   182
{
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
   183
	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
   184
	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
   185
	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
   186
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
   187
	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
   188
		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
   189
		if (sprite == 0) {
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
   190
			spritenum = orig_aircraft_vehicle_info[engine - AIRCRAFT_ENGINES_INDEX].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
   191
			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
   192
		}
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
   193
	}
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
   194
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
   195
	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
   196
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
   197
	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
   198
	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
   199
}
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
   200
6171
42ea86065d8d (svn r8548) -Fix
tron
parents: 6170
diff changeset
   201
static int32 EstimateAircraftCost(const AircraftVehicleInfo *avi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
{
9903
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9896
diff changeset
   203
	return avi->base_cost * (_eco->GetPrice(CEconomy::AIRCRAFT_BASE) >> 3) >> 5;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
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
   207
/**
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
   208
 * 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
   209
 * 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
   210
 * @param cid Which cargo type to calculate a capacity for.
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   211
 * @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
   212
 * @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
   213
 */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   214
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
   215
{
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
   216
	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
   217
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
   218
	/* 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
   219
	 * 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
   220
	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
   221
		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
   222
			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
   223
		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
   224
			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
   225
		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
   226
			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
   227
		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
   228
			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
   229
	}
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
   230
}
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
   231
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   232
/** 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
   233
 * @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
   234
 * @param flags for command
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   235
 * @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
   236
 * @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
   237
 * 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
   238
 */
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
   239
int32 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
   240
{
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   241
	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
   242
6171
42ea86065d8d (svn r8548) -Fix
tron
parents: 6170
diff changeset
   243
	const AircraftVehicleInfo *avi = AircraftVehInfo(p1);
42ea86065d8d (svn r8548) -Fix
tron
parents: 6170
diff changeset
   244
	int32 value = EstimateAircraftCost(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
   245
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   246
	/* 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
   247
	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
   248
3338
2c60ed0dcce3 (svn r4120) Use the new station functions where appropriate
tron
parents: 3315
diff changeset
   249
	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
   250
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   253
	/* Prevent building aircraft types at places which can't handle them */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   254
	if (!IsAircraftBuildableAtStation(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
   255
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
   256
	/* 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
   257
	 * vl[0] = aircraft, vl[1] = shadow, [vl[2] = rotor] */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   258
	Vehicle *vl[3];
6173
c6cf6600a82c (svn r8550) -Fix
tron
parents: 6172
diff changeset
   259
	if (!AllocateVehicles(vl, avi->subtype & AIR_CTOL ? 2 : 3)) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   260
		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   261
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   263
	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
   264
	if (unit_num > _patches.max_aircraft)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
		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
   266
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
	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
   268
		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
   269
		Vehicle *u = vl[1]; // shadow
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
		v->unitnumber = unit_num;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   272
		v->type = u->type = VEH_AIRCRAFT;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5836
diff changeset
   273
		v->direction = DIR_SE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
		v->owner = u->owner = _current_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
		v->tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
//		u->tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   280
		uint x = TileX(tile) * TILE_SIZE + 5;
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   281
		uint y = TileY(tile) * TILE_SIZE + 3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
		v->x_pos = u->x_pos = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
		v->y_pos = u->y_pos = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
		u->z_pos = GetSlopeZ(x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
		v->z_pos = u->z_pos + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
		v->x_offs = v->y_offs = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
//		u->delta_x = u->delta_y = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
		v->sprite_width = v->sprite_height = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
		v->z_height = 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
		u->sprite_width = u->sprite_height = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
		u->z_height = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
		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
   299
		u->vehstatus = VS_HIDDEN | VS_UNCLICKABLE | VS_SHADOW;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
538
5dd99f3b7eca (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   301
		v->spritenum = avi->image_index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
//		v->cargo_count = u->number_of_pieces = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
922
fc040662bd43 (svn r1410) Replaced all occurences of 'passanger' by 'passenger' in the code
celestar
parents: 919
diff changeset
   304
		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
   305
		u->cargo_cap = avi->mail_capacity;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
		v->cargo_type = CT_PASSENGERS;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
		u->cargo_type = CT_MAIL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
3870
766d7bd6c299 (svn r4910) - NewGRF: add and initialize cargo subtype for vehicle visual variations
peter1138
parents: 3816
diff changeset
   310
		v->cargo_subtype = 0;
766d7bd6c299 (svn r4910) - NewGRF: add and initialize cargo subtype for vehicle visual variations
peter1138
parents: 3816
diff changeset
   311
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
		v->string_id = STR_SV_AIRCRAFT_NAME;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
//		v->next_order_param = v->next_order = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
//		v->load_unload_time_rem = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
//		v->progress = 0;
1266
9dc5638fe8cc (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1263
diff changeset
   317
		v->last_station_visited = INVALID_STATION;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
//		v->destination_coords = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
538
5dd99f3b7eca (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   320
		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
   321
		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
   322
		v->engine_type = p1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
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
   324
		v->subtype = (avi->subtype & AIR_CTOL ? AIR_AIRCRAFT : AIR_HELICOPTER);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
		v->value = value;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
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
   327
		u->subtype = AIR_SHADOW;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
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
   329
		/* 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
   330
		 * 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
   331
		 * 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
   332
		 * 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
   333
		 * has no default cargo type specifier for planes... */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   334
		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
   335
		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
   336
			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
   337
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
   338
			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
   339
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
   340
			if (HASBIT(EngInfo(p1)->callbackmask, CBM_REFIT_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
   341
				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
   342
			}
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
   343
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
   344
			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
   345
				/* Callback failed, or not executed; use the default cargo capacity */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   346
				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
   347
			} 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
   348
				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
   349
			}
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
   350
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
   351
			/* 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
   352
			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
   353
		}
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
   354
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
   355
		const Engine *e = GetEngine(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
		v->reliability = e->reliability;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
		v->reliability_spd_dec = e->reliability_spd_dec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
		v->max_age = e->lifelength * 366;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
2564
371e0fa97e1e (svn r3101) -Codechange: added _new_vehicle_id
bjarni
parents: 2561
diff changeset
   360
		_new_vehicle_id = v->index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
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
   362
		/* 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
   363
		 * 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
   364
		 * 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
   365
		 * of all depots, it is simple */
6172
df973b5f6190 (svn r8549) -Fix
tron
parents: 6171
diff changeset
   366
		for (uint i = 0;; i++) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   367
			const Station *st = GetStationByTile(tile);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   368
			const AirportFTAClass *apc = st->Airport();
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   369
6172
df973b5f6190 (svn r8549) -Fix
tron
parents: 6171
diff changeset
   370
			assert(i != apc->nof_depots);
df973b5f6190 (svn r8549) -Fix
tron
parents: 6171
diff changeset
   371
			if (st->airport_tile + ToTileIndexDiff(apc->airport_depots[i]) == tile) {
df973b5f6190 (svn r8549) -Fix
tron
parents: 6171
diff changeset
   372
				assert(apc->layout[i].heading == HANGAR);
df973b5f6190 (svn r8549) -Fix
tron
parents: 6171
diff changeset
   373
				v->u.air.pos = apc->layout[i].position;
df973b5f6190 (svn r8549) -Fix
tron
parents: 6171
diff changeset
   374
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
		v->u.air.state = HANGAR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
		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
   380
		v->u.air.targetairport = GetStationIndex(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
		v->next = u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
		v->service_interval = _patches.servint_aircraft;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
		v->date_of_last_service = _date;
4329
9759d5c52010 (svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents: 4293
diff changeset
   386
		v->build_year = u->build_year = _cur_year;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
		v->cur_image = u->cur_image = 0xEA0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
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
   390
		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
   391
		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
   392
6502
7ca154aca2b7 (svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents: 6501
diff changeset
   393
		v->vehicle_flags = 0;
7ca154aca2b7 (svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents: 6501
diff changeset
   394
		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SETBIT(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
7ca154aca2b7 (svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents: 6501
diff changeset
   395
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
		VehiclePositionChanged(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   399
		/* 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
   400
		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
   401
			Vehicle *w = vl[2];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
			u->next = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   405
			w->type = VEH_AIRCRAFT;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5836
diff changeset
   406
			w->direction = DIR_N;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
			w->owner = _current_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
			w->x_pos = v->x_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
			w->y_pos = v->y_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
			w->z_pos = v->z_pos + 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
			w->x_offs = w->y_offs = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
			w->sprite_width = w->sprite_height = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
			w->z_height = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
			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
   415
			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
   416
			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
   417
			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
   418
			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
   419
			/* 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
   420
			w->u.air.state = HRS_ROTOR_STOPPED;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
			VehiclePositionChanged(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4732
diff changeset
   424
		InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 578
diff changeset
   425
		RebuildVehicleLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
		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
   427
		if (IsLocalPlayer())
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   428
			InvalidateAutoreplaceWindow(VEH_AIRCRAFT); //updates the replace Aircraft window
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6175
diff changeset
   429
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6175
diff changeset
   430
		GetPlayer(_current_player)->num_engines[p1]++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
	return value;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 381
diff changeset
   437
static void DoDeleteAircraft(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
	DeleteWindowById(WC_VEHICLE_VIEW, v->index);
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 578
diff changeset
   440
	RebuildVehicleLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
	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
   442
	DeleteDepotHighlightOfVehicle(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
	DeleteVehicleChain(v);
1055
3aae1d6f12aa (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
   444
	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
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
   447
/** 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
   448
 * @param tile unused
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   449
 * @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
   450
 * @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
   451
 * @param p2 unused
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   452
 * @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
   453
 */
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
   454
int32 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
   455
{
4352
8ddb01bc6075 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4351
diff changeset
   456
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   458
	Vehicle *v = GetVehicle(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   460
	if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR;
3963
d7d284c2f1f7 (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents: 3955
diff changeset
   461
	if (!IsAircraftInHangarStopped(v)) 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
   462
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
   463
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   464
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
		// Invalidate depot
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
		DoDeleteAircraft(v);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
	return -(int32)v->value;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
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
   474
/** 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
   475
 * @param tile unused
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   476
 * @param flags for command type
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   477
 * @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
   478
 * @param p2 unused
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   479
 * @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
   480
 */
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
   481
int32 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
   482
{
4352
8ddb01bc6075 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4351
diff changeset
   483
	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
   484
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   485
	Vehicle *v = GetVehicle(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   487
	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
   488
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   489
	/* 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
   490
	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
   491
		return_cmd_error(STR_A017_AIRCRAFT_IS_IN_FLIGHT);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
4338
cc4648e8e529 (svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents: 4329
diff changeset
   493
	/* 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
   494
	 * return 0xFF if it can. */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   495
	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
   496
	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
   497
		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
   498
		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
   499
	}
cc4648e8e529 (svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents: 4329
diff changeset
   500
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
	if (flags & DC_EXEC) {
3963
d7d284c2f1f7 (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents: 3955
diff changeset
   502
		if (IsAircraftInHangarStopped(v)) {
3139
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 3008
diff changeset
   503
			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
   504
		}
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 3008
diff changeset
   505
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
		v->vehstatus ^= VS_STOPPED;
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 699
diff changeset
   507
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
1055
3aae1d6f12aa (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
   509
		InvalidateWindowClasses(WC_AIRCRAFT_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   515
/** 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
   516
 * @param tile unused
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   517
 * @param flags for command type
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   518
 * @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
   519
 * @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
   520
 * - 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
   521
 * - 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
   522
 * @return o if everything went well
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   523
 */
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
   524
int32 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
   525
{
4506
0d8fcc0a4e49 (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4463
diff changeset
   526
	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
   527
		/* 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
   528
		if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   529
		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
   530
	}
3a70624c40eb (svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents: 4451
diff changeset
   531
4506
0d8fcc0a4e49 (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4463
diff changeset
   532
	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
   533
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   534
	Vehicle *v = GetVehicle(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   536
	if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner) || IsAircraftInHangar(v)) return CMD_ERROR;
4451
66603f0f732e (svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents: 4434
diff changeset
   537
4506
0d8fcc0a4e49 (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4463
diff changeset
   538
	if (v->current_order.type == OT_GOTO_DEPOT && !(p2 & DEPOT_LOCATE_HANGAR)) {
4519
1437b1e7416c (svn r6304) -Codechange r6295: Use !! instead of (bool) in commands to send vehicles to depots
bjarni
parents: 4510
diff changeset
   539
		if (!!(p2 & DEPOT_SERVICE) == HASBIT(v->current_order.flags, OFB_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
   540
			/* 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
   541
			 * 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
   542
			 * 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
   543
			if (flags & DC_EXEC) {
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
   544
				TOGGLEBIT(v->current_order.flags, OFB_HALT_IN_DEPOT);
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
   545
				InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
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
   546
			}
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
   547
			return 0;
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
   548
		}
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
   549
4506
0d8fcc0a4e49 (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4463
diff changeset
   550
		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
   551
		if (flags & DC_EXEC) {
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   552
			if (v->current_order.flags & OF_UNLOAD) v->cur_order_index++;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   553
			v->current_order.type = OT_DUMMY;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   554
			v->current_order.flags = 0;
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 699
diff changeset
   555
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
	} 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
   558
		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
   559
		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
   560
		const Station *st = GetStation(next_airport_index);
4111
8efd85ca4b76 (svn r5454) -Fix: [ 1394231 ] Autorenew glitch on helicopters
bjarni
parents: 4095
diff changeset
   561
		/* If the station is not a valid airport or if it has no hangars */
6358
e7997742bf02 (svn r8755) -Fix
tron
parents: 6353
diff changeset
   562
		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
   563
			/* the aircraft has to search for a hangar on its own */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   564
			StationID station = FindNearestHangar(v);
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   565
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   566
			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
   567
			if (station == INVALID_STATION) return CMD_ERROR;
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   568
			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
   569
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
		if (flags & DC_EXEC) {
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   572
			v->current_order.type = OT_GOTO_DEPOT;
4412
945e8a9bb89a (svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents: 4389
diff changeset
   573
			v->current_order.flags = OF_NON_STOP;
4991
9d63e4ab5e4a (svn r6994) -Regression (r6291): When sending an aircrafts to a hangar the wrong bit gets tested to determine if a aircraft should stop there or just get serviced
tron
parents: 4845
diff changeset
   574
			if (!(p2 & DEPOT_SERVICE)) SETBIT(v->current_order.flags, OFB_HALT_IN_DEPOT);
5259
08336337aae0 (svn r7389) -Fix: when forcing a vehicle to go to a depot, clear refit orders from current orders (caused refit error popup when not having no orders)
bjarni
parents: 5256
diff changeset
   575
			v->current_order.refit_cargo = CT_INVALID;
4527
b18634a31a4a (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4526
diff changeset
   576
			v->current_order.dest = next_airport_index;
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 699
diff changeset
   577
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
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
   578
			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
   579
				/* 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
   580
				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
   581
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
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
   589
/** 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
   590
 * @param tile unused
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   591
 * @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
   592
 * @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
   593
 * @param p2 various bitstuffed elements
2635
88b8b74c01ac (svn r3177) GB, CLRBIT, HASBIT, TOGGLEBIT
tron
parents: 2630
diff changeset
   594
 * - 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
   595
 * - p2 = (bit 8-15) - the new cargo subtype to refit to
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   596
 * @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
   597
 */
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
   598
int32 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
   599
{
3954
634cd5e35803 (svn r5103) - Add cargo subtype parameter to refit commands (mart3p)
peter1138
parents: 3948
diff changeset
   600
	byte new_subtype = GB(p2, 8, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
4352
8ddb01bc6075 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4351
diff changeset
   602
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   604
	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
   605
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   606
	if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR;
3963
d7d284c2f1f7 (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents: 3955
diff changeset
   607
	if (!IsAircraftInHangarStopped(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
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
   608
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
   609
	/* Check cargo */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   610
	CargoID new_cid = GB(p2, 0, 8);
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   611
	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
   612
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
   613
	SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN);
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   614
3974
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   615
	/* Check the refit capacity callback */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   616
	uint16 callback = CALLBACK_FAILED;
3974
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   617
	if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_REFIT_CAPACITY)) {
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   618
		/* Back up the existing cargo type */
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   619
		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
   620
		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
   621
		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
   622
		v->cargo_subtype = new_subtype;
3974
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   623
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   624
		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
   625
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   626
		/* Restore the cargo type */
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   627
		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
   628
		v->cargo_subtype = temp_subtype;
3974
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   629
	}
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   630
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   631
	const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   632
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   633
	uint pass;
3974
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   634
	if (callback == CALLBACK_FAILED) {
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   635
		/* 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
   636
		 * default cargo capacity */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   637
		pass = AircraftDefaultCargoCapacity(new_cid, avi);
3974
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   638
	} else {
ee12e0c0336c (svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents: 3973
diff changeset
   639
		pass = callback;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
	}
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
   641
	_returned_refit_capacity = pass;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   643
	int32 cost = 0;
4845
49105d3b5a9a (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4843
diff changeset
   644
	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
   645
		cost = GetRefitCost(v->engine_type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
		v->cargo_cap = pass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   651
		Vehicle *u = v->next;
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
   652
		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
   653
		u->cargo_cap = mail;
3955
81e7e25e4599 (svn r5104) - When refitting a vehicle to its existing cargo type, don't lose the cargo onboard (useful when adding wagons to a train)
peter1138
parents: 3954
diff changeset
   654
		if (v->cargo_type == new_cid) {
81e7e25e4599 (svn r5104) - When refitting a vehicle to its existing cargo type, don't lose the cargo onboard (useful when adding wagons to a train)
peter1138
parents: 3954
diff changeset
   655
			v->cargo_count = min(pass, v->cargo_count);
81e7e25e4599 (svn r5104) - When refitting a vehicle to its existing cargo type, don't lose the cargo onboard (useful when adding wagons to a train)
peter1138
parents: 3954
diff changeset
   656
			u->cargo_count = min(mail, u->cargo_count);
81e7e25e4599 (svn r5104) - When refitting a vehicle to its existing cargo type, don't lose the cargo onboard (useful when adding wagons to a train)
peter1138
parents: 3954
diff changeset
   657
		} else {
81e7e25e4599 (svn r5104) - When refitting a vehicle to its existing cargo type, don't lose the cargo onboard (useful when adding wagons to a train)
peter1138
parents: 3954
diff changeset
   658
			v->cargo_count = 0;
81e7e25e4599 (svn r5104) - When refitting a vehicle to its existing cargo type, don't lose the cargo onboard (useful when adding wagons to a train)
peter1138
parents: 3954
diff changeset
   659
			u->cargo_count = 0;
81e7e25e4599 (svn r5104) - When refitting a vehicle to its existing cargo type, don't lose the cargo onboard (useful when adding wagons to a train)
peter1138
parents: 3954
diff changeset
   660
		}
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
   661
		v->cargo_type = new_cid;
3954
634cd5e35803 (svn r5103) - Add cargo subtype parameter to refit commands (mart3p)
peter1138
parents: 3948
diff changeset
   662
		v->cargo_subtype = new_subtype;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
		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
   664
		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
   665
		RebuildVehicleLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
static void CheckIfAircraftNeedsService(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   674
	if (_patches.servint_aircraft == 0) return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   675
	if (!VehicleNeedsService(v)) return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   676
	if (v->vehstatus & VS_STOPPED) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   678
	if (v->current_order.type == OT_GOTO_DEPOT &&
1530
caa16c506a22 (svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents: 1520
diff changeset
   679
			v->current_order.flags & OF_HALT_IN_DEPOT)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   682
	if (_patches.gotodepot && VehicleHasDepotOrders(v)) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   683
4529
2bfac24af02a (svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents: 4527
diff changeset
   684
	if (IsAircraftInHangar(v)) {
2bfac24af02a (svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents: 4527
diff changeset
   685
		VehicleServiceInDepot(v);
2bfac24af02a (svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents: 4527
diff changeset
   686
		return;
2bfac24af02a (svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents: 4527
diff changeset
   687
	}
2bfac24af02a (svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents: 4527
diff changeset
   688
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   689
	const Station *st = GetStation(v->current_order.dest);
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   690
	/* only goto depot if the target airport has terminals (eg. it is airport) */
6358
e7997742bf02 (svn r8755) -Fix
tron
parents: 6353
diff changeset
   691
	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
   692
//		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
   693
//		v->u.air.targetairport = st->index;
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   694
		v->current_order.type = OT_GOTO_DEPOT;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   695
		v->current_order.flags = OF_NON_STOP;
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 699
diff changeset
   696
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   697
	} else if (v->current_order.type == OT_GOTO_DEPOT) {
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   698
		v->current_order.type = OT_DUMMY;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   699
		v->current_order.flags = 0;
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 699
diff changeset
   700
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
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
void OnNewDay_Aircraft(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
{
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
   706
	if (!IsNormalAircraft(v)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   708
	if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
3140
69cb681c6d86 (svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents: 3139
diff changeset
   710
	CheckOrders(v);
19
6080d2b6a959 (svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents: 11
diff changeset
   711
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
	CheckVehicleBreakdown(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
	AgeVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
	CheckIfAircraftNeedsService(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   716
	if (v->vehstatus & VS_STOPPED) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
9903
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9896
diff changeset
   718
	int32 cost = AircraftVehInfo(v->engine_type)->running_cost * _eco->GetPrice(CEconomy::AIRCRAFT_RUNNING) / 364;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
	v->profit_this_year -= cost >> 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
	SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
	SubtractMoneyFromPlayerFract(v->owner, cost);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
1055
3aae1d6f12aa (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
   726
	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   729
void AircraftYearlyLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
	FOR_ALL_VEHICLES(v) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   734
		if (v->type == VEH_AIRCRAFT && IsNormalAircraft(v)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
			v->profit_last_year = v->profit_this_year;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
			v->profit_this_year = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
			InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   740
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   741
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
static void AgeAircraftCargo(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   744
	if (_age_cargo_skip_counter != 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
	do {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   747
		if (v->cargo_days != 0xFF) v->cargo_days++;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   748
		v = v->next;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   749
	} while (v != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
static void HelicopterTickHandler(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
{
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   754
	Vehicle *u = v->next->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   756
	if (u->vehstatus & VS_HIDDEN) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   758
	/* 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
   759
	 * loading/unloading at a terminal or stopped */
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   760
	if (v->current_order.type == OT_LOADING || (v->vehstatus & VS_STOPPED)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
		if (u->cur_speed != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
			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
   763
			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
   764
				u->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
			}
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
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
		if (u->cur_speed == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
			u->cur_speed = 0x70;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
		if (u->cur_speed >= 0x50)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
			u->cur_speed--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   775
	int tick = ++u->tick_counter;
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   776
	int spd = u->cur_speed >> 4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   778
	SpriteID img;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
	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
   780
		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
   781
		img = GetRotorImage(v);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
   782
		if (u->cur_image == img) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
	} else if (tick >= spd) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
		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
   785
		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
   786
		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
   787
		img = GetRotorImage(v);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
   788
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
		return;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
   790
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
   792
	u->cur_image = img;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
	BeginVehicleMove(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
	VehiclePositionChanged(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
	EndVehicleMove(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
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
   800
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
	v->x_pos = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
	v->y_pos = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
	v->z_pos = z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
	v->cur_image = GetAircraftImage(v, v->direction);
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
   806
	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
   807
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
	BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
	VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
	EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   812
	Vehicle *u = v->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   814
	int safe_x = clamp(x, 0, MapMaxX() * TILE_SIZE);
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   815
	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
   816
	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
   817
	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
   818
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
   819
	safe_y = clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE);
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
   820
	u->z_pos = GetSlopeZ(safe_x, safe_y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
	u->cur_image = v->cur_image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
	BeginVehicleMove(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
	VehiclePositionChanged(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
	EndVehicleMove(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   827
	u = u->next;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   828
	if (u != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
		u->x_pos = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
		u->y_pos = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
		u->z_pos = z + 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
		BeginVehicleMove(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
		VehiclePositionChanged(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
		EndVehicleMove(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   837
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
4725
f7284b86833f (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
   839
/** 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
   840
 * @param *v Vehicle that enters the hangar
f7284b86833f (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
   841
 */
4732
da9d305d1c94 (svn r6644) -Fix(r6637): remove inline to allow MSVC compilation
belugas
parents: 4725
diff changeset
   842
void HandleAircraftEnterHangar(Vehicle *v)
0
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
	v->subspeed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
	v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   847
	Vehicle *u = v->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
	u->vehstatus |= VS_HIDDEN;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   849
	u = u->next;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   850
	if (u != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
		u->vehstatus |= VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
		u->cur_speed = 0;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
	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
   856
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
   858
static void PlayAircraftSound(const Vehicle* v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
{
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4574
diff changeset
   860
	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
   861
		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
   862
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
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
   865
/**
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
   866
 * 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
   867
 */
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
   868
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
   869
	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
   870
	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
   871
	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
   872
	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
   873
	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
   874
};
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
   875
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
   876
/**
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
   877
 * 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
   878
 * @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
   879
 * @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
   880
 * @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
   881
 * @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
   882
 */
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
   883
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
   884
{
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
   885
	uint spd = v->acceleration * 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
	byte t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
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
   888
	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
   889
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
	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
   891
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
   892
	if (!hard_limit && v->cur_speed > speed_limit) speed_limit = v->cur_speed - (v->cur_speed / 48);
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
   893
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
   894
	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
   895
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   896
	/* 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
   897
	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
   898
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   899
	/* 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
   900
	if (spd != v->cur_speed) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
		v->cur_speed = spd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
		if (_patches.vehicle_speed)
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 699
diff changeset
   903
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   906
	if (!(v->direction & 1)) spd = spd * 3 / 4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
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
   908
	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
   909
	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
   910
	return spd >> 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
6159
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   913
/**
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   914
 * 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
   915
 * 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
   916
 * 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
   917
 * @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
   918
 * @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
   919
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
static byte GetAircraftFlyingAltitude(const Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
{
6159
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   922
	/* 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
   923
	 * 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
   924
	 */
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   925
	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
   926
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   927
	/* 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
   928
	 * 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
   929
	 */
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   930
	switch (v->direction) {
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   931
		case DIR_N:
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   932
		case DIR_NE:
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   933
		case DIR_E:
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   934
		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
   935
			base_altitude += 10;
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   936
			break;
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   937
6159
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   938
		default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
	}
6159
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   940
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   941
	/* 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
   942
	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
   943
9a782ac72dba (svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents: 6137
diff changeset
   944
	return base_altitude;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
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
   947
/**
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   948
 * Find the entry point to an airport depending on direction which
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   949
 * the airport is being approached from. Each airport can have up to
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   950
 * four entry points for its approach system so that approaching
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   951
 * aircraft do not fly through each other or are forced to do 180
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   952
 * degree turns during the approach. The arrivals are grouped into
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   953
 * four sectors dependent on the DiagDirection from which the airport
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   954
 * is approached.
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   955
 *
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   956
 * @param v   The vehicle that is approaching the airport
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   957
 * @param apc The Airport Class being approached.
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   958
 * @returns   The index of the entry point
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   959
 */
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   960
static byte AircraftGetEntryPoint(const Vehicle *v, const AirportFTAClass *apc)
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   961
{
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   962
	assert(v != NULL);
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   963
	assert(apc != NULL);
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   964
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   965
	const Station *st = GetStation(v->u.air.targetairport);
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   966
	/* Make sure we don't go to 0,0 if the airport has been removed. */
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   967
	TileIndex tile = (st->airport_tile != 0) ? st->airport_tile : st->xy;
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   968
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   969
	int delta_x = v->x_pos - TileX(tile) * TILE_SIZE;
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   970
	int delta_y = v->y_pos - TileY(tile) * TILE_SIZE;
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   971
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   972
	DiagDirection dir;
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   973
	if (abs(delta_y) < abs(delta_x)) {
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   974
		/* We are northeast or southwest of the airport */
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   975
		dir = delta_x < 0 ? DIAGDIR_NE : DIAGDIR_SW;
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   976
	} else {
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   977
		/* We are northwest or southeast of the airport */
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   978
		dir = delta_y < 0 ? DIAGDIR_NW : DIAGDIR_SE;
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   979
	}
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   980
	return apc->entry_points[dir];
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   981
}
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   982
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   983
/**
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
   984
 * 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
   985
 * 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
   986
 * @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
   987
 * @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
   988
 * @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
   989
 */
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
   990
static bool AircraftController(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
{
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
   992
	int count;
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   993
	const Station *st = GetStation(v->u.air.targetairport);
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   994
	const AirportFTAClass *afc = st->Airport();
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   995
	const AirportMovingData *amd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
   997
	/* prevent going to 0,0 if airport is deleted. */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
   998
	TileIndex tile = st->airport_tile;
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   999
	if (tile == 0) {
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  1000
		tile = st->xy;
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  1001
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  1002
		/* Jump into our "holding pattern" state machine if possible */
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  1003
	if (v->u.air.pos >= afc->nofelements) v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, afc);
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  1004
	}
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  1005
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  1006
	/*  get airport moving data */
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  1007
	amd = afc->MovingData(v->u.air.pos);
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  1008
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1009
	int x = TileX(tile) * TILE_SIZE;
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1010
	int y = TileY(tile) * TILE_SIZE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1012
	/* Helicopter raise */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
	if (amd->flag & AMED_HELI_RAISE) {
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1014
		Vehicle *u = v->next->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1016
		/* 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
  1017
		if (u->cur_speed > 32) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
			v->cur_speed = 0;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1019
			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
  1020
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
			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
  1022
			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
  1023
			if (count > 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
				v->tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1026
				/* Reached altitude? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
				if (v->z_pos >= 184) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
					v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
					return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
				}
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
  1031
				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
  1032
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1035
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1037
	/* Helicopter landing. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
	if (amd->flag & AMED_HELI_LOWER) {
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
  1039
		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
  1040
		if (count > 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
			if (st->airport_tile == 0) {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1042
				/* FIXME - AircraftController -> if station no longer exists, do not land
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1043
				 * helicopter will circle until sign disappears, then go to next order
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1044
				 * what to do when it is the only order left, right now it just stays in 1 place */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
				v->u.air.state = FLYING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
				AircraftNextAirportPos_and_Order(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
				return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1050
			/* Vehicle is now at the airport. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
			v->tile = st->airport_tile;
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
			/* Find altitude of landing 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
  1054
			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
  1055
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
			if (z == v->z_pos) {
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1057
				Vehicle *u = v->next->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1059
				/*  Increase speed of rotors. When speed is 80, we've landed. */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1060
				if (u->cur_speed >= 80) return true;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1061
				u->cur_speed += 4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
			} else if (v->z_pos > z) {
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
  1063
				SetAircraftPosition(v, v->x_pos, v->y_pos, max(v->z_pos - count, z));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
			} else {
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
  1065
				SetAircraftPosition(v, v->x_pos, v->y_pos, min(v->z_pos + count, z));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1071
	/* Get distance from destination pos to current pos. */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1072
	uint dist = myabs(x + amd->x - v->x_pos) +  myabs(y + amd->y - v->y_pos);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1073
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1074
	/* 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
  1075
	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
  1076
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1077
	/* At final pos? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1078
	if (dist == 0) {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1079
		/* Change direction smoothly to final direction. */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1080
		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
  1081
		/* 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
  1082
		 * UpdateAircraftSpeed(). So do it only afterwards */
3158
a821c8fec829 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
  1083
		if (dirdiff == DIRDIFF_SAME) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
			v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
			return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
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
  1088
		if (!UpdateAircraftSpeed(v, SPEED_LIMIT_TAXI)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
3158
a821c8fec829 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
  1090
		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
  1091
		v->cur_speed >>= 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
		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
  1094
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
	}
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
	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
  1098
	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
  1099
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
  1100
	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
  1101
	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
  1102
	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
  1103
	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
  1104
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
  1105
	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
  1106
	if (count == 0) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1108
	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
  1109
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
  1110
	do {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1111
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1112
		GetNewVehiclePosResult gp;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1113
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1114
		if (dist < 4) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1115
			/* move vehicle one pixel towards target */
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1116
			gp.x = (v->x_pos != (x + amd->x)) ?
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1117
					v->x_pos + ((x + amd->x > v->x_pos) ? 1 : -1) :
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1118
					v->x_pos;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1119
			gp.y = (v->y_pos != (y + amd->y)) ?
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1120
					v->y_pos + ((y + amd->y > v->y_pos) ? 1 : -1) :
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1121
					v->y_pos;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1122
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1123
			/* Oilrigs must keep v->tile as st->airport_tile, since the landing pad is in a non-airport tile */
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1124
			gp.new_tile = (st->airport_type == AT_OILRIG) ? st->airport_tile : TileVirtXY(gp.x, gp.y);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1125
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1126
		} else {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1127
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1128
			/* Turn. Do it slowly if in the air. */
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1129
			Direction newdir = GetDirectionTowards(v, x + amd->x, y + amd->y);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1130
			if (newdir != v->direction) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1131
				v->direction = newdir;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1132
				if (amd->flag & AMED_SLOWTURN) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1133
					if (v->load_unload_time_rem == 0) v->load_unload_time_rem = 8;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1134
				} else {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1135
					v->cur_speed >>= 1;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1136
				}
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
  1137
			}
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1138
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1139
			/* Move vehicle. */
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1140
			gp = GetNewVehiclePos(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
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
  1143
		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
  1144
		/* If vehicle is in the air, use tile coordinate 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
  1145
		// 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
  1146
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
  1147
		/* 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
  1148
		uint z = v->z_pos;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
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
  1150
		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
  1151
			z = min(z + 2, GetAircraftFlyingAltitude(v));
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1152
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
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
  1154
		if ((amd->flag & AMED_HOLD) && (z > 150)) z--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
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
  1156
		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
  1157
			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
  1158
				/* 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
  1159
				v->u.air.state = FLYING;
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
  1160
				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
  1161
				/* 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
  1162
				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
  1163
				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
  1164
			}
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
  1165
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 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
  1167
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
			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
  1169
				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
  1170
			} 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
  1171
				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
  1172
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
				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
  1174
				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
  1175
			}
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
  1176
		}
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
  1177
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
  1178
		/* 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
  1179
		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
  1180
			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
  1181
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
  1182
			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
  1183
				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
  1184
			} 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
  1185
				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
  1186
			}
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
  1187
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
  1188
		}
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
  1189
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
  1190
		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
  1191
	} while (--count != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1192
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1193
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1194
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
static void HandleCrashedAircraft(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
	v->u.air.crashed_counter++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1200
	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
  1201
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1202
	/* make aircraft crash down to the ground */
1150
9ff458b2e574 (svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents: 1139
diff changeset
  1203
	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
  1204
		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
  1205
		v->z_pos -= 1;
1150
9ff458b2e574 (svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents: 1139
diff changeset
  1206
		if (v->z_pos == z) {
9ff458b2e574 (svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents: 1139
diff changeset
  1207
			v->u.air.crashed_counter = 500;
9ff458b2e574 (svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents: 1139
diff changeset
  1208
			v->z_pos++;
9ff458b2e574 (svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents: 1139
diff changeset
  1209
		}
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
  1210
	}
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
  1211
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
	if (v->u.air.crashed_counter < 650) {
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1213
		uint32 r;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
		if (CHANCE16R(1,32,r)) {
3160
9201d3f304e0 (svn r3786) More work for DirDiff
tron
parents: 3158
diff changeset
  1215
			static const DirDiff delta[] = {
9201d3f304e0 (svn r3786) More work for DirDiff
tron
parents: 3158
diff changeset
  1216
				DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT
9201d3f304e0 (svn r3786) More work for DirDiff
tron
parents: 3158
diff changeset
  1217
			};
9201d3f304e0 (svn r3786) More work for DirDiff
tron
parents: 3158
diff changeset
  1218
9201d3f304e0 (svn r3786) More work for DirDiff
tron
parents: 3158
diff changeset
  1219
			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
  1220
			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
  1221
			r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
			CreateEffectVehicleRel(v,
2140
d708eb80ab8b (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2133
diff changeset
  1223
				GB(r, 0, 4) + 4,
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
  1224
				GB(r, 4, 4) + 4,
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
  1225
				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
  1226
				EV_EXPLOSION_SMALL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1227
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1228
	} 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
  1229
		/*  remove rubble of crashed airplane */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1231
		/* 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
  1232
		 * 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
  1233
		 * but they all share the same number */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
		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
  1235
		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
  1236
		CLRBITS(st->airport_flags, RUNWAY_IN2_block);    // intercontinental
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
		BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
		DoDeleteAircraft(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1244
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1245
static void HandleBrokenAircraft(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1246
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1247
	if (v->breakdown_ctr != 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
		v->breakdown_ctr = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
		v->vehstatus |= VS_AIRCRAFT_BROKEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1250
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
		if (v->breakdowns_since_last_service != 255)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
			v->breakdowns_since_last_service++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
static void HandleAircraftSmoke(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
{
2654
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1261
	static const struct {
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1262
		int8 x;
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1263
		int8 y;
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1264
	} smoke_pos[] = {
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1265
		{  5,  5 },
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1266
		{  6,  0 },
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1267
		{  5, -5 },
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1268
		{  0, -6 },
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1269
		{ -5, -5 },
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1270
		{ -6,  0 },
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1271
		{ -5,  5 },
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1272
		{  0,  6 }
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1273
	};
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1274
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1275
	if (!(v->vehstatus & VS_AIRCRAFT_BROKEN)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
	if (v->cur_speed < 10) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
		v->vehstatus &= ~VS_AIRCRAFT_BROKEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1279
		v->breakdown_ctr = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1283
	if ((v->tick_counter & 0x1F) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
		CreateEffectVehicleRel(v,
2654
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1285
			smoke_pos[v->direction].x,
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2639
diff changeset
  1286
			smoke_pos[v->direction].y,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
			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
  1288
			EV_SMOKE
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
		);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1293
static void ProcessAircraftOrder(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
{
3005
db4007baa0ab (svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents: 2989
diff changeset
  1295
	switch (v->current_order.type) {
db4007baa0ab (svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents: 2989
diff changeset
  1296
		case OT_GOTO_DEPOT:
db4007baa0ab (svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents: 2989
diff changeset
  1297
			if (!(v->current_order.flags & OF_PART_OF_ORDERS)) return;
db4007baa0ab (svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents: 2989
diff changeset
  1298
			if (v->current_order.flags & OF_SERVICE_IF_NEEDED &&
db4007baa0ab (svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents: 2989
diff changeset
  1299
					!VehicleNeedsService(v)) {
db4007baa0ab (svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents: 2989
diff changeset
  1300
				v->cur_order_index++;
db4007baa0ab (svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents: 2989
diff changeset
  1301
			}
db4007baa0ab (svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents: 2989
diff changeset
  1302
			break;
db4007baa0ab (svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents: 2989
diff changeset
  1303
db4007baa0ab (svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents: 2989
diff changeset
  1304
		case OT_LOADING: return;
4351
63ae31104f07 (svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents: 4346
diff changeset
  1305
63ae31104f07 (svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents: 4346
diff changeset
  1306
		default: break;
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
  1307
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1308
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1309
	if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1310
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1311
	const Order *order = GetVehicleOrder(v, v->cur_order_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1312
6493
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1313
	if (order == NULL|| (order->type == OT_DUMMY && !CheckForValidOrders(v))) {
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1314
		/*
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1315
		 * We do not have an order. This can be divided into two cases:
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1316
		 * 1) we are heading to an invalid station. In this case we must
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1317
		 *    find another airport to go to. If there is nowhere to go,
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1318
		 *    we will destroy the aircraft as it otherwise will enter
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1319
		 *    the holding pattern for the first airport, which can cause
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1320
		 *    the plane to go into an undefined state when building an
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1321
		 *    airport with the same StationID.
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1322
		 * 2) we are (still) heading to a (still) valid airport, then we
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1323
		 *    can continue going there. This can happen when you are
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1324
		 *    changing the aircraft's orders while in-flight or in for
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1325
		 *    example a depot. However, when we have a current order to
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1326
		 *    go to a depot, we have to keep that order so the aircraft
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1327
		 *    actually stops.
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1328
		 */
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1329
		const Station *st = GetStation(v->u.air.targetairport);
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1330
		if (!st->IsValid() || st->airport_tile == 0) {
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1331
			int32 ret;
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1332
			PlayerID old_player = _current_player;
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1333
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1334
			_current_player = v->owner;
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1335
			ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1336
			_current_player = old_player;
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1337
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1338
			if (CmdFailed(ret)) CrashAirplane(v);
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1339
		} else if (v->current_order.type != OT_GOTO_DEPOT) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1340
			v->current_order.Free();
6493
da8b5609f110 (svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents: 6479
diff changeset
  1341
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1342
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1343
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1344
4527
b18634a31a4a (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4526
diff changeset
  1345
	if (order->type  == v->current_order.type  &&
b18634a31a4a (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4526
diff changeset
  1346
			order->flags == v->current_order.flags &&
b18634a31a4a (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4526
diff changeset
  1347
			order->dest  == v->current_order.dest)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1348
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1349
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1350
	v->current_order = *order;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1352
	/* orders are changed in flight, ensure going to the right station */
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1353
	if (order->type == OT_GOTO_STATION && v->u.air.state == FLYING) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1354
		AircraftNextAirportPos_and_Order(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1356
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1357
	InvalidateVehicleOrder(v);
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1358
1055
3aae1d6f12aa (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
  1359
	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
0
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
3722
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
  1362
/** Mark all views dirty for an aircraft.
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
  1363
 * @param v vehicle to be redrawn.
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
  1364
 */
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
  1365
static void MarkAircraftDirty(Vehicle *v)
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
  1366
{
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
  1367
		v->cur_image = GetAircraftImage(v, v->direction);
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
  1368
		if (v->subtype == AIR_HELICOPTER) v->next->next->cur_image = GetRotorImage(v);
3722
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
  1369
		MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
  1370
}
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
  1371
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
static void HandleAircraftLoading(Vehicle *v, int mode)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
{
6107
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1374
	switch (v->current_order.type) {
6109
2361013ddd68 (svn r8434) -Fix (r8430): Missing braces caused compilation failure for some (most?) compilers...
peter1138
parents: 6107
diff changeset
  1375
		case OT_LOADING: {
6107
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1376
			if (mode != 0) return;
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1377
			if (--v->load_unload_time_rem != 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1378
6107
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1379
			if (CanFillVehicle(v) && (
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1380
						v->current_order.flags & OF_FULL_LOAD ||
6501
1e95e8d993ff (svn r8945) -Codechange: Rename v->load_status to v->vehicle_flags so it can be used for more than just the gradual loading status.
maedhros
parents: 6493
diff changeset
  1381
						(_patches.gradual_loading && !HASBIT(v->vehicle_flags, VF_LOADING_FINISHED))
6107
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1382
					)) {
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1383
				SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC);
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1384
				if (LoadUnloadVehicle(v, false)) {
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1385
					InvalidateWindow(WC_AIRCRAFT_LIST, v->owner);
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1386
					MarkAircraftDirty(v);
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1387
				}
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1388
				return;
3722
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
  1389
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1391
			Order b = v->current_order;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1392
			v->current_order.Free();
3722
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
  1393
			MarkAircraftDirty(v);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1394
			if (!(b.flags & OF_NON_STOP)) return;
6107
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1395
			break;
6109
2361013ddd68 (svn r8434) -Fix (r8430): Missing braces caused compilation failure for some (most?) compilers...
peter1138
parents: 6107
diff changeset
  1396
		}
6107
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1397
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1398
		case OT_DUMMY: break;
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1399
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1400
		default: return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
	}
6107
0f6e342d55ff (svn r8430) -Fix
tron
parents: 6105
diff changeset
  1402
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
	v->cur_order_index++;
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1404
	InvalidateVehicleOrder(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
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
  1407
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
  1408
{
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
  1409
	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
  1410
	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
  1411
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
  1412
	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
  1413
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
	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
  1415
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1416
	uint amt = 2;
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1417
	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
  1418
	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
  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
	v->cargo_count = 0;
6202
d33e0e32f60a (svn r8617) -Fix
tron
parents: 6196
diff changeset
  1421
	v->next->cargo_count = 0;
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1422
	const Station *st = GetStation(v->u.air.targetairport);
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1423
	StringID newsitem;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1424
	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
  1425
		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
  1426
	} 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
  1427
		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
  1428
		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
  1429
	}
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
  1430
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
	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
  1432
	AddNewsItem(newsitem,
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
		NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 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
  1434
		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
  1435
		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
  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
	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
  1438
}
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
  1439
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1440
static void MaybeCrashAirplane(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1441
{
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1442
	Station *st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1444
	/* 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
  1445
	uint16 prob = 0x10000 / 1500;
6358
e7997742bf02 (svn r8755) -Fix
tron
parents: 6353
diff changeset
  1446
	if (st->Airport()->flags & AirportFTAClass::SHORT_STRIP &&
6351
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
  1447
			AircraftVehInfo(v->engine_type)->subtype & AIR_FAST &&
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
  1448
			!_cheats.no_jetcrash.value) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1449
		prob = 0x10000 / 20;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
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
  1452
	if (GB(Random(), 0, 16) > prob) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1454
	/* Crash the airplane. Remove all goods stored at the station. */
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9903
diff changeset
  1455
	for (CargoID i = 0; i < NUM_CARGO; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1456
		st->goods[i].rating = 1;
2504
7c27fc230cda (svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents: 2484
diff changeset
  1457
		SB(st->goods[i].waiting_acceptance, 0, 12, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
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
  1460
	CrashAirplane(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1462
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1463
/** 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
  1464
static void AircraftEntersTerminal(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1466
	if (v->current_order.type == OT_GOTO_DEPOT) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1468
	Station *st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
	v->last_station_visited = v->u.air.targetairport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1470
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
	/* Check if station was ever visited before */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1472
	if (!(st->had_vehicle_of_type & HVOT_AIRCRAFT)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1473
		uint32 flags;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
		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
  1476
		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
  1477
		/* show newsitem of celebrating citizens */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
		flags = (v->owner == _local_player) ? NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ARRIVAL_PLAYER, 0) : NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ARRIVAL_OTHER, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1479
		AddNewsItem(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1480
			STR_A033_CITIZENS_CELEBRATE_FIRST,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1481
			flags,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
			v->index,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1483
			0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1484
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1485
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1486
	Order old_order = v->current_order;
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
  1487
	v->BeginLoading();
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1488
	v->current_order.flags = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1489
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1490
	if (old_order.type == OT_GOTO_STATION &&
4527
b18634a31a4a (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4526
diff changeset
  1491
			v->current_order.dest == v->last_station_visited) {
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1492
		v->current_order.flags =
3872
2c1a79141c34 (svn r4914) -Fix (FS#180) Aircraft can now serve as feeders
celestar
parents: 3870
diff changeset
  1493
			(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER)) | OF_NON_STOP;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1494
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1495
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1496
	SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC);
5211
651c9272ad22 (svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents: 5198
diff changeset
  1497
	LoadUnloadVehicle(v, true);
3722
00921cc83d70 (svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents: 3710
diff changeset
  1498
	MarkAircraftDirty(v);
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 699
diff changeset
  1499
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
1055
3aae1d6f12aa (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
  1500
	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1501
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1502
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1503
static void AircraftLand(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1504
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1505
	v->sprite_width = v->sprite_height = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1506
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1507
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1508
static void AircraftLandAirplane(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1509
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1510
	AircraftLand(v);
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4574
diff changeset
  1511
	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
  1512
		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
  1513
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
	MaybeCrashAirplane(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
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
  1517
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1518
/** 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
  1519
static void AircraftNextAirportPos_and_Order(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1520
{
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1521
	if (v->current_order.type == OT_GOTO_STATION ||
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1522
			v->current_order.type == OT_GOTO_DEPOT)
4527
b18634a31a4a (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4526
diff changeset
  1523
		v->u.air.targetairport = v->current_order.dest;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1524
6358
e7997742bf02 (svn r8755) -Fix
tron
parents: 6353
diff changeset
  1525
	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
  1526
	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
  1527
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1528
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1529
static void AircraftLeaveHangar(Vehicle *v)
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
	v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1532
	v->subspeed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1533
	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
  1534
	v->direction = DIR_SE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1535
	v->vehstatus &= ~VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1536
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1537
		Vehicle *u = v->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1538
		u->vehstatus &= ~VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1539
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1540
		/* Rotor blades */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1541
		u = u->next;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1542
		if (u != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1543
			u->vehstatus &= ~VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1544
			u->cur_speed = 80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1545
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1546
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1547
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
  1548
	VehicleServiceInDepot(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1549
	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
  1550
	InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
1055
3aae1d6f12aa (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
  1551
	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1553
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1554
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1555
////////////////////////////////////////////////////////////////////////////////
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1556
///////////////////   AIRCRAFT MOVEMENT SCHEME  ////////////////////////////////
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
////////////////////////////////////////////////////////////////////////////////
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1558
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
  1559
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1560
	AircraftEntersTerminal(v);
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1561
	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
  1562
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1564
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
  1565
{
4725
f7284b86833f (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  1566
	VehicleEnterDepot(v);
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1567
	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
  1568
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1570
/** In an Airport Hangar */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1571
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
  1572
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1573
	/* if we just arrived, execute EnterHangar first */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1574
	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
  1575
		AircraftEventHandler_EnterHangar(v, apc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1576
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1578
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1579
	/* if we were sent to the depot, stay there */
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1580
	if (v->current_order.type == OT_GOTO_DEPOT && (v->vehstatus & VS_STOPPED)) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1581
		v->current_order.Free();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1582
		return;
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
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1585
	if (v->current_order.type != OT_GOTO_STATION &&
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1586
			v->current_order.type != OT_GOTO_DEPOT)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1587
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1588
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1589
	/* 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
  1590
	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
  1591
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1592
	/* We are already at the target airport, we need to find a terminal */
4527
b18634a31a4a (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4526
diff changeset
  1593
	if (v->current_order.dest == 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
  1594
		/* FindFreeTerminal:
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1595
		 * 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
  1596
		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
  1597
			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
  1598
		} else {
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1599
			if (!AirportFindFreeTerminal(v, apc)) return; // airplane
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  1600
		}
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  1601
	} 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
  1602
		/* 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
  1603
		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
  1604
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1605
	AircraftLeaveHangar(v);
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1606
	AirportMove(v, apc);
0
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
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1609
/** 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
  1610
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
  1611
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1612
	/* if we just arrived, execute EnterTerminal first */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1613
	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
  1614
		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
  1615
		/* 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
  1616
		 * 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
  1617
		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
  1618
			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
  1619
				/* an exerpt of ServiceAircraft, without the invisibility stuff */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1620
				v->date_of_last_service = _date;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1621
				v->breakdowns_since_last_service = 0;
1926
68d60188a22f (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1901
diff changeset
  1622
				v->reliability = GetEngine(v->engine_type)->reliability;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1623
				InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1624
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1625
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1626
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1627
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1628
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1629
	if (!v->current_order.IsValid()) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1630
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1631
	/* 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
  1632
	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
  1633
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1634
	/* 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
  1635
	 * ---> start moving */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1636
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1637
	switch (v->current_order.type) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1638
		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
  1639
			/* 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
  1640
			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
  1641
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1642
		case OT_GOTO_DEPOT:   // visit hangar for serivicing, sale, etc.
4527
b18634a31a4a (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4526
diff changeset
  1643
			if (v->current_order.dest == v->u.air.targetairport) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
				v->u.air.state = HANGAR;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1645
			} 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
  1646
				v->u.air.state = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : TAKEOFF;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1647
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1648
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1649
		default:  // orders have been deleted (no orders), goto depot and don't bother us
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1650
			v->current_order.Free();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1651
			v->u.air.state = HANGAR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1652
	}
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1653
	AirportMove(v, apc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1654
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1655
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1656
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
  1657
{
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5259
diff changeset
  1658
	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
  1659
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1660
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1661
static void AircraftEventHandler_TakeOff(Vehicle *v, const AirportFTAClass *apc)
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1662
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1663
	PlayAircraftSound(v); // play takeoffsound for airplanes
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1664
	v->u.air.state = STARTTAKEOFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1665
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1666
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1667
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
  1668
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1669
	v->sprite_width = v->sprite_height = 24; // ??? no idea what this is
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1670
	v->u.air.state = ENDTAKEOFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1671
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1672
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1673
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
  1674
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1675
	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
  1676
	/* 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
  1677
	AircraftNextAirportPos_and_Order(v);
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_HeliTakeOff(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1681
{
2475
8443e1eefe1b (svn r3001) s/Player*/const Player*/
tron
parents: 2464
diff changeset
  1682
	const Player* p = GetPlayer(v->owner);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1683
	v->sprite_width = v->sprite_height = 24; // ??? no idea what this is
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1684
	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
  1685
	/* 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
  1686
	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
  1687
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1688
	/* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1689
	 * unless it is due for renewal but the engine is no longer available */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1690
	if (v->owner == _local_player && (
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2819
diff changeset
  1691
				EngineHasReplacementForPlayer(p, v->engine_type) ||
4111
8efd85ca4b76 (svn r5454) -Fix: [ 1394231 ] Autorenew glitch on helicopters
bjarni
parents: 4095
diff changeset
  1692
				((p->engine_renew && v->age - v->max_age > p->engine_renew_months * 30) &&
8efd85ca4b76 (svn r5454) -Fix: [ 1394231 ] Autorenew glitch on helicopters
bjarni
parents: 4095
diff changeset
  1693
				HASBIT(GetEngine(v->engine_type)->player_avail, _local_player))
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1694
			)) {
1520
c85dc79795e0 (svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents: 1401
diff changeset
  1695
		_current_player = _local_player;
4506
0d8fcc0a4e49 (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4463
diff changeset
  1696
		DoCommandP(v->tile, v->index, DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR);
1520
c85dc79795e0 (svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents: 1401
diff changeset
  1697
		_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
  1698
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1699
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1700
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1701
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
  1702
{
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1703
	Station *st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1704
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1705
	/* 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
  1706
	if (apc->flags & (v->subtype == AIR_HELICOPTER ? AirportFTAClass::HELICOPTERS : AirportFTAClass::AIRPLANES) &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1707
			st->airport_tile != 0 &&
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1708
			(st->owner == OWNER_NONE || st->owner == v->owner)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1709
		// {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
  1710
		// 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
  1711
		// 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
  1712
		byte landingtype = (v->subtype == AIR_HELICOPTER) ? HELILANDING : LANDING;
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1713
		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
  1714
		while (current != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1715
			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
  1716
				/* 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
  1717
				 * 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
  1718
				 * hack for speed thingie */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1719
				uint16 tcur_speed = v->cur_speed;
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1720
				uint16 tsubspeed = v->subspeed;
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1721
				if (!AirportHasBlock(v, current, apc)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1722
					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
  1723
					/* 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
  1724
					 * 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
  1725
					 * 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
  1726
					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
  1727
					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
  1728
					return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1729
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1730
				v->cur_speed = tcur_speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1731
				v->subspeed = tsubspeed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1732
			}
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1733
			current = current->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1734
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1735
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1736
	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
  1737
	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
  1738
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1739
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1740
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
  1741
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1742
	AircraftLandAirplane(v);  // maybe crash airplane
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1743
	v->u.air.state = ENDLANDING;
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1744
	/* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */
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
  1745
	if (v->current_order.type != OT_GOTO_DEPOT && v->owner == _local_player) {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1746
		/* only the vehicle owner needs to calculate the rest (locally) */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1747
		const Player* p = GetPlayer(v->owner);
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2819
diff changeset
  1748
		if (EngineHasReplacementForPlayer(p, v->engine_type) ||
2293
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2244
diff changeset
  1749
			(p->engine_renew && v->age - v->max_age > (p->engine_renew_months * 30))) {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1750
			/* send the aircraft to the hangar at next airport */
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
  1751
			_current_player = _local_player;
4506
0d8fcc0a4e49 (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4463
diff changeset
  1752
			DoCommandP(v->tile, v->index, DEPOT_SERVICE, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR);
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
  1753
			_current_player = OWNER_NONE;
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
  1754
		}
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
  1755
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1756
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1757
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1758
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
  1759
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
	AircraftLand(v); // helicopters don't crash
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1761
	v->u.air.state = HELIENDLANDING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1762
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1763
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1764
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
  1765
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1766
	/* 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
  1767
	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
  1768
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1769
	/* 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
  1770
	 * 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
  1771
	 * 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
  1772
	 * --> get out of the way to the hangar. */
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1773
	if (v->current_order.type == OT_GOTO_STATION) {
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1774
		if (AirportFindFreeTerminal(v, apc)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1775
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1776
	v->u.air.state = HANGAR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1777
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1778
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1779
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1780
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
  1781
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1782
	/*  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
  1783
	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
  1784
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1785
	/* 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
  1786
	 * 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
  1787
	 * 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
  1788
	 * --> 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
  1789
	 * --> else TAKEOFF
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1790
	 * 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
  1791
	 * must go to a hangar. */
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1792
	if (v->current_order.type == OT_GOTO_STATION) {
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1793
		if (AirportFindFreeHelipad(v, apc)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1794
	}
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1795
	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
  1796
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1797
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1798
typedef void AircraftStateHandler(Vehicle *v, const AirportFTAClass *apc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1799
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
  1800
	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
  1801
	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
  1802
	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
  1803
	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
  1804
	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
  1805
	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
  1806
	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
  1807
	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
  1808
	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
  1809
	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
  1810
	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
  1811
	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
  1812
	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
  1813
	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
  1814
	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
  1815
	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
  1816
	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
  1817
	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
  1818
	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
  1819
	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
  1820
	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
  1821
	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
  1822
	AircraftEventHandler_AtTerminal,     // HELIPAD4       = 22
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1823
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1824
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1825
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
  1826
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1827
	/* 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
  1828
	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
  1829
		Station *st = GetStation(v->u.air.targetairport);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1830
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1831
		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
  1832
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1833
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1834
6425
0af66a18da06 (svn r8834) -Fix
tron
parents: 6413
diff changeset
  1835
static void AirportGoToNextPosition(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1836
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1837
	/* 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
  1838
	if (!AircraftController(v)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1839
6425
0af66a18da06 (svn r8834) -Fix
tron
parents: 6413
diff changeset
  1840
	const AirportFTAClass *apc = GetStation(v->u.air.targetairport)->Airport();
0af66a18da06 (svn r8834) -Fix
tron
parents: 6413
diff changeset
  1841
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1842
	AirportClearBlock(v, apc);
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1843
	AirportMove(v, apc); // move aircraft to next position
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1844
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1845
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1846
/* 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
  1847
static bool AirportMove(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1848
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1849
	/* error handling */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1850
	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
  1851
		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
  1852
		assert(v->u.air.pos < apc->nofelements);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1853
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1854
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1855
	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
  1856
	/* 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
  1857
	if (current->heading == v->u.air.state) {
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1858
		byte prev_pos = v->u.air.pos; // location could be changed in state, so save it before-hand
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1859
		_aircraft_state_handlers[v->u.air.state](v, apc);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  1860
		if (v->u.air.state != FLYING) v->u.air.previous_pos = prev_pos;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1861
		return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1862
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1863
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1864
	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
  1865
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1866
	/* 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
  1867
	if (current->next == NULL) {
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1868
		if (AirportSetBlocks(v, current, apc)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1869
			v->u.air.pos = current->next_position;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1870
		} // move to next position
3579
8885d65a2ba7 (svn r4465) -Codechange (FS#60): Remove a variable no one really needs. (DaleStan)
celestar
parents: 3491
diff changeset
  1871
		return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1872
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1873
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1874
	/* 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
  1875
	 * matches our heading */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1876
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1877
		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
  1878
			if (AirportSetBlocks(v, current, apc)) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1879
				v->u.air.pos = current->next_position;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1880
			} // move to next position
3579
8885d65a2ba7 (svn r4465) -Codechange (FS#60): Remove a variable no one really needs. (DaleStan)
celestar
parents: 3491
diff changeset
  1881
			return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1882
		}
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1883
		current = current->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1884
	} while (current != NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1885
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
  1886
	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
  1887
	assert(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1888
	return false;
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
/*  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
  1892
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
  1893
{
4843
724322df355a (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
  1894
	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
  1895
	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
  1896
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1897
	/* 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
  1898
	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
  1899
		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
  1900
		uint64 airport_flags = next->block;
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2618
diff changeset
  1901
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1902
		/* check additional possible extra blocks */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1903
		if (current_pos != reference && current_pos->block != NOTHING_block) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1904
			airport_flags |= current_pos->block;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1905
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1906
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1907
		if (HASBITS(st->airport_flags, airport_flags)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1908
			v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1909
			v->subspeed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1910
			return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1911
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1912
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1913
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1915
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1916
/**
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  1917
 * "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
  1918
 * @param v airplane that requires the operation
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  1919
 * @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
  1920
 * @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
  1921
 * @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
  1922
 */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1923
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
  1924
{
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1925
	const AirportFTA *next = &apc->layout[current_pos->next_position];
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1926
	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
  1927
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1928
	/* 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
  1929
	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
  1930
		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
  1931
		/* 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
  1932
		 * this means more blocks should be checked/set */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1933
		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
  1934
		if (current == reference) current = current->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1935
		while (current != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1936
			if (current->heading == current_pos->heading && current->block != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1937
				airport_flags |= current->block;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1938
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1939
			}
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1940
			current = current->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1941
		};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1942
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  1943
		/* 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
  1944
		 * 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
  1945
		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
  1946
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1947
		Station* st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1948
		if (HASBITS(st->airport_flags, airport_flags)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1949
			v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1950
			v->subspeed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1951
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1952
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1953
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1954
		if (next->block != NOTHING_block) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1955
			SETBITS(st->airport_flags, airport_flags); // occupy next block
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1956
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1957
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1958
	return true;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1961
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
  1962
{
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1963
	Station *st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1964
	for (; i < last_terminal; i++) {
4059
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4056
diff changeset
  1965
		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
  1966
			/* TERMINAL# HELIPAD# */
4059
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4056
diff changeset
  1967
			v->u.air.state = _airport_terminal_state[i]; // start moving to that terminal/helipad
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4056
diff changeset
  1968
			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
  1969
			return true;
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
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1973
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1974
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1975
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
  1976
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1977
	uint num = 0;
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1018
diff changeset
  1978
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1979
	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
  1980
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1981
	return num;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1982
}
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1983
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1984
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1985
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1986
	/* example of more terminalgroups
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4546
diff changeset
  1987
	 * {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
  1988
	 * 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
  1989
	 * 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
  1990
	 * 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
  1991
	 * 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
  1992
	 * 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
  1993
	 * 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
  1994
	 * 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
  1995
	 */
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  1996
	if (apc->terminals[0] > 1) {
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1997
		const Station *st = GetStation(v->u.air.targetairport);
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  1998
		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
  1999
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2000
		while (temp != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2001
			if (temp->heading == 255) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2002
				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
  2003
					/* 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
  2004
					 * (the first free group) */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2005
					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
  2006
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2007
					/* 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
  2008
					 * 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
  2009
					 * groups with lower number */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2010
					uint group_start = 0;
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2011
					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
  2012
						group_start += apc->terminals[i];
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2013
					}
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2014
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2015
					uint group_end = group_start + apc->terminals[target_group];
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2016
					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
  2017
				}
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2018
			} else {
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2019
				/* 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
  2020
				 * So we cannot move */
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2021
				return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2022
			}
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2023
			temp = temp->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2024
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2025
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2026
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2027
	/* 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
  2028
	return FreeTerminal(v, 0, GetNumTerminals(apc));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2029
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2030
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2031
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
  2032
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  2033
	uint num = 0;
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1018
diff changeset
  2034
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2035
	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
  2036
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2037
	return num;
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2038
}
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2039
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2040
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2041
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *apc)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2042
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2043
	/* 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
  2044
	if (apc->helipads == NULL) return AirportFindFreeTerminal(v, apc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2045
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2046
	/* 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
  2047
	if (apc->helipads[0] > 1) {
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4072
diff changeset
  2048
		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
  2049
		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
  2050
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2051
		while (temp != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2052
			if (temp->heading == 255) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2053
				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
  2054
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2055
					/* 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
  2056
					 * (the first free group) */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2057
					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
  2058
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2059
					/* 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
  2060
					 * 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
  2061
					 * groups with lower number */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2062
					uint group_start = 0;
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2063
					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
  2064
						group_start += apc->helipads[i];
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2065
					}
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2066
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2067
					uint group_end = group_start + apc->helipads[target_group];
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2068
					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
  2069
				}
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2070
			} else {
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2071
				/* 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
  2072
				 * So we cannot move */
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2073
				return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2074
			}
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4739
diff changeset
  2075
			temp = temp->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2076
		}
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2077
	} else {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2078
		/* 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
  2079
		 * 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
  2080
		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
  2081
	}
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
  2082
	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
  2083
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2084
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2085
static void AircraftEventHandler(Vehicle *v, int loop)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2086
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2087
	v->tick_counter++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2088
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2089
	if (v->vehstatus & VS_CRASHED) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2090
		HandleCrashedAircraft(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2091
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2092
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2093
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  2094
	if (v->vehstatus & VS_STOPPED) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2095
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2096
	/* aircraft is broken down? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2097
	if (v->breakdown_ctr != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2098
		if (v->breakdown_ctr <= 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2099
			HandleBrokenAircraft(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2100
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2101
			v->breakdown_ctr--;
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
	}
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
	HandleAircraftSmoke(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2106
	ProcessAircraftOrder(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2107
	HandleAircraftLoading(v, loop);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2108
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  2109
	if (v->current_order.type >= OT_LOADING) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2110
6425
0af66a18da06 (svn r8834) -Fix
tron
parents: 6413
diff changeset
  2111
	AirportGoToNextPosition(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2112
}
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
void Aircraft_Tick(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2115
{
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
  2116
	if (!IsNormalAircraft(v)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2117
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
  2118
	if (v->subtype == AIR_HELICOPTER) HelicopterTickHandler(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2119
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2120
	AgeAircraftCargo(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2121
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
  2122
	for (uint i = 0; i != 2; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2123
		AircraftEventHandler(v, i);
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2124
		if (v->type != VEH_AIRCRAFT) // In case it was deleted
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2125
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2126
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2127
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2128
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2129
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2130
/** need to be called to load aircraft from old version */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2131
void UpdateOldAircraft()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2132
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2133
	/* 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
  2134
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2135
	FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2136
		st->airport_flags = 0; // reset airport
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2137
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2138
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2139
	Vehicle *v_oldstyle;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2140
	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
  2141
	/* 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
  2142
	 * skip those */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2143
		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
  2144
			/* airplane in terminal stopped doesn't hurt anyone, so goto next */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  2145
			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
  2146
				v_oldstyle->u.air.state = HANGAR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2147
				continue;
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
			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
  2151
			v_oldstyle->vehstatus &= ~VS_STOPPED; // make airplane moving
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2152
			v_oldstyle->u.air.state = FLYING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2153
			AircraftNextAirportPos_and_Order(v_oldstyle); // move it to the entry point of the airport
6479
b228a94a1832 (svn r8897) -Fix
tron
parents: 6449
diff changeset
  2154
			GetNewVehiclePosResult gp = GetNewVehiclePos(v_oldstyle);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2155
			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
  2156
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2157
			/* correct speed of helicopter-rotors */
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
  2158
			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
  2159
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2160
			/* set new position x,y,z */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2161
			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
  2162
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2163
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2164
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2165
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  2166
/**
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  2167
 * Updates the status of the Aircraft heading or in the station
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  2168
 * @param st Station been updated
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  2169
 */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2170
void UpdateAirplanesOnNewStation(const Station *st)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2171
{
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6443
diff changeset
  2172
	/* 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
  2173
	const AirportFTAClass *ap = st->Airport();
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2174
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2175
	Vehicle *v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2176
	FOR_ALL_VEHICLES(v) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  2177
		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
  2178
			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
  2179
				/* update position of airplane. If plane is not flying, landing, or taking off
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  2180
				 * 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
  2181
				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
  2182
					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
  2183
					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
  2184
					/* 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
  2185
					 * in normal mode, plane is reset in AircraftController. It doesn't hurt for FLYING */
6479
b228a94a1832 (svn r8897) -Fix
tron
parents: 6449
diff changeset
  2186
					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
  2187
					/* set new position x,y,z */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2188
					SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v));
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
  2189
				} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2190
					assert(v->u.air.state == ENDTAKEOFF || v->u.air.state == HELITAKEOFF);
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2191
					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
  2192
					/* 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
  2193
					 * easiest to do, since this doesn't happen a lot */
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6363
diff changeset
  2194
					for (uint cnt = 0; cnt < ap->nofelements; cnt++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2195
						if (ap->layout[cnt].heading == takeofftype) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2196
							v->u.air.pos = ap->layout[cnt].position;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2197
							break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2198
						}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2199
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2200
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2201
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2202
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2203
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2204
}