aircraft_cmd.c
author bjarni
Sun, 30 Jan 2005 20:50:06 +0000
changeset 1237 1c7a3f9c94b9
parent 1235 b9938f523286
child 1238 ba0c6c551c1d
permissions -rw-r--r--
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
- Fix: added check for v->type in some commands, which expects v to be a specific type

Checks like this is needed to protect network servers from people, who hack their clients to either cheat or crash the server

NOTE: if I made a mistake here it can make a function unreachable when it should be used. Here is one place to look if something weird happens
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     1
#include "stdafx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     2
#include "ttd.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 458
diff changeset
     3
#include "table/strings.h"
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 593
diff changeset
     4
#include "map.h"
1209
2e00193652b2 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1206
diff changeset
     5
#include "tile.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "engine.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "gfx.h"
337
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    12
#include "sound.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "airport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
static bool AirportMove(Vehicle *v, const AirportFTAClass *Airport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
static bool AirportHasBlock(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
static void AirportGoToNextPosition(Vehicle *v, const AirportFTAClass *Airport);
899
69db9cb6bc9d (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
    22
static void CrashAirplane(Vehicle *v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
static void AircraftNextAirportPos_and_Order(Vehicle *v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
static byte GetAircraftFlyingAltitude(const Vehicle *v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
static const SpriteID _aircraft_sprite[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	0x0EB5, 0x0EBD, 0x0EC5, 0x0ECD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
	0x0ED5, 0x0EDD, 0x0E9D, 0x0EA5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	0x0EAD, 0x0EE5, 0x0F05, 0x0F0D,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	0x0F15, 0x0F1D, 0x0F25, 0x0F2D,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
	0x0EED, 0x0EF5, 0x0EFD, 0x0F35,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	0x0E9D, 0x0EA5, 0x0EAD, 0x0EB5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	0x0EBD, 0x0EC5
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
1194
2b25b1477623 (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
    37
// use this to find the nearest hangar to v
2b25b1477623 (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
    38
// bit 16 is set in the return value if the player do not have any airports with a hangar (like helipads only)
2b25b1477623 (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
    39
static uint32 FindNearestHangar(Vehicle *v)
2b25b1477623 (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
    40
{
2b25b1477623 (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
    41
	Station *st;
1204
747d1f630eda (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
    42
	uint temp_distance, distance = 0xFFFF;
1194
2b25b1477623 (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
    43
	uint16 index_to_target = 0;
2b25b1477623 (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
    44
2b25b1477623 (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
    45
	FOR_ALL_STATIONS(st) {
2b25b1477623 (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
    46
		if (st->owner == v->owner && st->facilities & FACIL_AIRPORT) {
2b25b1477623 (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
    47
			if (GetAirport(st->airport_type)->terminals != NULL) {
1204
747d1f630eda (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
    48
				// don't crash the planes if we know they can't land at the airport
747d1f630eda (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
    49
				if (HASBIT(v->subtype,1) && st->airport_type == AT_SMALL && !_cheats.no_jetcrash.value) continue;
747d1f630eda (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
    50
747d1f630eda (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
    51
				temp_distance = GetTileDistAdv(v->tile, st->airport_tile);
1194
2b25b1477623 (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
    52
				if (temp_distance < distance) {
2b25b1477623 (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
    53
					distance = temp_distance;
2b25b1477623 (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
    54
					index_to_target = st->index;
2b25b1477623 (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
    55
				}
2b25b1477623 (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
    56
			}
2b25b1477623 (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
    57
		}
2b25b1477623 (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
    58
	}
2b25b1477623 (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
    59
	if (distance == 65000)
2b25b1477623 (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
    60
		SETBIT(index_to_target, 16);
2b25b1477623 (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
    61
	return index_to_target;
2b25b1477623 (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
    62
}
2b25b1477623 (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
    63
2b25b1477623 (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
    64
// returns true if vehicle v have an airport in the schedule, that has a hangar
2b25b1477623 (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
    65
static bool HaveHangarInOrderList(Vehicle *v)
2b25b1477623 (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
    66
{
2b25b1477623 (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
    67
	const Order *order;
2b25b1477623 (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
    68
2b25b1477623 (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
    69
	FOR_VEHICLE_ORDERS(v, order) {
2b25b1477623 (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
    70
		const Station *st = GetStation(order->station);
2b25b1477623 (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
    71
		if (st->owner == v->owner && st->facilities & FACIL_AIRPORT) {
2b25b1477623 (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
    72
			// If an airport doesn't have terminals (so no landing space for airports),
2b25b1477623 (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
    73
			// it surely doesn't have any hangars
2b25b1477623 (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
    74
			if (GetAirport(st->airport_type)->terminals != NULL)
2b25b1477623 (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
    75
				return true;
2b25b1477623 (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
		}
2b25b1477623 (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
    77
	}
2b25b1477623 (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
    78
2b25b1477623 (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
    79
	return false;
2b25b1477623 (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
    80
}
2b25b1477623 (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
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
int GetAircraftImage(Vehicle *v, byte direction)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
	int spritenum = v->spritenum;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
	if (is_custom_sprite(spritenum)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
		int sprite = GetCustomVehicleSprite(v, direction);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
		if (sprite) return sprite;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
		spritenum = _engine_original_sprites[v->engine_type];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
	return direction + _aircraft_sprite[spritenum];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
void DrawAircraftEngine(int x, int y, int engine, uint32 image_ormod)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
{
538
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
    97
	int spritenum = AircraftVehInfo(engine)->image_index;
1200
d5ef134866de (svn r1704) - Fix: [newgrf] rotors of custom helicopters are displayed correctly in the hangar window
dominik
parents: 1197
diff changeset
    98
	int sprite = (6 + _aircraft_sprite[spritenum]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
381
527e47c8feec (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
   100
	if (is_custom_sprite(spritenum)) {
1200
d5ef134866de (svn r1704) - Fix: [newgrf] rotors of custom helicopters are displayed correctly in the hangar window
dominik
parents: 1197
diff changeset
   101
		sprite = GetCustomVehicleIcon(engine, 6);
d5ef134866de (svn r1704) - Fix: [newgrf] rotors of custom helicopters are displayed correctly in the hangar window
dominik
parents: 1197
diff changeset
   102
		if (!sprite)
d5ef134866de (svn r1704) - Fix: [newgrf] rotors of custom helicopters are displayed correctly in the hangar window
dominik
parents: 1197
diff changeset
   103
			sprite = _engine_original_sprites[engine];
381
527e47c8feec (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
   104
	}
527e47c8feec (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
   105
1200
d5ef134866de (svn r1704) - Fix: [newgrf] rotors of custom helicopters are displayed correctly in the hangar window
dominik
parents: 1197
diff changeset
   106
	DrawSprite(sprite | image_ormod, x, y);
381
527e47c8feec (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
   107
1200
d5ef134866de (svn r1704) - Fix: [newgrf] rotors of custom helicopters are displayed correctly in the hangar window
dominik
parents: 1197
diff changeset
   108
	if ((AircraftVehInfo(engine)->subtype & 1) == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
		DrawSprite(0xF3D, x, y-5);
1200
d5ef134866de (svn r1704) - Fix: [newgrf] rotors of custom helicopters are displayed correctly in the hangar window
dominik
parents: 1197
diff changeset
   110
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
void DrawAircraftEngineInfo(int engine, int x, int y, int maxw)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
{
538
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   115
	const AircraftVehicleInfo *avi = AircraftVehInfo(engine);
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   116
	SetDParam(0, ((_price.aircraft_base >> 3) * avi->base_cost) >> 5);
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   117
	SetDParam(1, avi->max_speed << 3);
922
10035216cbaf (svn r1410) Replaced all occurences of 'passanger' by 'passenger' in the code
celestar
parents: 919
diff changeset
   118
	SetDParam(2, avi->passenger_capacity);
538
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   119
	SetDParam(3, avi->mail_capacity);
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   120
	SetDParam(4, avi->running_cost * _price.aircraft_running >> 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
	DrawStringMultiCenter(x, y, STR_A02E_COST_MAX_SPEED_CAPACITY, maxw);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
/* Allocate many vehicles */
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 381
diff changeset
   126
static bool AllocateVehicles(Vehicle **vl, int num)
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 i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	bool success = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
	for(i=0; i!=num; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
		vl[i] = v = AllocateVehicle();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
		if (v == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
			success = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
			break;
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
		v->type = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
	while (--i >= 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
		vl[i]->type = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
	return success;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
812
65ecc321b3db (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
   148
int32 EstimateAircraftCost(uint16 engine_type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
{
538
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   150
	return AircraftVehInfo(engine_type)->base_cost * (_price.aircraft_base>>3)>>5;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
/* p1 = engine */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
	int32 value;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
	Vehicle *vl[3], *v, *u, *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
	byte unit_num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	uint tile = TILE_FROM_XY(x,y);
538
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   161
	const AircraftVehicleInfo *avi = AircraftVehInfo(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
	Engine *e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
1197
433b4a05fa3e (svn r1701) Style police ^^
tron
parents: 1196
diff changeset
   164
	if (!IsEngineBuildable(p1, VEH_Aircraft)) return CMD_ERROR;
1196
67f7f3017d99 (svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents: 1195
diff changeset
   165
1226
f0cb2c427b84 (svn r1730) - Fix: Ships and Aircrafts have to be build in depots owned by _current_player (hacked client protection)
bjarni
parents: 1209
diff changeset
   166
	// Workaround: TODO: make AI players try to build planes in a hangar instead of just an airport tile.
f0cb2c427b84 (svn r1730) - Fix: Ships and Aircrafts have to be build in depots owned by _current_player (hacked client protection)
bjarni
parents: 1209
diff changeset
   167
	if (!IsAircraftHangarTile((TileIndex)tile) && IS_HUMAN_PLAYER(_current_player)) return CMD_ERROR;
f0cb2c427b84 (svn r1730) - Fix: Ships and Aircrafts have to be build in depots owned by _current_player (hacked client protection)
bjarni
parents: 1209
diff changeset
   168
f0cb2c427b84 (svn r1730) - Fix: Ships and Aircrafts have to be build in depots owned by _current_player (hacked client protection)
bjarni
parents: 1209
diff changeset
   169
	if (_map_owner[tile] != _current_player) return CMD_ERROR;
f0cb2c427b84 (svn r1730) - Fix: Ships and Aircrafts have to be build in depots owned by _current_player (hacked client protection)
bjarni
parents: 1209
diff changeset
   170
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
	value = EstimateAircraftCost(p1);
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
	if (flags & DC_QUERY_COST)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
		return value;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
	// allocate 2 or 3 vehicle structs, depending on type
538
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   179
	if (!AllocateVehicles(vl, (avi->subtype & 1) == 0 ? 3 : 2) ||
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
   180
				IsOrderPoolFull())
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
					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
   182
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	unit_num = GetFreeUnitNumber(VEH_Aircraft);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
	if (unit_num > _patches.max_aircraft)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
		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
   186
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
		v = vl[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
		u = vl[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
		v->unitnumber = unit_num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
		v->type = u->type = VEH_Aircraft;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
		v->direction = 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
		v->owner = u->owner = _current_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
		v->tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
//		u->tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
926
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 924
diff changeset
   200
		x = TileX(tile) * 16 + 5;
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 924
diff changeset
   201
		y = TileY(tile) * 16 + 3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
		v->x_pos = u->x_pos = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
		v->y_pos = u->y_pos = y;
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
		u->z_pos = GetSlopeZ(x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
		v->z_pos = u->z_pos + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
		v->x_offs = v->y_offs = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
//		u->delta_x = u->delta_y = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
		v->sprite_width = v->sprite_height = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
		v->z_height = 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
		u->sprite_width = u->sprite_height = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
		u->z_height = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
		v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
		u->vehstatus = VS_HIDDEN | VS_UNCLICKABLE | VS_DISASTER;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
538
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   221
		v->spritenum = avi->image_index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
//		v->cargo_count = u->number_of_pieces = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
922
10035216cbaf (svn r1410) Replaced all occurences of 'passanger' by 'passenger' in the code
celestar
parents: 919
diff changeset
   224
		v->cargo_cap = avi->passenger_capacity;
538
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   225
		u->cargo_cap = avi->mail_capacity;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
		v->cargo_type = CT_PASSENGERS;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
		u->cargo_type = CT_MAIL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
		v->string_id = STR_SV_AIRCRAFT_NAME;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
//		v->next_order_param = v->next_order = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
//		v->load_unload_time_rem = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
//		v->progress = 0;
817
238bbdaa228b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 812
diff changeset
   235
		v->last_station_visited = 0xFFFF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
//		v->destination_coords = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
538
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   238
		v->max_speed = avi->max_speed;
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   239
		v->acceleration = avi->acceleration;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
		v->engine_type = (byte)p1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
538
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   242
		v->subtype = (avi->subtype & 1) == 0 ? 0 : 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
		v->value = value;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
		u->subtype = 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
		e = &_engines[p1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
		v->reliability = e->reliability;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
		v->reliability_spd_dec = e->reliability_spd_dec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
		v->max_age = e->lifelength * 366;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
		_new_aircraft_id = v->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
		// the AI doesn't click on a tile to build airplanes, so the below code will
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
		// never work. Therefore just assume the AI's planes always come from Hangar0
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 76
diff changeset
   256
		// On hold for NewAI
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 76
diff changeset
   257
		v->u.air.pos = (!_patches.ainew_active && _is_ai_player) ? 0:MAX_ELEMENTS;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   259
		/* When we click on hangar we know the tile (it is in var 'tile')it is on. By that we know
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   260
			its position in the array of depots the airport has.....we can search
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
			->layout for #th position of depot. Since layout must start with depots, it is simple
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
		*/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
			Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
			const AirportFTAClass *Airport;
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 901
diff changeset
   266
			const TileIndexDiffC *cur_depot;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
			byte i = 0;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   268
			st = GetStation(_map2[tile]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
			Airport = GetAirport(st->airport_type);
699
604af534c65d (svn r1149) Fix hack which abuses first TileIndex of airport depot array as number of depots (similar change as in map branch)
tron
parents: 679
diff changeset
   270
			for (cur_depot = Airport->airport_depots; i != Airport->nof_depots; cur_depot++) {
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 901
diff changeset
   271
				if ((uint)(st->airport_tile + ToTileIndexDiff(*cur_depot)) == tile) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
					assert(Airport->layout[i].heading == HANGAR);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
					v->u.air.pos = Airport->layout[i].position;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
				i++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
			// to ensure v->u.air.pos has been given a value
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
			assert(v->u.air.pos != MAX_ELEMENTS);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
		v->u.air.state = HANGAR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
		v->u.air.previous_pos = v->u.air.pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
		v->u.air.targetairport = _map2[tile];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
		v->next = u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
		v->service_interval = _patches.servint_aircraft;
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->date_of_last_service = _date;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
		v->build_year = _cur_year;
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->cur_image = u->cur_image = 0xEA0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
		VehiclePositionChanged(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
		// Aircraft with 3 vehicles?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
		if (v->subtype == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
			w = vl[2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
			u->next = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
			w->type = VEH_Aircraft;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
			w->direction = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
			w->owner = _current_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
			w->x_pos = v->x_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
			w->y_pos = v->y_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
			w->z_pos = v->z_pos + 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
			w->x_offs = w->y_offs = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
			w->sprite_width = w->sprite_height = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
			w->z_height = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
			w->vehstatus = VS_HIDDEN | VS_UNCLICKABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
			w->subtype = 6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
			w->cur_image = 0xF3D;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
			VehiclePositionChanged(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 578
diff changeset
   319
		RebuildVehicleLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
		InvalidateWindow(WC_COMPANY, v->owner);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   323
	InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Aircraft); //updates the replace Aircraft window
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   324
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
	return value;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
bool IsAircraftHangarTile(TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
	// 0x56 - hangar facing other way international airport (86)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
	// 0x20 - hangar large airport (32)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
	// 0x41 - hangar small airport (65)
1035
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1024
diff changeset
   333
	return IsTileType(tile, MP_STATION) &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
				(_map5[tile] == 32 || _map5[tile] == 65 || _map5[tile] == 86);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
static bool CheckStoppedInHangar(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
	if (!(v->vehstatus&VS_STOPPED) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
			!IsAircraftHangarTile(v->tile)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
		_error_message = STR_A01B_AIRCRAFT_MUST_BE_STOPPED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 381
diff changeset
   349
static void DoDeleteAircraft(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
	DeleteWindowById(WC_VEHICLE_VIEW, v->index);
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 578
diff changeset
   352
	RebuildVehicleLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
	InvalidateWindow(WC_COMPANY, v->owner);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
	DeleteVehicleChain(v);
1055
cc4f60cc9102 (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
   355
	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
// p1 = vehicle
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
int32 CmdSellAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
1237
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   363
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   365
	v = GetVehicle(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
1235
b9938f523286 (svn r1739) - Fix: type checking when selling vehicles (TrueLight)
darkvater
parents: 1226
diff changeset
   367
	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner) || !CheckStoppedInHangar(v))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
1237
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   370
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   371
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
		// Invalidate depot
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
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
		DoDeleteAircraft(v);
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   380
	InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Aircraft); // updates the replace Aircraft window
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   381
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
	return -(int32)v->value;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
}
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
// p1 = vehicle
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
int32 CmdStartStopAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
1237
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   390
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   391
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   392
	v = GetVehicle(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
1237
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   394
	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
	// cannot stop airplane when in flight, or when taking off / landing
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
	if (v->u.air.state >= STARTTAKEOFF) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
		return_cmd_error(STR_A017_AIRCRAFT_IS_IN_FLIGHT);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
		v->vehstatus ^= VS_STOPPED;
755
80091de50044 (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
   404
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
1055
cc4f60cc9102 (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
   406
		InvalidateWindowClasses(WC_AIRCRAFT_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
1206
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
   412
/*  Send an aircraft to the hangar in the next station
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
   413
	p1 = index of the aircraft
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
   414
	p2 = bit 0..15 = index of station with hangar to use (only used if bit 17 is set)
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
   415
		 bit 16 = set v->set_for_replacement & do not stop in hangar
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
   416
		 bit 17 = goto the hangar in airport given in bit 0..15 instead of next stop
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
   417
		 bit 18 = clear v->set_for_replacement */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
int32 CmdSendAircraftToHangar(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
	Station *st;
1194
2b25b1477623 (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
   422
	uint16 next_airport_index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
1237
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   424
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   425
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   426
	v = GetVehicle(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
1237
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   428
	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner))
1206
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
   429
		return CMD_ERROR;
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
   430
1194
2b25b1477623 (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
   431
	if (HASBIT(p2, 16)) v->set_for_replacement = true; //now all clients knows that the vehicle wants to be replaced
1139
1649055e5e89 (svn r1640) fix: now helicopters will use a hangar in schedule to be replaced in, even if they are only set to service there. Since helicopters are serviced at helipads, they will only go there if they needs to be replaced or renewed.
bjarni
parents: 1135
diff changeset
   432
1206
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
   433
	if (HASBIT(p2, 18)) {
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
   434
		v->set_for_replacement = false;
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
   435
		return CMD_ERROR; // no need to send aircraft to a depot. We just told that it don't have to anymore
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
   436
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
1195
54d50ac3311a (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
   438
	if (v->current_order.type == OT_GOTO_DEPOT && p2 == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
		if (flags & DC_EXEC) {
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   440
			if (v->current_order.flags & OF_UNLOAD) v->cur_order_index++;
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   441
			v->current_order.type = OT_DUMMY;
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   442
			v->current_order.flags = 0;
755
80091de50044 (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
   443
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
	} else {
1194
2b25b1477623 (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
   446
		next_airport_index = (HASBIT(p2, 17)) ? (int16)p2 : v->u.air.targetairport;
2b25b1477623 (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
   447
		st = GetStation(next_airport_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
		// If an airport doesn't have terminals (so no landing space for airports),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
		// it surely doesn't have any hangars
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
   450
		if (st->xy == 0 || st->airport_tile == 0 || GetAirport(st->airport_type)->terminals == NULL)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
					return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
		if (flags & DC_EXEC) {
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   454
			v->current_order.type = OT_GOTO_DEPOT;
1194
2b25b1477623 (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
   455
			v->current_order.flags = v->set_for_replacement ? 0 : OF_NON_STOP | OF_FULL_LOAD;
2b25b1477623 (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
   456
			v->current_order.station = next_airport_index;
755
80091de50044 (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
   457
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
1194
2b25b1477623 (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
   458
			if (HASBIT(p2, 17)) {
2b25b1477623 (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
   459
				AircraftNextAirportPos_and_Order(v);
2b25b1477623 (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
   460
				v->u.air.targetairport = next_airport_index;
2b25b1477623 (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
   461
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
// p1 = vehicle
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
// p2 = new service int
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
int32 CmdChangeAircraftServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
1237
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   474
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   475
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   476
	v = GetVehicle(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
1237
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   478
	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
		v->service_interval = (uint16)p2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
		InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 7);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
// p1 = vehicle
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 817
diff changeset
   490
// p2 = new cargo type(0xFF)
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 817
diff changeset
   491
// p2 = skip check for stopped in hanger (0x0100)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
int32 CmdRefitAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
	Vehicle *v,*u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
	int pass, mail;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
	int32 cost;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 817
diff changeset
   497
	byte SkipStoppedInHangerCheck = (p2 & 0x100) >> 8; //excludes the cargo value
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 817
diff changeset
   498
	byte new_cargo_type = p2 & 0xFF; //gets the cargo number
924
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   499
	AircraftVehicleInfo *avi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
1237
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   501
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   503
	v = GetVehicle(p1);
1237
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   504
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   505
	if (v->type != VEH_Aircraft) return CMD_ERROR;
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   506
924
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   507
	avi = AircraftVehInfo(v->engine_type);
1237
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   508
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 817
diff changeset
   509
	if (!CheckOwnership(v->owner) || (!CheckStoppedInHangar(v) && !(SkipStoppedInHangerCheck)))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
1237
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   512
	SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN);
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1235
diff changeset
   513
924
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   514
	switch (new_cargo_type) {
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   515
		case CT_PASSENGERS:
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   516
			pass = avi->passenger_capacity;
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   517
			break;
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   518
		case CT_MAIL:
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   519
			pass = avi->passenger_capacity + avi->mail_capacity;
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   520
			break;
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   521
		case CT_GOODS:
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   522
			pass = avi->passenger_capacity + avi->mail_capacity;
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   523
			pass /= 2;
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   524
			break;
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   525
		default:
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   526
			pass = avi->passenger_capacity + avi->mail_capacity;
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   527
			pass /= 4;
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   528
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
	_aircraft_refit_capacity = pass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
	cost = 0;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 817
diff changeset
   533
	if (IS_HUMAN_PLAYER(v->owner) && new_cargo_type != v->cargo_type) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
		cost = _price.aircraft_base >> 7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
		v->cargo_cap = pass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
		u = v->next;
924
6fbd4419db2a (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   541
		mail = avi->mail_capacity;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 817
diff changeset
   542
		if (new_cargo_type != CT_PASSENGERS) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
			mail = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
		u->cargo_cap = mail;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 817
diff changeset
   546
		//autorefitted planes wants to keep the cargo
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 817
diff changeset
   547
		//it will be checked if the cargo is valid in CmdReplaceVehicle
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 817
diff changeset
   548
		if (!(SkipStoppedInHangerCheck))
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 817
diff changeset
   549
			v->cargo_count = u->cargo_count = 0;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 817
diff changeset
   550
		v->cargo_type = new_cargo_type;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
}
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
void HandleClickOnAircraft(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
	ShowAircraftViewWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
static void CheckIfAircraftNeedsService(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
76
30511cbc5188 (svn r77) -Fix: [1010788] AI service interval bug (tnx truesatan)
truelight
parents: 70
diff changeset
   566
	if (_patches.servint_aircraft == 0)
11
836bc4b37b5b (svn r12) Change: removed patch no_train_service. Instead you can set the default service interval for any vehicle type to 'disabled'.
dominik
parents: 0
diff changeset
   567
		return;
836bc4b37b5b (svn r12) Change: removed patch no_train_service. Instead you can set the default service interval for any vehicle type to 'disabled'.
dominik
parents: 0
diff changeset
   568
593
4240f624bca0 (svn r1015) MFM r789
tron
parents: 588
diff changeset
   569
	if (!VehicleNeedsService(v))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
	if (v->vehstatus & VS_STOPPED)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   575
	if (v->current_order.type == OT_GOTO_DEPOT &&
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   576
			v->current_order.flags & OF_FULL_LOAD)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
   579
	if (_patches.gotodepot && VehicleHasDepotOrders(v))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
 		return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   581
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   582
	st = GetStation(v->current_order.station);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
	// only goto depot if the target airport has terminals (eg. it is airport)
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
   584
	if (st->xy != 0 && st->airport_tile != 0 && GetAirport(st->airport_type)->terminals != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
//		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
   586
//		v->u.air.targetairport = st->index;
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   587
		v->current_order.type = OT_GOTO_DEPOT;
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   588
		v->current_order.flags = OF_NON_STOP;
755
80091de50044 (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
   589
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   590
	} else if (v->current_order.type == OT_GOTO_DEPOT) {
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   591
		v->current_order.type = OT_DUMMY;
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   592
		v->current_order.flags = 0;
755
80091de50044 (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
   593
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
void OnNewDay_Aircraft(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
	int32 cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	if (v->subtype > 2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
	if ((++v->day_counter & 7) == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
		DecreaseVehicleValue(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
1053
8d90844ddc2e (svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents: 1043
diff changeset
   607
	CheckOrders(v->index, OC_INIT);
19
6080d2b6a959 (svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents: 11
diff changeset
   608
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
	CheckVehicleBreakdown(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
	AgeVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
	CheckIfAircraftNeedsService(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
	if (v->vehstatus & VS_STOPPED)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
538
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   616
	cost = AircraftVehInfo(v->engine_type)->running_cost * _price.aircraft_running / 364;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
	v->profit_this_year -= cost >> 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
	SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
	SubtractMoneyFromPlayerFract(v->owner, cost);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
1055
cc4f60cc9102 (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
   624
	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1064
diff changeset
   627
void AircraftYearlyLoop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
	FOR_ALL_VEHICLES(v) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
		if (v->type == VEH_Aircraft && v->subtype <= 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
			v->profit_last_year = v->profit_this_year;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
			v->profit_this_year = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
			InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
static void AgeAircraftCargo(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
	if (_age_cargo_skip_counter != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
		if (v->cargo_days != 0xFF)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
			v->cargo_days++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
	} while ( (v=v->next) != NULL );
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
static void HelicopterTickHandler(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
	Vehicle *u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
	int tick,spd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
	uint16 img;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
	u = v->next->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
	if (u->vehstatus & VS_HIDDEN)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   662
	// if true, helicopter rotors do not rotate. This should only be the case if a helicopter is
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
	// loading/unloading at a terminal or stopped
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   664
	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
   665
		if (u->cur_speed != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
			u->cur_speed++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
			if (u->cur_speed >= 0x80 && u->cur_image == 0xF40) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
				u->cur_speed = 0;
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
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
		if (u->cur_speed == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
			u->cur_speed = 0x70;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
		if (u->cur_speed >= 0x50)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
			u->cur_speed--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
	tick = ++u->tick_counter;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
	spd = u->cur_speed >> 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
	if (spd == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
		img = 0xF3D;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
		if (u->cur_image == img)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
	} else if (tick >= spd) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
		u->tick_counter = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
		img = u->cur_image + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
		if (img > 0xF40)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
			img = 0xF3E;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
	} else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
	u->cur_image=img;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   696
	BeginVehicleMove(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
	VehiclePositionChanged(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
	EndVehicleMove(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
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
   702
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
	Vehicle *u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
	int yt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
	v->x_pos = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
	v->y_pos = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
	v->z_pos = z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
	v->cur_image = GetAircraftImage(v, v->direction);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
	BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
	VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
	EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
	u = v->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
	yt = y - ((v->z_pos-GetSlopeZ(x, y-1)) >> 3);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
	u->x_pos = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
	u->y_pos = yt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
	u->z_pos = GetSlopeZ(x,yt);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
	u->cur_image = v->cur_image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
	BeginVehicleMove(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
	VehiclePositionChanged(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
	EndVehicleMove(u);
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
	if ((u=u->next) != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
		u->x_pos = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
		u->y_pos = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
		u->z_pos = z + 5;
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
		BeginVehicleMove(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
		VehiclePositionChanged(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
		EndVehicleMove(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
}
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
static void ServiceAircraft(Vehicle *v)
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
	Vehicle *u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
	v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
	v->subspeed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
	v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
	v->vehstatus |= VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
	u = v->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
	u->vehstatus |= VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
	if ((u=u->next) != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
		u->vehstatus |= VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
		u->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
	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
   756
	InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
578
1e66514eb621 (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
   758
	VehicleServiceInDepot(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
static void PlayAircraftSound(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
{
538
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   764
	SndPlayVehicleFx(AircraftVehInfo(v->engine_type)->sfx, v);
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
static bool UpdateAircraftSpeed(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
	uint spd = v->acceleration * 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
	byte t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
	v->subspeed = (t=v->subspeed) + (byte)spd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
	spd = min( v->cur_speed + (spd >> 8) + (v->subspeed < t), v->max_speed);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   774
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
	// adjust speed for broken vehicles
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
	if(v->vehstatus&VS_AIRCRAFT_BROKEN) spd = min(spd, 27);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
	//updates statusbar only if speed have changed to save CPU time
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
	if (spd != v->cur_speed) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
		v->cur_speed = spd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
		if (_patches.vehicle_speed)
755
80091de50044 (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
   782
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
	if (!(v->direction & 1)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
		spd = spd * 3 >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
	if (spd == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
	if ((byte)++spd == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
		return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
	v->progress = (t = v->progress) - (byte)spd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
	return (t < v->progress);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
// get Aircraft running altitude
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
static byte GetAircraftFlyingAltitude(const Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
	byte maxz = 162;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
	if (v->max_speed != 37) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
		maxz = 171;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
		if (v->max_speed != 74) {maxz = 180;}
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
	return maxz;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
static bool Aircraft_5(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
	const AirportMovingData *amd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
	Vehicle *u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
	byte z,dirdiff,newdir,maxz,curz;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
	GetNewVehiclePosResult gp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
	uint dist;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
	int x,y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   821
	st = GetStation(v->u.air.targetairport);
0
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
	// prevent going to 0,0 if airport is deleted.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
		uint tile = st->airport_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
		if (tile == 0) tile = st->xy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
		// xy of destination
926
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 924
diff changeset
   828
		x = TileX(tile) * 16;
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 924
diff changeset
   829
		y = TileY(tile) * 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
	// get airport moving data
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
	assert(v->u.air.pos < GetAirport(st->airport_type)->nofelements);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
	amd = &_airport_moving_datas[st->airport_type][v->u.air.pos];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
	// Helicopter raise
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   837
	if (amd->flag & AMED_HELI_RAISE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
		u = v->next->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   839
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
		// Make sure the rotors don't rotate too fast
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
		if (u->cur_speed > 32) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
			v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
			if (--u->cur_speed == 32) {
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 538
diff changeset
   844
				SndPlayVehicleFx(SND_18_HELICOPTER, v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
			u->cur_speed = 32;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
			if (UpdateAircraftSpeed(v)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
				v->tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
				// Reached altitude?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
				if (v->z_pos >= 184) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
					v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
					return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
				SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos+1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
	// Helicopter landing.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
	if (amd->flag & AMED_HELI_LOWER) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
		if (UpdateAircraftSpeed(v)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
			if (st->airport_tile == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
				// FIXME - Aircraft_5 -> if station no longer exists, do not land
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
				// helicopter will circle until sign disappears, then go to next order
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
				// * what to do when it is the only order left, right now it just stays in 1 place
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
				v->u.air.state = FLYING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
				AircraftNextAirportPos_and_Order(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
				return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
			// Vehicle is now at the airport.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
			v->tile = st->airport_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
			// Find altitude of landing position.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
			z = GetSlopeZ(x, y) + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
			if (st->airport_type == AT_OILRIG) z += 54;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
			if (st->airport_type == AT_HELIPORT) z += 60;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
			if (z == v->z_pos) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
				u = v->next->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
				// Increase speed of rotors. When speed is 80, we've landed.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
				if (u->cur_speed >= 80)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
					return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
				u->cur_speed+=4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
			} else if (v->z_pos > z) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
				SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos-1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
				SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos+1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   893
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
	// Get distance from destination pos to current pos.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
	dist = myabs(x + amd->x - v->x_pos) +  myabs(y + amd->y - v->y_pos);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
	// Need exact position?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
	if (!(amd->flag & AMED_EXACTPOS) && dist <= (uint)((amd->flag&AMED_SLOWTURN)?8:4))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
		return true;
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
	// At final pos?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
	if (dist == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
		// Clamp speed to 12.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
		if (v->cur_speed > 12)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
			v->cur_speed = 12;
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
		// Change direction smoothly to final direction.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
		dirdiff = amd->direction - v->direction;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   914
		// if distance is 0, and plane points in right direction, no point in calling
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
		// UpdateAircraftSpeed(). So do it only afterwards
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
		if (dirdiff == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
			v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
			return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
		if (!UpdateAircraftSpeed(v))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
		v->direction = (v->direction+((dirdiff&7)<5?1:-1)) & 7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
		v->cur_speed >>= 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
		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
   928
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
	// Clamp speed?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
	if (!(amd->flag & AMED_NOSPDCLAMP) && v->cur_speed > 12)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
		v->cur_speed = 12;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
	if (!UpdateAircraftSpeed(v))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
	// Decrease animation counter.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
	if (v->load_unload_time_rem != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
		v->load_unload_time_rem--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
	// Turn. Do it slowly if in the air.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
	newdir = GetDirectionTowards(v, x + amd->x, y + amd->y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
	if (newdir != v->direction) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
		if (amd->flag & AMED_SLOWTURN) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
			if (v->load_unload_time_rem == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
				v->load_unload_time_rem = 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
			}
99
66c0918845af (svn r100) Fix: [ 1012086 ] Drunk pilot (Celestar)
dominik
parents: 84
diff changeset
   949
			v->direction = newdir;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
			v->cur_speed >>= 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
			v->direction = newdir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
	// Move vehicle.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
	GetNewVehiclePos(v, &gp);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
	v->tile = gp.new_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
	// If vehicle is in the air, use tile coordinate 0.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
	if (amd->flag & (AMED_TAKEOFF | AMED_SLOWTURN | AMED_LAND)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
		v->tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
	// Adjust Z for land or takeoff?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
	z = v->z_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
	if (amd->flag & AMED_TAKEOFF) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
		z+=2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
		// Determine running altitude
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
		maxz = GetAircraftFlyingAltitude(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
		if (z > maxz)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
			z = maxz;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
	if (amd->flag & AMED_LAND) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
		if (st->airport_tile == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
			//FIXME -- FIXED - Aircraft_5 -> if station no longer exists, do not land
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
			// * what to do when it is the only order left, right now it just stays in 1 place?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
			v->u.air.state = FLYING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
			AircraftNextAirportPos_and_Order(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
			// get aircraft back on running altitude
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
			SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
		curz = GetSlopeZ(x, y) + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
		if (curz > z) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
			z++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
			int t = max(1, dist-4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
			z -= ((z - curz) + t - 1) / t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
			if (z < curz) z = curz;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
	// We've landed. Decrase speed when we're reaching end of runway.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
	if (amd->flag & AMED_BRAKE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
		curz = GetSlopeZ(x, y) + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1003
		if (z > curz) z--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
		else if (z < curz) z++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
		if (dist < 64 && v->cur_speed > 12)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1007
			v->cur_speed -= 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
	SetAircraftPosition(v, gp.x, gp.y, z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
static const int8 _crashed_aircraft_moddir[4] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
	-1,0,0,1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
static void HandleCrashedAircraft(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
	uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
	Station *st;
899
69db9cb6bc9d (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
  1022
	int z;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
	v->u.air.crashed_counter++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1026
	st = GetStation(v->u.air.targetairport);
899
69db9cb6bc9d (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
  1027
69db9cb6bc9d (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
  1028
	// make aircraft crash down to the ground
1150
7b5946a53372 (svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents: 1139
diff changeset
  1029
	if (v->u.air.crashed_counter < 500 && st->airport_tile==0 && ((v->u.air.crashed_counter % 3) == 0) ) {
7b5946a53372 (svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents: 1139
diff changeset
  1030
		z = GetSlopeZ(v->x_pos, v->y_pos);
899
69db9cb6bc9d (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
  1031
		v->z_pos -= 1;
1150
7b5946a53372 (svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents: 1139
diff changeset
  1032
		if (v->z_pos == z) {
7b5946a53372 (svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents: 1139
diff changeset
  1033
			v->u.air.crashed_counter = 500;
7b5946a53372 (svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents: 1139
diff changeset
  1034
			v->z_pos++;
7b5946a53372 (svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents: 1139
diff changeset
  1035
		}
899
69db9cb6bc9d (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
  1036
	}
69db9cb6bc9d (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
  1037
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
	if (v->u.air.crashed_counter < 650) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
		if (CHANCE16R(1,32,r)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
			v->direction = (v->direction+_crashed_aircraft_moddir[(r >> 16)&3]) & 7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
			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
  1042
			r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
			CreateEffectVehicleRel(v,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
				4 + (r&0xF),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
				4 + ((r>>4)&0xF),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
				((r>>8)&0xF),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
				EV_DEMOLISH);
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
	} else if (v->u.air.crashed_counter >= 10000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
		// remove rubble of crashed airplane
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
		// clear runway-in on all airports, set by crashing plane
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
		// small airports use AIRPORT_BUSY, city airports use RUNWAY_IN_OUT_block, etc.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
		// but they all share the same number
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1055
		CLRBITS(st->airport_flags, RUNWAY_IN_block);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
		BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
		DoDeleteAircraft(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
static void HandleBrokenAircraft(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
	if (v->breakdown_ctr != 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
		v->breakdown_ctr = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
		v->vehstatus |= VS_AIRCRAFT_BROKEN;
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
		if (v->breakdowns_since_last_service != 255)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
			v->breakdowns_since_last_service++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1073
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1074
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
static const int8 _aircraft_smoke_xy[16] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1078
	5,6,5,0,-5,-6,-5,0, /* x coordinates */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
	5,0,-5,-6,-5,0,5,6, /* y coordinate */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1080
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1082
static void HandleAircraftSmoke(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
	if (!(v->vehstatus&VS_AIRCRAFT_BROKEN))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
		return;
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
	if (v->cur_speed < 10) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
		v->vehstatus &= ~VS_AIRCRAFT_BROKEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
		v->breakdown_ctr = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
	}
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
	if ((v->tick_counter & 0x1F) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
		CreateEffectVehicleRel(v,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
			_aircraft_smoke_xy[v->direction],
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
			_aircraft_smoke_xy[v->direction + 8],
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
			2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
			EV_SMOKE_3
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
		);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
static void ProcessAircraftOrder(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
{
1043
44508ede2f92 (svn r1544) -Fix: SwapOrder did not use AssignOrder, which caused the saveroutine to
truelight
parents: 1035
diff changeset
  1105
	const Order *order;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1106
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
	// OT_GOTO_DEPOT, OT_LOADING
899
69db9cb6bc9d (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
  1108
	if (v->current_order.type == OT_GOTO_DEPOT ||
69db9cb6bc9d (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
  1109
			v->current_order.type == OT_LOADING) {
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1110
		if (v->current_order.type != OT_GOTO_DEPOT ||
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1111
				!(v->current_order.flags & OF_UNLOAD))
1151
06c115ce7b7a (svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents: 1150
diff changeset
  1112
			return;
06c115ce7b7a (svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents: 1150
diff changeset
  1113
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1114
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1115
	if (v->current_order.type == OT_GOTO_DEPOT &&
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1116
			(v->current_order.flags & (OF_UNLOAD | OF_FULL_LOAD)) == (OF_UNLOAD | OF_FULL_LOAD) &&
1151
06c115ce7b7a (svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents: 1150
diff changeset
  1117
			!VehicleNeedsService(v) &&
1139
1649055e5e89 (svn r1640) fix: now helicopters will use a hangar in schedule to be replaced in, even if they are only set to service there. Since helicopters are serviced at helipads, they will only go there if they needs to be replaced or renewed.
bjarni
parents: 1135
diff changeset
  1118
			v->set_for_replacement == false) {
1151
06c115ce7b7a (svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents: 1150
diff changeset
  1119
			v->cur_order_index++;
06c115ce7b7a (svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents: 1150
diff changeset
  1120
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
	if (v->cur_order_index >= v->num_orders)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
		v->cur_order_index = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1125
	order = GetVehicleOrder(v, v->cur_order_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1126
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1127
	if (order == NULL) {
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1128
		v->current_order.type = OT_NOTHING;
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1129
		v->current_order.flags = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1133
	if (order->type == OT_DUMMY && !CheckForValidOrders(v))
901
0e42c4b151e3 (svn r1387) Fix: Airplanes now also crash when only one invalid order is in the schedule
dominik
parents: 899
diff changeset
  1134
		CrashAirplane(v);
0e42c4b151e3 (svn r1387) Fix: Airplanes now also crash when only one invalid order is in the schedule
dominik
parents: 899
diff changeset
  1135
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1136
	if (order->type    == v->current_order.type   &&
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1137
			order->flags   == v->current_order.flags  &&
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1138
			order->station == v->current_order.station)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1141
	v->current_order = *order;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
	// orders are changed in flight, ensure going to the right station
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1144
	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
  1145
		AircraftNextAirportPos_and_Order(v);
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1146
		v->u.air.targetairport = order->station;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1149
	InvalidateVehicleOrder(v);
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1150
1055
cc4f60cc9102 (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
  1151
	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
static void HandleAircraftLoading(Vehicle *v, int mode)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
{
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1156
	if (v->current_order.type == OT_NOTHING)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1159
	if (v->current_order.type != OT_DUMMY) {
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1160
		if (v->current_order.type != OT_LOADING)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1163
		if (mode != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
		if (--v->load_unload_time_rem)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1169
		if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
			SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
			LoadUnloadVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
		{
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1176
			Order b = v->current_order;
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1177
			v->current_order.type = OT_NOTHING;
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1178
			v->current_order.flags = 0;
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1179
			if (!(b.flags & OF_NON_STOP))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
	v->cur_order_index++;
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1020
diff changeset
  1184
	InvalidateVehicleOrder(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1186
899
69db9cb6bc9d (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
  1187
static void CrashAirplane(Vehicle *v)
69db9cb6bc9d (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
  1188
{
69db9cb6bc9d (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
  1189
	uint16 amt;
69db9cb6bc9d (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
  1190
	Station *st;
69db9cb6bc9d (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
  1191
	StringID newsitem;
69db9cb6bc9d (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
  1192
69db9cb6bc9d (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
  1193
	v->vehstatus |= VS_CRASHED;
69db9cb6bc9d (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
  1194
	v->u.air.crashed_counter = 0;
69db9cb6bc9d (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
  1195
69db9cb6bc9d (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
  1196
	CreateEffectVehicleRel(v, 4, 4, 8, EV_CRASHED_SMOKE);
69db9cb6bc9d (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
  1197
69db9cb6bc9d (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
  1198
	InvalidateWindow(WC_VEHICLE_VIEW, v->index);
69db9cb6bc9d (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
  1199
69db9cb6bc9d (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
  1200
	amt = 2;
69db9cb6bc9d (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
	if (v->cargo_type == CT_PASSENGERS) amt += v->cargo_count;
69db9cb6bc9d (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
  1202
	SetDParam(0, amt);
69db9cb6bc9d (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
  1203
69db9cb6bc9d (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
  1204
	v->cargo_count = 0;
69db9cb6bc9d (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->next->cargo_count = 0,
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1206
	st = GetStation(v->u.air.targetairport);
899
69db9cb6bc9d (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
  1207
	if(st->airport_tile==0) {
69db9cb6bc9d (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
  1208
		newsitem = STR_PLANE_CRASH_OUT_OF_FUEL;
69db9cb6bc9d (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
  1209
	} else {
69db9cb6bc9d (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
		SetDParam(1, st->index);
69db9cb6bc9d (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
		newsitem = STR_A034_PLANE_CRASH_DIE_IN_FIREBALL;
69db9cb6bc9d (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
  1212
	}
69db9cb6bc9d (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
  1213
69db9cb6bc9d (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
  1214
	SetDParam(1, st->index);
69db9cb6bc9d (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
  1215
	AddNewsItem(newsitem,
69db9cb6bc9d (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
  1216
		NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
69db9cb6bc9d (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
  1217
		v->index,
69db9cb6bc9d (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
  1218
		0);
69db9cb6bc9d (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
  1219
69db9cb6bc9d (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
  1220
	SndPlayVehicleFx(SND_12_EXPLOSION, v);
69db9cb6bc9d (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
  1221
}
69db9cb6bc9d (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
  1222
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
static void MaybeCrashAirplane(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1226
	uint16 prob;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1227
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1228
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1229
	st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
	//FIXME -- MaybeCrashAirplane -> increase crashing chances of very modern airplanes on smaller than AT_METROPOLITAN airports
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
	prob = 0x10000 / 1500;
538
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
  1233
	if (st->airport_type == AT_SMALL && (AircraftVehInfo(v->engine_type)->subtype & 2) && !_cheats.no_jetcrash.value) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
		prob = 0x10000 / 20;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
	if ((uint16)Random() > prob)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
	// Crash the airplane. Remove all goods stored at the station.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
	for(i=0; i!=NUM_CARGO; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
		st->goods[i].rating = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
		st->goods[i].waiting_acceptance &= ~0xFFF;
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
899
69db9cb6bc9d (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
  1246
	CrashAirplane(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1247
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
// we've landed and just arrived at a terminal
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1250
static void AircraftEntersTerminal(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
	Station *st;
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1253
	Order old_order;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1255
	if (v->current_order.type == OT_GOTO_DEPOT)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1258
	st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
	v->last_station_visited = v->u.air.targetairport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
	/* Check if station was ever visited before */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
	if (!(st->had_vehicle_of_type & HVOT_AIRCRAFT)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
		uint32 flags;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
		st->had_vehicle_of_type |= HVOT_AIRCRAFT;
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1266
		SetDParam(0, st->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
		// show newsitem of celebrating citizens
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
		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
  1269
		AddNewsItem(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
			STR_A033_CITIZENS_CELEBRATE_FIRST,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
			flags,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1272
			v->index,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
			0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1276
	old_order = v->current_order;
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1277
	v->current_order.type = OT_LOADING;
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1278
	v->current_order.flags = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1279
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1280
	if (old_order.type == OT_GOTO_STATION &&
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1281
			v->current_order.station == v->last_station_visited) {
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1282
		v->current_order.flags =
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1283
			(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD)) | OF_NON_STOP;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1285
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
	SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
	LoadUnloadVehicle(v);
755
80091de50044 (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
  1288
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
1055
cc4f60cc9102 (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
  1289
	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
0
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
1064
2242cd7419bb (svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents: 1055
diff changeset
  1292
static bool ValidateAircraftInHangar( uint data_a, uint data_b )
2242cd7419bb (svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents: 1055
diff changeset
  1293
{
2242cd7419bb (svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents: 1055
diff changeset
  1294
	Vehicle *v = GetVehicle(data_a);
2242cd7419bb (svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents: 1055
diff changeset
  1295
2242cd7419bb (svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents: 1055
diff changeset
  1296
	return (IsAircraftHangarTile(v->tile) && (v->vehstatus & VS_STOPPED));
2242cd7419bb (svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents: 1055
diff changeset
  1297
}
2242cd7419bb (svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents: 1055
diff changeset
  1298
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
static void AircraftEnterHangar(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
{
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1301
	Order old_order;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
	ServiceAircraft(v);
1055
cc4f60cc9102 (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
  1304
	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1305
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 817
diff changeset
  1306
	MaybeReplaceVehicle(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
445
beafc0fb8f12 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 410
diff changeset
  1308
	TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT);
beafc0fb8f12 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 410
diff changeset
  1309
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1310
	if (v->current_order.type == OT_GOTO_DEPOT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1312
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1313
		old_order = v->current_order;
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1314
		v->current_order.type = OT_NOTHING;
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1315
		v->current_order.flags = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1316
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1317
		if (old_order.flags & OF_UNLOAD) {
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1318
			v->cur_order_index++;
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1319
		} else if (old_order.flags & OF_FULL_LOAD) { // force depot visit
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1320
			v->vehstatus |= VS_STOPPED;
1055
cc4f60cc9102 (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
  1321
			InvalidateWindowClasses(WC_AIRCRAFT_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1322
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1323
			if (v->owner == _local_player) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1324
				SetDParam(0, v->unitnumber);
1064
2242cd7419bb (svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents: 1055
diff changeset
  1325
				AddValidatedNewsItem(
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1326
					STR_A014_AIRCRAFT_IS_WAITING_IN,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
					NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1328
					v->index,
1064
2242cd7419bb (svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents: 1055
diff changeset
  1329
					0,
2242cd7419bb (svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents: 1055
diff changeset
  1330
					ValidateAircraftInHangar);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1332
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1333
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1334
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1335
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
static void AircraftLand(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1337
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1338
	v->sprite_width = v->sprite_height = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1339
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
static void AircraftLandAirplane(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1342
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1343
	AircraftLand(v);
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 538
diff changeset
  1344
	SndPlayVehicleFx(SND_17_SKID_PLANE, v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1345
	MaybeCrashAirplane(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1346
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1348
// set the right pos when heading to other airports after takeoff
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1349
static void AircraftNextAirportPos_and_Order(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
	const AirportFTAClass *Airport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1354
	if (v->current_order.type == OT_GOTO_STATION ||
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1355
			v->current_order.type == OT_GOTO_DEPOT)
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1356
		v->u.air.targetairport = v->current_order.station;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1358
	st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
	Airport = GetAirport(st->airport_type);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
	v->u.air.pos = v->u.air.previous_pos = Airport->entry_point;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1363
static void AircraftLeaveHangar(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1364
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
	v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
	v->subspeed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
	v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1368
	v->direction = 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1369
	v->vehstatus &= ~VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
		Vehicle *u = v->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
		u->vehstatus &= ~VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1374
		// Rotor blades
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1375
		if ((u=u->next) != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1376
			u->vehstatus &= ~VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
			u->cur_speed = 80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1378
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1379
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1380
578
1e66514eb621 (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
  1381
	VehicleServiceInDepot(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
	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
  1383
	InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
1055
cc4f60cc9102 (svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents: 1053
diff changeset
  1384
	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1386
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
////////////////////////////////////////////////////////////////////////////////
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
///////////////////   AIRCRAFT MOVEMENT SCHEME  ////////////////////////////////
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
////////////////////////////////////////////////////////////////////////////////
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
static void AircraftEventHandler_EnterTerminal(Vehicle *v, const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
	AircraftEntersTerminal(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1394
	v->u.air.state = Airport->layout[v->u.air.pos].heading;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1396
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1397
static void AircraftEventHandler_EnterHangar(Vehicle *v, const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1398
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
	AircraftEnterHangar(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
	v->u.air.state = Airport->layout[v->u.air.pos].heading;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1402
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
// In an Airport Hangar
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
static void AircraftEventHandler_InHangar(Vehicle *v, const AirportFTAClass *Airport)
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
	// if we just arrived, execute EnterHangar first
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
	if (v->u.air.previous_pos != v->u.air.pos) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
		AircraftEventHandler_EnterHangar(v, Airport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1410
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1411
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1412
	// if we were sent to the depot, stay there
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1413
	if (v->current_order.type == OT_GOTO_DEPOT && (v->vehstatus & VS_STOPPED)) {
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1414
		v->current_order.type = OT_NOTHING;
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1415
		v->current_order.flags = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1419
	if (v->current_order.type != OT_GOTO_STATION &&
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1420
			v->current_order.type != OT_GOTO_DEPOT)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1421
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1422
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1423
	// if the block of the next position is busy, stay put
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1424
	if (AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) {return;}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1425
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1426
	// We are already at the target airport, we need to find a terminal
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1427
	if (v->current_order.station == v->u.air.targetairport) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1428
		// FindFreeTerminal:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1429
		// 1. Find a free terminal, 2. Occupy it, 3. Set the vehicle's state to that terminal
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1430
		if (v->subtype != 0) {if(!AirportFindFreeTerminal(v, Airport)) {return;}} // airplane
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1431
		else {if(!AirportFindFreeHelipad(v, Airport)) {return;}} // helicopter
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1432
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1433
	else { // Else prepare for launch.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1434
		// airplane goto state takeoff, helicopter to helitakeoff
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
		v->u.air.state = (v->subtype != 0) ? TAKEOFF : HELITAKEOFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1436
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1437
	AircraftLeaveHangar(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1438
	AirportMove(v, Airport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1439
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1440
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1441
// At one of the Airport's Terminals
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1442
static void AircraftEventHandler_AtTerminal(Vehicle *v, const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1444
	// if we just arrived, execute EnterTerminal first
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
	if (v->u.air.previous_pos != v->u.air.pos) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
		AircraftEventHandler_EnterTerminal(v, Airport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
		// on an airport with helipads, a helicopter will always land there
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
		// and get serviced at the same time - patch setting
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1449
		if (_patches.serviceathelipad) {
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1450
			if (v->subtype == 0 && Airport->helipads != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
				// an exerpt of ServiceAircraft, without the invisibility stuff
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
				v->date_of_last_service = _date;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
				v->breakdowns_since_last_service = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
				v->reliability = _engines[v->engine_type].reliability;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1455
				InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1456
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1457
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1461
	if (v->current_order.type == OT_NOTHING) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1462
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
	// if the block of the next position is busy, stay put
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
	if (AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1466
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
	// airport-road is free. We either have to go to another airport, or to the hangar
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
	// ---> start moving
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1470
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1471
	switch (v->current_order.type) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1472
		case OT_GOTO_STATION: // ready to fly to another airport
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1473
			// airplane goto state takeoff, helicopter to helitakeoff
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
			v->u.air.state = (v->subtype != 0) ? TAKEOFF : HELITAKEOFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1476
		case OT_GOTO_DEPOT:   // visit hangar for serivicing, sale, etc.
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1477
			if (v->current_order.station == v->u.air.targetairport)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
				v->u.air.state = HANGAR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1479
			else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1480
				v->u.air.state = (v->subtype != 0) ? TAKEOFF : HELITAKEOFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1481
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
		default:  // orders have been deleted (no orders), goto depot and don't bother us
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1483
			v->current_order.type = OT_NOTHING;
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1484
			v->current_order.flags = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1485
			v->u.air.state = HANGAR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1486
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1487
	AirportMove(v, Airport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1488
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1489
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1490
static void AircraftEventHandler_General(Vehicle *v, const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1491
{
70
60216d94f7c1 (svn r71) -Cheat: [976127] no extra frequent jet crash on small airports (truesatan)
darkvater
parents: 19
diff changeset
  1492
	DEBUG(misc, 0) ("OK, you shouldn't be here, check your Airport Scheme!");
60216d94f7c1 (svn r71) -Cheat: [976127] no extra frequent jet crash on small airports (truesatan)
darkvater
parents: 19
diff changeset
  1493
	assert(0);
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
static void AircraftEventHandler_TakeOff(Vehicle *v, const AirportFTAClass *Airport) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1497
	PlayAircraftSound(v); // play takeoffsound for airplanes
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1498
	v->u.air.state = STARTTAKEOFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1499
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1500
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1501
static void AircraftEventHandler_StartTakeOff(Vehicle *v, const AirportFTAClass *Airport)
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
	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
  1504
	v->u.air.state = ENDTAKEOFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1505
}
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
static void AircraftEventHandler_EndTakeOff(Vehicle *v, const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1508
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1509
	v->u.air.state = FLYING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1510
	// get the next position to go to, differs per airport
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1511
	AircraftNextAirportPos_and_Order(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1512
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1513
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
static void AircraftEventHandler_HeliTakeOff(Vehicle *v, const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
	v->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
  1517
	v->u.air.state = FLYING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1518
	// get the next position to go to, differs per airport
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1519
	AircraftNextAirportPos_and_Order(v);
1135
6c3b6e855c98 (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
  1520
6c3b6e855c98 (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
  1521
	// check if the aircraft needs to be replaced or renewed and send it to a hangar if needed
1194
2b25b1477623 (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
  1522
	if (v->current_order.type != OT_GOTO_DEPOT && v->owner == _local_player) {
2b25b1477623 (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
  1523
		// only the vehicle owner needs to calculate the rest (locally)
2b25b1477623 (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
  1524
		if ((_autoreplace_array[v->engine_type] != v->engine_type) ||
2b25b1477623 (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
  1525
			(_patches.autorenew && v->age - v->max_age > (_patches.autorenew_months * 30))) {
2b25b1477623 (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
  1526
2b25b1477623 (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
  1527
			if (v->set_for_replacement) {
2b25b1477623 (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
  1528
				Station *st = GetStation(v->u.air.targetairport);
2b25b1477623 (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
  1529
				// If an airport doesn't have terminals (so no landing space for airports),
2b25b1477623 (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
  1530
				// it surely doesn't have any hangars
2b25b1477623 (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
  1531
				if (st->xy == 0 || st->airport_tile == 0 || GetAirport(st->airport_type)->terminals == NULL)
2b25b1477623 (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
  1532
					return;
2b25b1477623 (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
  1533
				/* this is not the airport, where the helicopter will be replaced
2b25b1477623 (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
  1534
					No need to make everybody check this, since it would be a waste of bandwidth */
2b25b1477623 (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
  1535
			}
2b25b1477623 (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
  1536
2b25b1477623 (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
  1537
			{
2b25b1477623 (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
  1538
				bool has_hangar = HaveHangarInOrderList(v); // this info is needed twice, but we only want to loop the orders once ;)
2b25b1477623 (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
  1539
				uint32 next_airport = 0;
2b25b1477623 (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
  1540
2b25b1477623 (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
  1541
				if (!has_hangar) {
2b25b1477623 (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
  1542
					// the helicopter needs help to find a hangar since there are none in the schedule
2b25b1477623 (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
  1543
					SETBIT(next_airport, 17);
2b25b1477623 (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
  1544
					next_airport |= FindNearestHangar(v);
2b25b1477623 (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
  1545
					if (HASBIT(next_airport, 16)) {
2b25b1477623 (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
  1546
						/* when shared airports are allowed, a check for a rentable hangar should be added here */
2b25b1477623 (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
  1547
						/* TODO: tell the player that he needs a hangar */
2b25b1477623 (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
  1548
						v->set_for_replacement = false; //needed so it will check again later when the player might have build a hangar
2b25b1477623 (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
  1549
						return; // player do not own any hangars
2b25b1477623 (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
  1550
					}
2b25b1477623 (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
  1551
				}
2b25b1477623 (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
  1552
				SETBIT(next_airport, 16);
2b25b1477623 (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
  1553
				_current_player = _local_player;
2b25b1477623 (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
  1554
				DoCommandP(v->tile, v->index, next_airport, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR);
2b25b1477623 (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
  1555
				_current_player = OWNER_NONE;
2b25b1477623 (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
  1556
			}
1206
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
  1557
		} else { // no need to go to a depot
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
  1558
			if (v->set_for_replacement) {
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
  1559
				// it seems that the user clicked "Stop replacing"
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
  1560
				_current_player = _local_player;
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
  1561
				DoCommandP(v->tile, v->index, (1 | (1 << 2)) << 16, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR);
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
  1562
				_current_player = OWNER_NONE;
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
  1563
			}
1194
2b25b1477623 (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
  1564
		}
1135
6c3b6e855c98 (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
  1565
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1566
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1567
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1568
static void AircraftEventHandler_Flying(Vehicle *v, const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1570
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1571
	byte landingtype;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1572
	AirportFTA *current;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1573
	uint16 tcur_speed, tsubspeed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1574
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1575
	st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1576
	// flying device is accepted at this station
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
	// small airport --> no helicopters (AIRCRAFT_ONLY)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1578
	// all other airports --> all types of flying devices (ALL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1579
	// heliport/oilrig, etc --> no airplanes (HELICOPTERS_ONLY)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1580
	// runway busy or not allowed to use this airstation, circle
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1581
	if (! (v->subtype == Airport->acc_planes ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1582
			st->airport_tile == 0 || (st->owner != OWNER_NONE && st->owner != v->owner) )) {
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
		// {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
  1585
		// 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
  1586
		// it is possible to choose from multiple landing runways, so loop until a free one is found
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1587
		landingtype = (v->subtype != 0) ? LANDING : HELILANDING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1588
		current = Airport->layout[v->u.air.pos].next_in_chain;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1589
		while (current != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1590
			if (current->heading == landingtype) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1591
				// save speed before, since if AirportHasBlock is false, it resets them to 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1592
				// we don't want that for plane in air
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1593
				// hack for speed thingie
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1594
				tcur_speed = v->cur_speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1595
				tsubspeed = v->subspeed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1596
				if (!AirportHasBlock(v, current, Airport)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1597
					v->u.air.state = landingtype; // LANDING / HELILANDING
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1598
					// it's a bit dirty, but I need to set position to next position, otherwise
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1599
					// if there are multiple runways, plane won't know which one it took (because
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1600
					// they all have heading LANDING). And also occupy that block!
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1601
					v->u.air.pos = current->next_position;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1602
					SETBITS(st->airport_flags, Airport->layout[v->u.air.pos].block);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1603
					return;
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
				v->cur_speed = tcur_speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1606
				v->subspeed = tsubspeed;
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
			current = current->next_in_chain;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1609
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1610
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1611
	v->u.air.state = FLYING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1612
	v->u.air.pos = Airport->layout[v->u.air.pos].next_position;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1613
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1614
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1615
static void AircraftEventHandler_Landing(Vehicle *v, const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1616
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1617
	AircraftLandAirplane(v);  // maybe crash airplane
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1618
	v->u.air.state = ENDLANDING;
1195
54d50ac3311a (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
  1619
	// check if the aircraft needs to be replaced or renewed and send it to a hangar if needed
54d50ac3311a (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
  1620
	if (v->current_order.type != OT_GOTO_DEPOT && v->owner == _local_player) {
54d50ac3311a (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
  1621
		// only the vehicle owner needs to calculate the rest (locally)
54d50ac3311a (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
  1622
		if ((_autoreplace_array[v->engine_type] != v->engine_type) ||
54d50ac3311a (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
  1623
			(_patches.autorenew && v->age - v->max_age > (_patches.autorenew_months * 30))) {
54d50ac3311a (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
  1624
			// send the aircraft to the hangar at next airport
54d50ac3311a (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
  1625
			_current_player = _local_player;
54d50ac3311a (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
  1626
			DoCommandP(v->tile, v->index, 1 << 16, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR);
54d50ac3311a (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
  1627
			_current_player = OWNER_NONE;
1206
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
  1628
		} else { // no need to go to a depot
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
  1629
			if (v->set_for_replacement) {
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
  1630
				// it seems that the user clicked "Stop replacing"
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
  1631
				_current_player = _local_player;
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
  1632
				DoCommandP(v->tile, v->index, (1 | (1 << 2)) << 16, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR);
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
  1633
				_current_player = OWNER_NONE;
5d3c1d2c3214 (svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents: 1204
diff changeset
  1634
			}
1195
54d50ac3311a (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
  1635
		}
54d50ac3311a (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
  1636
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1637
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1638
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1639
static void AircraftEventHandler_HeliLanding(Vehicle *v, const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1641
	AircraftLand(v); // helicopters don't crash
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1642
	v->u.air.state = HELIENDLANDING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1643
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
static void AircraftEventHandler_EndLanding(Vehicle *v, const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1646
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1647
	// next block busy, don't do a thing, just wait
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1648
	if(AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) {return;}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1649
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1650
	// if going to terminal (OT_GOTO_STATION) choose one
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1651
	// 1. in case all terminals are busy AirportFindFreeTerminal() returns false or
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1652
	// 2. not going for terminal (but depot, no order),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1653
	// --> get out of the way to the hangar.
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1654
	if (v->current_order.type == OT_GOTO_STATION) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1655
		if (AirportFindFreeTerminal(v, Airport)) {return;}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1656
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1657
	v->u.air.state = HANGAR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1658
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1661
static void AircraftEventHandler_HeliEndLanding(Vehicle *v, const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1662
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1663
	// next block busy, don't do a thing, just wait
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1664
	if(AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) {return;}
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
	// if going to helipad (OT_GOTO_STATION) choose one. If airport doesn't have helipads, choose terminal
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1667
	// 1. in case all terminals/helipads are busy (AirportFindFreeHelipad() returns false) or
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1668
	// 2. not going for terminal (but depot, no order),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1669
	// --> get out of the way to the hangar IF there are terminals on the airport.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1670
	// --> else TAKEOFF
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1671
	// the reason behind this is that if an airport has a terminal, it also has a hangar. Airplanes
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1672
	// must go to a hangar.
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1673
	if (v->current_order.type == OT_GOTO_STATION) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1674
		if (AirportFindFreeHelipad(v, Airport)) {return;}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1675
	}
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1676
	v->u.air.state = (Airport->terminals != NULL) ? HANGAR : HELITAKEOFF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1677
}
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
typedef void AircraftStateHandler(Vehicle *v, const AirportFTAClass *Airport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1680
static AircraftStateHandler * const _aircraft_state_handlers[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1681
	AircraftEventHandler_General,				// TO_ALL         =  0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1682
	AircraftEventHandler_InHangar,			// HANGAR         =  1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1683
	AircraftEventHandler_AtTerminal,		// TERM1          =  2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1684
	AircraftEventHandler_AtTerminal,		// TERM2          =  3
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1685
	AircraftEventHandler_AtTerminal,		// TERM3          =  4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1686
	AircraftEventHandler_AtTerminal,		// TERM4          =  5
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1687
	AircraftEventHandler_AtTerminal,		// TERM5          =  6
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1688
	AircraftEventHandler_AtTerminal,		// TERM6          =  7
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1689
	AircraftEventHandler_AtTerminal,		// HELIPAD1       =  8
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1690
	AircraftEventHandler_AtTerminal,		// HELIPAD2       =  9
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1691
	AircraftEventHandler_TakeOff,				// TAKEOFF        = 10
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1692
	AircraftEventHandler_StartTakeOff,	// STARTTAKEOFF   = 11
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1693
	AircraftEventHandler_EndTakeOff,		// ENDTAKEOFF     = 12
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1694
	AircraftEventHandler_HeliTakeOff,		// HELITAKEOFF    = 13
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1695
	AircraftEventHandler_Flying,				// FLYING         = 14
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1696
	AircraftEventHandler_Landing,				// LANDING        = 15
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1697
	AircraftEventHandler_EndLanding,		// ENDLANDING     = 16
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1698
	AircraftEventHandler_HeliLanding,		// HELILANDING    = 17
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1699
	AircraftEventHandler_HeliEndLanding,// HELIENDLANDING = 18
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1700
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1701
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1702
static void AirportClearBlock(Vehicle *v, const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1703
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1704
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1705
	// we have left the previous block, and entered the new one. Free the previous block
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1706
	if (Airport->layout[v->u.air.previous_pos].block != Airport->layout[v->u.air.pos].block) {
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1707
		st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1708
		CLRBITS(st->airport_flags, Airport->layout[v->u.air.previous_pos].block);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1709
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1710
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1711
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1712
static void AirportGoToNextPosition(Vehicle *v, const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1713
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1714
	// if aircraft is not in position, wait until it is
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1715
	if (!Aircraft_5(v)) {return;}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1716
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1717
	AirportClearBlock(v, Airport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1718
	AirportMove(v, Airport); // move aircraft to next position
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1719
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1720
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1721
// gets pos from vehicle and next orders
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1722
static bool AirportMove(Vehicle *v, const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1723
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1724
	AirportFTA *current;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1725
	byte prev_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1726
	bool retval = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1727
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1728
	// error handling
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1729
	if (v->u.air.pos >= Airport->nofelements) {
70
60216d94f7c1 (svn r71) -Cheat: [976127] no extra frequent jet crash on small airports (truesatan)
darkvater
parents: 19
diff changeset
  1730
		DEBUG(misc, 0) ("position %d is not valid for current airport. Max position is %d", v->u.air.pos, Airport->nofelements-1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1731
		assert(v->u.air.pos < Airport->nofelements);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1732
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1733
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1734
	current = &Airport->layout[v->u.air.pos];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1735
	// we have arrived in an important state (eg terminal, hangar, etc.)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1736
	if (current->heading == v->u.air.state) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1737
		prev_pos = v->u.air.pos; // location could be changed in state, so save it before-hand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1738
		_aircraft_state_handlers[v->u.air.state](v, Airport);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1739
		if (v->u.air.state != FLYING) {v->u.air.previous_pos = prev_pos;}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1740
		return true;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1743
	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
  1744
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1745
	// there is only one choice to move to
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1746
	if (current->next_in_chain == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1747
		if (AirportSetBlocks(v, current, Airport)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1748
			v->u.air.pos = current->next_position;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1749
		} // move to next position
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1750
		return retval;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1753
	// there are more choices to choose from, choose the one that
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1754
	// matches our heading
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1755
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1756
		if (v->u.air.state == current->heading || current->heading == TO_ALL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1757
					if (AirportSetBlocks(v, current, Airport)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1758
						v->u.air.pos = current->next_position;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1759
					} // move to next position
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
					return retval;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1761
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1762
		current = current->next_in_chain;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1763
	} while (current != NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1764
70
60216d94f7c1 (svn r71) -Cheat: [976127] no extra frequent jet crash on small airports (truesatan)
darkvater
parents: 19
diff changeset
  1765
	DEBUG(misc, 0) ("Cannot move further on Airport...! pos:%d state:%d", v->u.air.pos, v->u.air.state);
60216d94f7c1 (svn r71) -Cheat: [976127] no extra frequent jet crash on small airports (truesatan)
darkvater
parents: 19
diff changeset
  1766
	DEBUG(misc, 0) ("Airport entry point: %d, Vehicle: %d", Airport->entry_point, v->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1767
	assert(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1768
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1769
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1770
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1771
// returns true if the road ahead is busy, eg. you must wait before proceeding
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1772
static bool AirportHasBlock(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1773
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1774
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1775
	uint32 airport_flags;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1776
	AirportFTA *next, *reference;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1777
	reference = &Airport->layout[v->u.air.pos];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1778
	next = &Airport->layout[current_pos->next_position];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1779
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1780
	// same block, then of course we can move
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1781
	if (Airport->layout[current_pos->position].block != next->block) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1782
		airport_flags = next->block;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1783
		st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1784
		// check additional possible extra blocks
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1785
		if (current_pos != reference && current_pos->block != NOTHING_block) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1786
			airport_flags |= current_pos->block;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1787
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1788
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1789
		if (HASBITS(st->airport_flags, airport_flags)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1790
			v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1791
			v->subspeed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1792
			return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1793
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1794
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1795
	return false;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1798
// returns true on success. Eg, next block was free and we have occupied it
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1799
static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1800
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1801
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1802
	uint32 airport_flags;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1803
	AirportFTA *current, *reference, *next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1804
	next = &Airport->layout[current_pos->next_position];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1805
	reference = &Airport->layout[v->u.air.pos];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1806
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1807
	// if the next position is in another block, check it and wait until it is free
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1808
	if (Airport->layout[current_pos->position].block != next->block) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1809
		airport_flags = next->block;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1810
		st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1811
		//search for all all elements in the list with the same state, and blocks != N
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1812
		// this means more blocks should be checked/set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1813
		current = current_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1814
		if (current == reference) { current = current->next_in_chain;}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1815
		while (current != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1816
			if (current->heading == current_pos->heading && current->block != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1817
				airport_flags |= current->block;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1818
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1819
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1820
			current = current->next_in_chain;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1821
		};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1822
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1823
		// if the block to be checked is in the next position, then exclude that from
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1824
		// checking, because it has been set by the airplane before
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1825
		if (current_pos->block == next->block) {airport_flags ^= next->block;}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1826
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1827
		if (HASBITS(st->airport_flags, airport_flags)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1828
			v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1829
			v->subspeed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1830
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1831
		}
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
		if (next->block != NOTHING_block) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1834
			SETBITS(st->airport_flags, airport_flags); // occupy next block
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1835
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1836
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1837
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1838
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1839
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1840
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
  1841
{
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1842
	Station *st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1843
	for (; i < last_terminal; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1844
		if (!HASBIT(st->airport_flags, i)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1845
			// TERMINAL# HELIPAD#
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1846
			v->u.air.state = i + TERM1; // start moving to that terminal/helipad
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1847
			SETBIT(st->airport_flags, i); // occupy terminal/helipad
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1848
			return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1849
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1850
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1851
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1852
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1853
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1854
static int GetNumTerminals(const AirportFTAClass *Airport)
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1855
{
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1856
	int i, num = 0;
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1018
diff changeset
  1857
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1858
	for (i = Airport->terminals[0]; i > 0; i--)
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1859
		num += Airport->terminals[i];
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1018
diff changeset
  1860
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1861
	return num;
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1862
}
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1863
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1864
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1865
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1866
	AirportFTA *temp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1867
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1868
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1869
	/* example of more terminalgroups
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1870
		{0,HANGAR,NOTHING_block,1}, {0,255,TERM_GROUP1_block,0}, {0,255,TERM_GROUP2_ENTER_block,1}, {0,0,N,1},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1871
		Heading 255 denotes a group. We see 2 groups here:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1872
		1. group 0 -- TERM_GROUP1_block (check block)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1873
		2. group 1 -- TERM_GROUP2_ENTER_block (check block)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1874
		First in line is checked first, group 0. If the block (TERM_GROUP1_block) is free, it
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1875
		looks	at the corresponding terminals of that group. If no free ones are found, other
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1876
		possible groups are checked	(in this case group 1, since that is after group 0). If that
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1877
		fails, then attempt fails and plane waits
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1878
	*/
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1879
	if (Airport->terminals[0] > 1) {
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1880
		st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1881
		temp = Airport->layout[v->u.air.pos].next_in_chain;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1882
		while (temp != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1883
			if (temp->heading == 255) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1884
				if (!HASBITS(st->airport_flags, temp->block)) {
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1885
					int target_group;
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1886
					int i;
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1887
					int group_start = 0;
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1888
					int group_end;
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1889
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1890
					//read which group do we want to go to?
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1891
					//(the first free group)
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1892
					target_group = temp->next_position + 1;
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1893
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1894
					//at what terminal does the group start?
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1895
					//that means, sum up all terminals of
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1896
					//groups with lower number
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1897
					for(i = 1; i < target_group; i++)
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1898
						group_start += Airport->terminals[i];
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1899
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1900
					group_end = group_start + Airport->terminals[target_group];
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1901
					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
  1902
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1903
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1904
			else {return false;} // once the heading isn't 255, we've exhausted the possible blocks. So we cannot move
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1905
			temp = temp->next_in_chain;
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1908
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1909
	// if there is only 1 terminalgroup, all terminals are checked (starting from 0 to max)
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1910
	return FreeTerminal(v, 0, GetNumTerminals(Airport));
0
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
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1913
static int GetNumHelipads(const AirportFTAClass *Airport)
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1914
{
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1915
	int i, num = 0;
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1018
diff changeset
  1916
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1917
	for (i = Airport->helipads[0]; i > 0; i--)
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1918
		num += Airport->helipads[i];
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1018
diff changeset
  1919
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1920
	return num;
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1921
}
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1922
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1923
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1924
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1926
  Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1927
  AirportFTA *temp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1928
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
	// if an airport doesn't have helipads, use terminals
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1930
	if (Airport->helipads == NULL) {return AirportFindFreeTerminal(v, Airport);}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1931
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1932
	// if there are more helicoptergroups, pick one, just as in AirportFindFreeTerminal()
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1933
	if (Airport->helipads[0] > 1) {
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1934
		st = GetStation(v->u.air.targetairport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1935
		temp = Airport->layout[v->u.air.pos].next_in_chain;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1936
		while (temp != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1937
			if (temp->heading == 255) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1938
				if (!HASBITS(st->airport_flags, temp->block)) {
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1939
					int target_group;
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1940
					int i;
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1941
					int group_start = 0;
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1942
					int group_end;
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1943
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1944
					//read which group do we want to go to?
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1945
					//(the first free group)
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1946
					target_group = temp->next_position + 1;
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1947
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1948
					//at what terminal does the group start?
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1949
					//that means, sum up all terminals of
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1950
					//groups with lower number
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1951
					for(i = 1; i < target_group; i++)
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1952
						group_start += Airport->helipads[i];
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1953
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1954
					group_end = group_start + Airport->helipads[target_group];
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1955
					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
  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
			else {return false;} // once the heading isn't 255, we've exhausted the possible blocks. So we cannot move
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1959
			temp = temp->next_in_chain;
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1962
	// only 1 helicoptergroup, check all helipads
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1963
	// The blocks for helipads start after the last terminal (MAX_TERMINALS)
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  1964
	else {return FreeTerminal(v, MAX_TERMINALS, GetNumHelipads(Airport) + MAX_TERMINALS);}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1965
	return false;	// it shouldn't get here anytime, but just to be sure
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1966
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1967
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1968
static void AircraftEventHandler(Vehicle *v, int loop)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1969
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1970
	v->tick_counter++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1971
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1972
	if (v->vehstatus & VS_CRASHED) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1973
		HandleCrashedAircraft(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1974
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1975
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1976
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1977
	/* exit if aircraft is stopped */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1978
	if (v->vehstatus & VS_STOPPED)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1979
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1980
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1981
	/* aircraft is broken down? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1982
	if (v->breakdown_ctr != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1983
		if (v->breakdown_ctr <= 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1984
			HandleBrokenAircraft(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1985
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1986
			v->breakdown_ctr--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1987
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1988
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1989
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1990
	HandleAircraftSmoke(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1991
	ProcessAircraftOrder(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1992
	HandleAircraftLoading(v, loop);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1993
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1994
	if (v->current_order.type >= OT_LOADING)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1995
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1996
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1997
	// pass the right airport structure to the functions
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1998
	// DEREF_STATION gets target airport (Station *st), its type is passed to GetAirport
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1999
	// that returns the correct layout depending on type
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  2000
	AirportGoToNextPosition(v, GetAirport(GetStation(v->u.air.targetairport)->airport_type));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2001
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2002
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2003
void Aircraft_Tick(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2004
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2005
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2006
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2007
	if (v->subtype > 2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2008
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2009
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2010
	if (v->subtype == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2011
		HelicopterTickHandler(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2012
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2013
	AgeAircraftCargo(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2014
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2015
	for(i=0; i!=6; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2016
		AircraftEventHandler(v, i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2017
		if (v->type != VEH_Aircraft) // In case it was deleted
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2018
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2019
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2020
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2021
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2022
void UpdateOilRig( void )
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2023
{
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2024
	Station *st;
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1018
diff changeset
  2025
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2026
	FOR_ALL_STATIONS(st) {
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2027
		if (st->airport_type == 5) st->airport_type = AT_OILRIG;
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2028
	}
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2029
}
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 926
diff changeset
  2030
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2031
// need to be called to load aircraft from old version
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1064
diff changeset
  2032
void UpdateOldAircraft(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2033
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2034
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2035
	Vehicle *v_oldstyle;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2036
	GetNewVehiclePosResult gp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2037
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2038
	// set airport_flags to 0 for all airports just to be sure
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2039
	FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2040
		st->airport_flags = 0; // reset airport
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2041
		// type of oilrig has been moved, update it (3-5)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2042
		if (st->airport_type == 3) {st->airport_type = AT_OILRIG;}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2043
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2044
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2045
	FOR_ALL_VEHICLES(v_oldstyle) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2046
	// airplane has another vehicle with subtype 4 (shadow), helicopter also has 3 (rotor)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2047
	// skip those
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2048
		if (v_oldstyle->type == VEH_Aircraft && v_oldstyle->subtype <= 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2049
			// airplane in terminal stopped doesn't hurt anyone, so goto next
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2050
			if ((v_oldstyle->vehstatus & VS_STOPPED) && (v_oldstyle->u.air.state == 0)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2051
				v_oldstyle->u.air.state = HANGAR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2052
				continue;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2053
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2054
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2055
			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
  2056
			v_oldstyle->vehstatus &= ~VS_STOPPED; // make airplane moving
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2057
			v_oldstyle->u.air.state = FLYING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2058
			AircraftNextAirportPos_and_Order(v_oldstyle); // move it to the entry point of the airport
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2059
			GetNewVehiclePos(v_oldstyle, &gp); // get the position of the plane (to be used for setting)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2060
			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
  2061
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2062
			// correct speed of helicopter-rotors
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2063
			if (v_oldstyle->subtype == 0) {v_oldstyle->next->next->cur_speed = 32;}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2064
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2065
			// set new position x,y,z
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2066
			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
  2067
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2068
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2069
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2070
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  2071
void UpdateAirplanesOnNewStation(Station *st)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2072
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2073
	GetNewVehiclePosResult gp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2074
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2075
	byte takeofftype;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2076
	uint16 cnt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2077
	// only 1 station is updated per function call, so it is enough to get entry_point once
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2078
	const AirportFTAClass *ap = GetAirport(st->airport_type);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2079
	FOR_ALL_VEHICLES(v) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2080
		if (v->type == VEH_Aircraft && v->subtype <= 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2081
			if (v->u.air.targetairport == st->index) {	// if heading to this airport
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2082
				/*	update position of airplane. If plane is not flying, landing, or taking off
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2083
						you cannot delete airport, so it doesn't matter
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
				if (v->u.air.state >= FLYING) {	// circle around
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2086
					v->u.air.pos = v->u.air.previous_pos = ap->entry_point;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2087
					v->u.air.state = FLYING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2088
					// landing plane needs to be reset to flying height (only if in pause mode upgrade,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2089
					// in normal mode, plane is reset in Aircraft_5. It doesn't hurt for FLYING
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2090
					GetNewVehiclePos(v, &gp);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2091
					// set new position x,y,z
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2092
					SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2093
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2094
				else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2095
					assert(v->u.air.state == ENDTAKEOFF || v->u.air.state == HELITAKEOFF);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2096
					takeofftype = (v->subtype == 0) ? HELITAKEOFF : ENDTAKEOFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2097
					// search in airportdata for that heading
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2098
					// easiest to do, since this doesn't happen a lot
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2099
					for (cnt = 0; cnt < ap->nofelements; cnt++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2100
						if (ap->layout[cnt].heading == takeofftype) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2101
							v->u.air.pos = ap->layout[cnt].position;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2102
							break;
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
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2106
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2107
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2108
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2109
}