author | KUDr |
Fri, 20 Apr 2007 19:43:06 +0000 | |
changeset 6513 | 454347ca3dfb |
parent 6502 | 8056fdc57aa9 |
child 6546 | 4c6d90bde803 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6117
6507b2a7e71d
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6100
diff
changeset
|
3 |
/** @file aircraft_cmd.cpp |
6507b2a7e71d
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6100
diff
changeset
|
4 |
* This file deals with aircraft and airport movements functionalities */ |
6507b2a7e71d
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6100
diff
changeset
|
5 |
|
0 | 6 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1877
diff
changeset
|
7 |
#include "openttd.h" |
3963
6cab57074a9a
(svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
3955
diff
changeset
|
8 |
#include "aircraft.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1282
diff
changeset
|
9 |
#include "debug.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2140
diff
changeset
|
10 |
#include "functions.h" |
6453
226bcddeba32
(svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents:
6415
diff
changeset
|
11 |
#include "landscape.h" |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3186
diff
changeset
|
12 |
#include "station_map.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
458
diff
changeset
|
13 |
#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
|
14 |
#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
|
15 |
#include "tile.h" |
0 | 16 |
#include "vehicle.h" |
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1786
diff
changeset
|
17 |
#include "depot.h" |
0 | 18 |
#include "engine.h" |
19 |
#include "command.h" |
|
20 |
#include "station.h" |
|
21 |
#include "news.h" |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
22 |
#include "sound.h" |
0 | 23 |
#include "player.h" |
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
24 |
#include "aircraft.h" |
0 | 25 |
#include "airport.h" |
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1614
diff
changeset
|
26 |
#include "vehicle_gui.h" |
2517
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2504
diff
changeset
|
27 |
#include "table/sprites.h" |
2962
f0a49b646c48
(svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents:
2952
diff
changeset
|
28 |
#include "newgrf_engine.h" |
3973
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
29 |
#include "newgrf_callbacks.h" |
4244
d40c73c55357
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
30 |
#include "newgrf_text.h" |
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
31 |
#include "newgrf_sound.h" |
4261
28670f743746
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4259
diff
changeset
|
32 |
#include "date.h" |
5972
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
33 |
#include "spritecache.h" |
6340
df75644b9f06
(svn r9352) -Codechange: Use cargo class to determine if an aircraft should carry mail
peter1138
parents:
6334
diff
changeset
|
34 |
#include "cargotype.h" |
0 | 35 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
36 |
/** this maps the terminal to its corresponding state and block flag |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
37 |
* currently set for 10 terms, 4 helipads */ |
5754
086187883012
(svn r8305) -Codechange: defining 'static const' in a header is a bit weird.
truelight
parents:
5668
diff
changeset
|
38 |
static const byte _airport_terminal_state[] = {2, 3, 4, 5, 6, 7, 19, 20, 0, 0, 8, 9, 21, 22}; |
086187883012
(svn r8305) -Codechange: defining 'static const' in a header is a bit weird.
truelight
parents:
5668
diff
changeset
|
39 |
static const byte _airport_terminal_flag[] = {0, 1, 2, 3, 4, 5, 22, 23, 0, 0, 6, 7, 24, 25}; |
086187883012
(svn r8305) -Codechange: defining 'static const' in a header is a bit weird.
truelight
parents:
5668
diff
changeset
|
40 |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
41 |
static bool AirportMove(Vehicle *v, const AirportFTAClass *apc); |
6087 | 42 |
static bool AirportSetBlocks(Vehicle *v, const AirportFTA *current_pos, const AirportFTAClass *apc); |
4843
4bef85baee3f
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
43 |
static bool AirportHasBlock(Vehicle *v, const AirportFTA *current_pos, const AirportFTAClass *apc); |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
44 |
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *apc); |
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
45 |
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *apc); |
899
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
|
46 |
static void CrashAirplane(Vehicle *v); |
0 | 47 |
|
48 |
static void AircraftNextAirportPos_and_Order(Vehicle *v); |
|
49 |
static byte GetAircraftFlyingAltitude(const Vehicle *v); |
|
50 |
||
51 |
static const SpriteID _aircraft_sprite[] = { |
|
52 |
0x0EB5, 0x0EBD, 0x0EC5, 0x0ECD, |
|
53 |
0x0ED5, 0x0EDD, 0x0E9D, 0x0EA5, |
|
54 |
0x0EAD, 0x0EE5, 0x0F05, 0x0F0D, |
|
55 |
0x0F15, 0x0F1D, 0x0F25, 0x0F2D, |
|
56 |
0x0EED, 0x0EF5, 0x0EFD, 0x0F35, |
|
57 |
0x0E9D, 0x0EA5, 0x0EAD, 0x0EB5, |
|
58 |
0x0EBD, 0x0EC5 |
|
59 |
}; |
|
60 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
61 |
/** Helicopter rotor animation states */ |
3710
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
62 |
enum HelicopterRotorStates { |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
63 |
HRS_ROTOR_STOPPED, |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
64 |
HRS_ROTOR_MOVING_1, |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
65 |
HRS_ROTOR_MOVING_2, |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
66 |
HRS_ROTOR_MOVING_3, |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
67 |
}; |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
68 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
69 |
/** Find the nearest hangar to v |
1532
a69fdc89b5fc
(svn r2036) Fix FindNearestHanger(), it never worked correctly because 0xFFFF != 65000 and a 16bit number has no 17th bit
tron
parents:
1530
diff
changeset
|
70 |
* INVALID_STATION is returned, if the player does not have any suitable |
a69fdc89b5fc
(svn r2036) Fix FindNearestHanger(), it never worked correctly because 0xFFFF != 65000 and a 16bit number has no 17th bit
tron
parents:
1530
diff
changeset
|
71 |
* airports (like helipads only) |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
72 |
* @param v vehicle looking for a hangar |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
73 |
* @return the StationID if one is found, otherwise, INVALID_STATION |
1532
a69fdc89b5fc
(svn r2036) Fix FindNearestHanger(), it never worked correctly because 0xFFFF != 65000 and a 16bit number has no 17th bit
tron
parents:
1530
diff
changeset
|
74 |
*/ |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
75 |
static StationID FindNearestHangar(const Vehicle *v) |
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
|
76 |
{ |
1532
a69fdc89b5fc
(svn r2036) Fix FindNearestHanger(), it never worked correctly because 0xFFFF != 65000 and a 16bit number has no 17th bit
tron
parents:
1530
diff
changeset
|
77 |
const Station *st; |
a69fdc89b5fc
(svn r2036) Fix FindNearestHanger(), it never worked correctly because 0xFFFF != 65000 and a 16bit number has no 17th bit
tron
parents:
1530
diff
changeset
|
78 |
uint best = 0; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
79 |
StationID index = INVALID_STATION; |
4284
ea9579c54725
(svn r5914) -Fix [FS#235]: Bugfix for errors in FindNearestHangar function in aircraft_cmd.c (mart3p).
Darkvater
parents:
4261
diff
changeset
|
80 |
TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos); |
1194
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 |
|
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
|
82 |
FOR_ALL_STATIONS(st) { |
6025 | 83 |
if (st->owner != v->owner || !(st->facilities & FACIL_AIRPORT)) continue; |
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
|
84 |
|
6032 | 85 |
const AirportFTAClass *afc = st->Airport(); |
6025 | 86 |
if (afc->nof_depots == 0 || ( |
87 |
/* don't crash the plane if we know it can't land at the airport */ |
|
88 |
afc->flags & AirportFTAClass::SHORT_STRIP && |
|
89 |
AircraftVehInfo(v->engine_type)->subtype & AIR_FAST && |
|
90 |
!_cheats.no_jetcrash.value |
|
91 |
)) { |
|
92 |
continue; |
|
93 |
} |
|
1532
a69fdc89b5fc
(svn r2036) Fix FindNearestHanger(), it never worked correctly because 0xFFFF != 65000 and a 16bit number has no 17th bit
tron
parents:
1530
diff
changeset
|
94 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
95 |
/* v->tile can't be used here, when aircraft is flying v->tile is set to 0 */ |
6025 | 96 |
uint distance = DistanceSquare(vtile, st->airport_tile); |
97 |
if (distance < best || index == INVALID_STATION) { |
|
98 |
best = distance; |
|
99 |
index = st->index; |
|
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
|
100 |
} |
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
|
101 |
} |
1532
a69fdc89b5fc
(svn r2036) Fix FindNearestHanger(), it never worked correctly because 0xFFFF != 65000 and a 16bit number has no 17th bit
tron
parents:
1530
diff
changeset
|
102 |
return index; |
1194
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
|
103 |
} |
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
|
104 |
|
1614
f6f2c918356d
(svn r2118) - Fix: Fix compilation with network disabled, and comment out some of the warnings (unused function)
Darkvater
parents:
1533
diff
changeset
|
105 |
#if 0 |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
106 |
/** Check if given vehicle has a goto hangar in his orders |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
107 |
* @param v vehicle to inquiry |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
108 |
* @return true if vehicle v has an airport in the schedule, that has a hangar */ |
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
|
109 |
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
|
110 |
{ |
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
|
111 |
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
|
112 |
|
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
|
113 |
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
|
114 |
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
|
115 |
if (st->owner == v->owner && st->facilities & FACIL_AIRPORT) { |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
116 |
/* If an airport doesn't have a hangar, skip it */ |
6032 | 117 |
if (st->Airport()->nof_depots != 0) |
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
|
118 |
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
|
119 |
} |
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
|
120 |
} |
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
|
121 |
|
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
|
122 |
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
|
123 |
} |
1614
f6f2c918356d
(svn r2118) - Fix: Fix compilation with network disabled, and comment out some of the warnings (unused function)
Darkvater
parents:
1533
diff
changeset
|
124 |
#endif |
1194
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
|
125 |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3140
diff
changeset
|
126 |
int GetAircraftImage(const Vehicle* v, Direction direction) |
0 | 127 |
{ |
128 |
int spritenum = v->spritenum; |
|
129 |
||
130 |
if (is_custom_sprite(spritenum)) { |
|
131 |
int sprite = GetCustomVehicleSprite(v, direction); |
|
132 |
||
2989 | 133 |
if (sprite != 0) return sprite; |
2464
e3054f0f0627
(svn r2990) Remove _engine_original_sprites and replace all uses with references to our (new) original engine/vehicle tables.
peter1138
parents:
2423
diff
changeset
|
134 |
spritenum = orig_aircraft_vehicle_info[v->engine_type - AIRCRAFT_ENGINES_INDEX].image_index; |
0 | 135 |
} |
136 |
return direction + _aircraft_sprite[spritenum]; |
|
137 |
} |
|
138 |
||
3710
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
139 |
SpriteID GetRotorImage(const Vehicle *v) |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
140 |
{ |
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
141 |
assert(v->subtype == AIR_HELICOPTER); |
3710
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
142 |
|
6087 | 143 |
const Vehicle *w = v->next->next; |
3710
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
144 |
if (is_custom_sprite(v->spritenum)) { |
4056
7899dc230a12
(svn r5336) - NewGRF: draw custom helicopter rotor sprites in vehicle info window, ensuring the correct direction is used (inspiration from mart3p)
peter1138
parents:
4023
diff
changeset
|
145 |
SpriteID spritenum = GetCustomRotorSprite(v, false); |
3710
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
146 |
if (spritenum != 0) return spritenum; |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
147 |
} |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
148 |
|
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
149 |
/* Return standard rotor sprites if there are no custom sprites for this helicopter */ |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
150 |
return SPR_ROTOR_STOPPED + w->u.air.state; |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
151 |
} |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
152 |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5651
diff
changeset
|
153 |
void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal) |
0 | 154 |
{ |
4023
5d84c056a2b1
(svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
tron
parents:
3988
diff
changeset
|
155 |
const AircraftVehicleInfo* avi = AircraftVehInfo(engine); |
5d84c056a2b1
(svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
tron
parents:
3988
diff
changeset
|
156 |
int spritenum = avi->image_index; |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5651
diff
changeset
|
157 |
SpriteID sprite = (6 + _aircraft_sprite[spritenum]); |
0 | 158 |
|
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
|
159 |
if (is_custom_sprite(spritenum)) { |
3186
4317b5b295c4
(svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents:
3183
diff
changeset
|
160 |
sprite = GetCustomVehicleIcon(engine, DIR_W); |
5012
d59cca2ac433
(svn r7032) - Fix (r1704): Sprite index wasn't updated with correct image number if
peter1138
parents:
4991
diff
changeset
|
161 |
if (sprite == 0) { |
2464
e3054f0f0627
(svn r2990) Remove _engine_original_sprites and replace all uses with references to our (new) original engine/vehicle tables.
peter1138
parents:
2423
diff
changeset
|
162 |
spritenum = orig_aircraft_vehicle_info[engine - AIRCRAFT_ENGINES_INDEX].image_index; |
5012
d59cca2ac433
(svn r7032) - Fix (r1704): Sprite index wasn't updated with correct image number if
peter1138
parents:
4991
diff
changeset
|
163 |
sprite = (6 + _aircraft_sprite[spritenum]); |
d59cca2ac433
(svn r7032) - Fix (r1704): Sprite index wasn't updated with correct image number if
peter1138
parents:
4991
diff
changeset
|
164 |
} |
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
|
165 |
} |
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
|
166 |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5651
diff
changeset
|
167 |
DrawSprite(sprite, pal, 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
|
168 |
|
4023
5d84c056a2b1
(svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
tron
parents:
3988
diff
changeset
|
169 |
if (!(avi->subtype & AIR_CTOL)) { |
3710
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
170 |
SpriteID rotor_sprite = GetCustomRotorIcon(engine); |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
171 |
if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED; |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5651
diff
changeset
|
172 |
DrawSprite(rotor_sprite, PAL_NONE, 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
|
173 |
} |
0 | 174 |
} |
175 |
||
5972
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
176 |
/** Get the size of the sprite of an aircraft sprite heading west (used for lists) |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
177 |
* @param engine The engine to get the sprite from |
6409
2dc181151153
(svn r9545) -Documentation: Some corrections to previous doxygen work
belugas
parents:
6407
diff
changeset
|
178 |
* @param width The width of the sprite |
2dc181151153
(svn r9545) -Documentation: Some corrections to previous doxygen work
belugas
parents:
6407
diff
changeset
|
179 |
* @param height The height of the sprite |
5972
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
180 |
*/ |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
181 |
void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height) |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
182 |
{ |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
183 |
const AircraftVehicleInfo* avi = AircraftVehInfo(engine); |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
184 |
int spritenum = avi->image_index; |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
185 |
SpriteID sprite = (6 + _aircraft_sprite[spritenum]); |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
186 |
|
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
187 |
if (is_custom_sprite(spritenum)) { |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
188 |
sprite = GetCustomVehicleIcon(engine, DIR_W); |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
189 |
if (sprite == 0) { |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
190 |
spritenum = orig_aircraft_vehicle_info[engine - AIRCRAFT_ENGINES_INDEX].image_index; |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
191 |
sprite = (6 + _aircraft_sprite[spritenum]); |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
192 |
} |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
193 |
} |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
194 |
|
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
195 |
const Sprite *spr = GetSprite(sprite); |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
196 |
|
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
197 |
width = spr->width ; |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
198 |
height = spr->height; |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
199 |
} |
59953719a3ff
(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only)
bjarni
parents:
5952
diff
changeset
|
200 |
|
5920 | 201 |
static int32 EstimateAircraftCost(const AircraftVehicleInfo *avi) |
0 | 202 |
{ |
5920 | 203 |
return avi->base_cost * (_price.aircraft_base >> 3) >> 5; |
0 | 204 |
} |
205 |
||
206 |
||
3973
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
207 |
/** |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
208 |
* Calculates cargo capacity based on an aircraft's passenger |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
209 |
* and mail capacities. |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
210 |
* @param cid Which cargo type to calculate a capacity for. |
6409
2dc181151153
(svn r9545) -Documentation: Some corrections to previous doxygen work
belugas
parents:
6407
diff
changeset
|
211 |
* @param avi Which engine to find a cargo capacity for. |
3973
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
212 |
* @return New cargo capacity value. |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
213 |
*/ |
6087 | 214 |
uint16 AircraftDefaultCargoCapacity(CargoID cid, const AircraftVehicleInfo *avi) |
3973
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
215 |
{ |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
216 |
assert(cid != CT_INVALID); |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
217 |
|
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
218 |
/* An aircraft can carry twice as much goods as normal cargo, |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
219 |
* and four times as many passengers. */ |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
220 |
switch (cid) { |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
221 |
case CT_PASSENGERS: |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
222 |
return avi->passenger_capacity; |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
223 |
case CT_MAIL: |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
224 |
return avi->passenger_capacity + avi->mail_capacity; |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
225 |
case CT_GOODS: |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
226 |
return (avi->passenger_capacity + avi->mail_capacity) / 2; |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
227 |
default: |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
228 |
return (avi->passenger_capacity + avi->mail_capacity) / 4; |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
229 |
} |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
230 |
} |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
231 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
232 |
/** Build an aircraft. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
233 |
* @param tile tile of depot where aircraft is built |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
234 |
* @param flags for command |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
235 |
* @param p1 aircraft type being built (engine) |
3816
28ee8b8c2522
(svn r4826) -Fix: [autoreplace] fixed possible problem when autoreplacing and was number of vehicles (of a type, not total) was reached
bjarni
parents:
3722
diff
changeset
|
236 |
* @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
237 |
* return result of operation. Could be cost, error |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
238 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
239 |
int32 CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 240 |
{ |
6407
757a3cec2422
(svn r9543) -Fix [FS#691]: Split up STR_ENGINE_NOT_BUILDABLE into four strings so it can be
maedhros
parents:
6394
diff
changeset
|
241 |
if (!IsEngineBuildable(p1, VEH_AIRCRAFT, _current_player)) return_cmd_error(STR_AIRCRAFT_NOT_AVAILABLE); |
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
|
242 |
|
5920 | 243 |
const AircraftVehicleInfo *avi = AircraftVehInfo(p1); |
244 |
int32 value = EstimateAircraftCost(avi); |
|
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
|
245 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
246 |
/* to just query the cost, it is not neccessary to have a valid tile (automation/AI) */ |
2423
4266590b549d
(svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents:
2422
diff
changeset
|
247 |
if (flags & DC_QUERY_COST) return value; |
4266590b549d
(svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents:
2422
diff
changeset
|
248 |
|
3338
7cff208f0446
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
249 |
if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR; |
1226
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
|
250 |
|
0 | 251 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
252 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
253 |
/* Prevent building aircraft types at places which can't handle them */ |
6237
69427b23257f
(svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents:
6193
diff
changeset
|
254 |
if (!IsAircraftBuildableAtStation(p1, tile)) return CMD_ERROR; |
4161
60e38778d90b
(svn r5594) Be more strict what's allowed to be built in a hangar: if the airport can't handle planes/helicopters don't present and disallow building planes/helicopters - the latter case wasn't covered yet.
tron
parents:
4111
diff
changeset
|
255 |
|
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
256 |
/* Allocate 2 or 3 vehicle structs, depending on type |
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
257 |
* vl[0] = aircraft, vl[1] = shadow, [vl[2] = rotor] */ |
6087 | 258 |
Vehicle *vl[3]; |
5922 | 259 |
if (!AllocateVehicles(vl, avi->subtype & AIR_CTOL ? 2 : 3)) { |
2639 | 260 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
261 |
} |
|
0 | 262 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
263 |
UnitID unit_num = HASBIT(p2, 0) ? 0 : GetFreeUnitNumber(VEH_AIRCRAFT); |
0 | 264 |
if (unit_num > _patches.max_aircraft) |
265 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
|
266 |
||
267 |
if (flags & DC_EXEC) { |
|
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
268 |
Vehicle *v = vl[0]; // aircraft |
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
269 |
Vehicle *u = vl[1]; // shadow |
0 | 270 |
|
271 |
v->unitnumber = unit_num; |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
272 |
v->type = u->type = VEH_AIRCRAFT; |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5585
diff
changeset
|
273 |
v->direction = DIR_SE; |
0 | 274 |
|
275 |
v->owner = u->owner = _current_player; |
|
276 |
||
277 |
v->tile = tile; |
|
278 |
// u->tile = 0; |
|
279 |
||
6087 | 280 |
uint x = TileX(tile) * TILE_SIZE + 5; |
281 |
uint y = TileY(tile) * TILE_SIZE + 3; |
|
0 | 282 |
|
283 |
v->x_pos = u->x_pos = x; |
|
284 |
v->y_pos = u->y_pos = y; |
|
285 |
||
286 |
u->z_pos = GetSlopeZ(x, y); |
|
287 |
v->z_pos = u->z_pos + 1; |
|
288 |
||
289 |
v->x_offs = v->y_offs = -1; |
|
290 |
// u->delta_x = u->delta_y = 0; |
|
291 |
||
292 |
v->sprite_width = v->sprite_height = 2; |
|
293 |
v->z_height = 5; |
|
294 |
||
295 |
u->sprite_width = u->sprite_height = 2; |
|
296 |
u->z_height = 1; |
|
297 |
||
298 |
v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL; |
|
4175
b79ec8a94d4e
(svn r5613) Rename VS_DISASTER to VS_SHADOW, because this is what this flag actually means
tron
parents:
4161
diff
changeset
|
299 |
u->vehstatus = VS_HIDDEN | VS_UNCLICKABLE | VS_SHADOW; |
0 | 300 |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
301 |
v->spritenum = avi->image_index; |
0 | 302 |
// v->cargo_count = u->number_of_pieces = 0; |
303 |
||
922
10035216cbaf
(svn r1410) Replaced all occurences of 'passanger' by 'passenger' in the code
celestar
parents:
919
diff
changeset
|
304 |
v->cargo_cap = avi->passenger_capacity; |
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
305 |
u->cargo_cap = avi->mail_capacity; |
0 | 306 |
|
307 |
v->cargo_type = CT_PASSENGERS; |
|
308 |
u->cargo_type = CT_MAIL; |
|
309 |
||
3870
d9ebc4ea750a
(svn r4910) - NewGRF: add and initialize cargo subtype for vehicle visual variations
peter1138
parents:
3816
diff
changeset
|
310 |
v->cargo_subtype = 0; |
d9ebc4ea750a
(svn r4910) - NewGRF: add and initialize cargo subtype for vehicle visual variations
peter1138
parents:
3816
diff
changeset
|
311 |
|
0 | 312 |
v->string_id = STR_SV_AIRCRAFT_NAME; |
313 |
// v->next_order_param = v->next_order = 0; |
|
314 |
||
315 |
// v->load_unload_time_rem = 0; |
|
316 |
// v->progress = 0; |
|
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1263
diff
changeset
|
317 |
v->last_station_visited = INVALID_STATION; |
0 | 318 |
// v->destination_coords = 0; |
319 |
||
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
320 |
v->max_speed = avi->max_speed; |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
321 |
v->acceleration = avi->acceleration; |
2477
225b2916fe2a
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2475
diff
changeset
|
322 |
v->engine_type = p1; |
0 | 323 |
|
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
324 |
v->subtype = (avi->subtype & AIR_CTOL ? AIR_AIRCRAFT : AIR_HELICOPTER); |
0 | 325 |
v->value = value; |
326 |
||
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
327 |
u->subtype = AIR_SHADOW; |
0 | 328 |
|
3973
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
329 |
/* Danger, Will Robinson! |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
330 |
* If the aircraft is refittable, but cannot be refitted to |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
331 |
* passengers, we select the cargo type from the refit mask. |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
332 |
* This is a fairly nasty hack to get around the fact that TTD |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
333 |
* has no default cargo type specifier for planes... */ |
6087 | 334 |
CargoID cargo = FindFirstRefittableCargo(p1); |
3973
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
335 |
if (cargo != CT_INVALID && cargo != CT_PASSENGERS) { |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
336 |
uint16 callback = CALLBACK_FAILED; |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
337 |
|
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
338 |
v->cargo_type = cargo; |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
339 |
|
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
340 |
if (HASBIT(EngInfo(p1)->callbackmask, CBM_REFIT_CAPACITY)) { |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
341 |
callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v); |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
342 |
} |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
343 |
|
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
344 |
if (callback == CALLBACK_FAILED) { |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
345 |
/* Callback failed, or not executed; use the default cargo capacity */ |
6087 | 346 |
v->cargo_cap = AircraftDefaultCargoCapacity(v->cargo_type, avi); |
3973
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
347 |
} else { |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
348 |
v->cargo_cap = callback; |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
349 |
} |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
350 |
|
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
351 |
/* Set the 'second compartent' capacity to none */ |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
352 |
u->cargo_cap = 0; |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
353 |
} |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3963
diff
changeset
|
354 |
|
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
355 |
const Engine *e = GetEngine(p1); |
0 | 356 |
v->reliability = e->reliability; |
357 |
v->reliability_spd_dec = e->reliability_spd_dec; |
|
358 |
v->max_age = e->lifelength * 366; |
|
359 |
||
2564 | 360 |
_new_vehicle_id = v->index; |
0 | 361 |
|
2423
4266590b549d
(svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents:
2422
diff
changeset
|
362 |
/* When we click on hangar we know the tile it is on. By that we know |
4266590b549d
(svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents:
2422
diff
changeset
|
363 |
* its position in the array of depots the airport has.....we can search |
4266590b549d
(svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents:
2422
diff
changeset
|
364 |
* layout for #th position of depot. Since layout must start with a listing |
4266590b549d
(svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents:
2422
diff
changeset
|
365 |
* of all depots, it is simple */ |
5921 | 366 |
for (uint i = 0;; i++) { |
6237
69427b23257f
(svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents:
6193
diff
changeset
|
367 |
const Station *st = GetStationByTile(tile); |
69427b23257f
(svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents:
6193
diff
changeset
|
368 |
const AirportFTAClass *apc = st->Airport(); |
69427b23257f
(svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents:
6193
diff
changeset
|
369 |
|
5921 | 370 |
assert(i != apc->nof_depots); |
371 |
if (st->airport_tile + ToTileIndexDiff(apc->airport_depots[i]) == tile) { |
|
372 |
assert(apc->layout[i].heading == HANGAR); |
|
373 |
v->u.air.pos = apc->layout[i].position; |
|
374 |
break; |
|
0 | 375 |
} |
376 |
} |
|
377 |
||
378 |
v->u.air.state = HANGAR; |
|
379 |
v->u.air.previous_pos = v->u.air.pos; |
|
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3186
diff
changeset
|
380 |
v->u.air.targetairport = GetStationIndex(tile); |
0 | 381 |
v->next = u; |
382 |
||
383 |
v->service_interval = _patches.servint_aircraft; |
|
384 |
||
385 |
v->date_of_last_service = _date; |
|
4329
0e6e689f66e7
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4293
diff
changeset
|
386 |
v->build_year = u->build_year = _cur_year; |
0 | 387 |
|
388 |
v->cur_image = u->cur_image = 0xEA0; |
|
389 |
||
2804
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2752
diff
changeset
|
390 |
v->random_bits = VehicleRandomBits(); |
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2752
diff
changeset
|
391 |
u->random_bits = VehicleRandomBits(); |
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2752
diff
changeset
|
392 |
|
6176
153f0f24dc1b
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents:
6175
diff
changeset
|
393 |
v->vehicle_flags = 0; |
153f0f24dc1b
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents:
6175
diff
changeset
|
394 |
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SETBIT(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE); |
153f0f24dc1b
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents:
6175
diff
changeset
|
395 |
|
6490
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
396 |
UpdateAircraftCache(v); |
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
397 |
|
0 | 398 |
VehiclePositionChanged(v); |
399 |
VehiclePositionChanged(u); |
|
400 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
401 |
/* Aircraft with 3 vehicles (chopper)? */ |
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
402 |
if (v->subtype == AIR_HELICOPTER) { |
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
403 |
Vehicle *w = vl[2]; |
0 | 404 |
|
405 |
u->next = w; |
|
406 |
||
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
407 |
w->type = VEH_AIRCRAFT; |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5585
diff
changeset
|
408 |
w->direction = DIR_N; |
0 | 409 |
w->owner = _current_player; |
410 |
w->x_pos = v->x_pos; |
|
411 |
w->y_pos = v->y_pos; |
|
412 |
w->z_pos = v->z_pos + 5; |
|
413 |
w->x_offs = w->y_offs = -1; |
|
414 |
w->sprite_width = w->sprite_height = 2; |
|
415 |
w->z_height = 1; |
|
416 |
w->vehstatus = VS_HIDDEN | VS_UNCLICKABLE; |
|
3710
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
417 |
w->spritenum = 0xFF; |
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
418 |
w->subtype = AIR_ROTOR; |
2517
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2504
diff
changeset
|
419 |
w->cur_image = SPR_ROTOR_STOPPED; |
2804
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2752
diff
changeset
|
420 |
w->random_bits = VehicleRandomBits(); |
3710
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
421 |
/* Use rotor's air.state to store the rotor animation frame */ |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
422 |
w->u.air.state = HRS_ROTOR_STOPPED; |
0 | 423 |
VehiclePositionChanged(w); |
424 |
} |
|
425 |
||
4739
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4732
diff
changeset
|
426 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
588 | 427 |
RebuildVehicleLists(); |
0 | 428 |
InvalidateWindow(WC_COMPANY, v->owner); |
2618
9691753519ac
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2601
diff
changeset
|
429 |
if (IsLocalPlayer()) |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
430 |
InvalidateAutoreplaceWindow(VEH_AIRCRAFT); //updates the replace Aircraft window |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5924
diff
changeset
|
431 |
|
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5924
diff
changeset
|
432 |
GetPlayer(_current_player)->num_engines[p1]++; |
0 | 433 |
} |
434 |
||
435 |
return value; |
|
436 |
} |
|
437 |
||
438 |
||
410 | 439 |
static void DoDeleteAircraft(Vehicle *v) |
0 | 440 |
{ |
441 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
588 | 442 |
RebuildVehicleLists(); |
0 | 443 |
InvalidateWindow(WC_COMPANY, v->owner); |
5256
9056fd4b30f4
(svn r7386) -Codechange r7385: moved deletion of the vehicle highlight from DeleteVehicle to the sell commands as they are not called as often
bjarni
parents:
5215
diff
changeset
|
444 |
DeleteDepotHighlightOfVehicle(v); |
0 | 445 |
DeleteVehicleChain(v); |
1055
cc4f60cc9102
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
446 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 447 |
} |
448 |
||
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1752
diff
changeset
|
449 |
/** Sell an aircraft. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
450 |
* @param tile unused |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
451 |
* @param flags for command type |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1752
diff
changeset
|
452 |
* @param p1 vehicle ID to be sold |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1752
diff
changeset
|
453 |
* @param p2 unused |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
454 |
* @return result of operation. Error or sold value |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1752
diff
changeset
|
455 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
456 |
int32 CmdSellAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 457 |
{ |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
458 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
0 | 459 |
|
6087 | 460 |
Vehicle *v = GetVehicle(p1); |
0 | 461 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
462 |
if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR; |
3963
6cab57074a9a
(svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
3955
diff
changeset
|
463 |
if (!IsAircraftInHangarStopped(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED); |
0 | 464 |
|
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
|
465 |
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
|
466 |
|
0 | 467 |
if (flags & DC_EXEC) { |
468 |
// Invalidate depot |
|
469 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
470 |
DoDeleteAircraft(v); |
|
471 |
} |
|
472 |
||
473 |
return -(int32)v->value; |
|
474 |
} |
|
475 |
||
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1752
diff
changeset
|
476 |
/** Start/Stop an aircraft. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
477 |
* @param tile unused |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
478 |
* @param flags for command type |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
479 |
* @param p1 aircraft ID to start/stop |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1752
diff
changeset
|
480 |
* @param p2 unused |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
481 |
* @return result of operation. Nothing if everything went well |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1752
diff
changeset
|
482 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
483 |
int32 CmdStartStopAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 484 |
{ |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
485 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
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
|
486 |
|
6087 | 487 |
Vehicle *v = GetVehicle(p1); |
0 | 488 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
489 |
if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 490 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
491 |
/* cannot stop airplane when in flight, or when taking off / landing */ |
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4056
diff
changeset
|
492 |
if (v->u.air.state >= STARTTAKEOFF && v->u.air.state < TERM7) |
0 | 493 |
return_cmd_error(STR_A017_AIRCRAFT_IS_IN_FLIGHT); |
494 |
||
4338
e079d33dc473
(svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents:
4329
diff
changeset
|
495 |
/* Check if this aircraft can be started/stopped. The callback will fail or |
e079d33dc473
(svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents:
4329
diff
changeset
|
496 |
* return 0xFF if it can. */ |
6087 | 497 |
uint16 callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v); |
4338
e079d33dc473
(svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents:
4329
diff
changeset
|
498 |
if (callback != CALLBACK_FAILED && callback != 0xFF) { |
e079d33dc473
(svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents:
4329
diff
changeset
|
499 |
StringID error = GetGRFStringID(GetEngineGRFID(v->engine_type), 0xD000 + callback); |
e079d33dc473
(svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents:
4329
diff
changeset
|
500 |
return_cmd_error(error); |
e079d33dc473
(svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents:
4329
diff
changeset
|
501 |
} |
e079d33dc473
(svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents:
4329
diff
changeset
|
502 |
|
0 | 503 |
if (flags & DC_EXEC) { |
3963
6cab57074a9a
(svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
3955
diff
changeset
|
504 |
if (IsAircraftInHangarStopped(v)) { |
3139
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3008
diff
changeset
|
505 |
DeleteVehicleNews(p1, STR_A014_AIRCRAFT_IS_WAITING_IN); |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3008
diff
changeset
|
506 |
} |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3008
diff
changeset
|
507 |
|
0 | 508 |
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
|
509 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 510 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
1055
cc4f60cc9102
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
511 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 512 |
} |
513 |
||
514 |
return 0; |
|
515 |
} |
|
516 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
517 |
/** Send an aircraft to the hangar. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
518 |
* @param tile unused |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
519 |
* @param flags for command type |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
520 |
* @param p1 vehicle ID to send to the hangar |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
521 |
* @param p2 various bitmasked elements |
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
522 |
* - p2 bit 0-3 - DEPOT_ flags (see vehicle.h) |
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
523 |
* - p2 bit 8-10 - VLW flag (for mass goto depot) |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
524 |
* @return o if everything went well |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
525 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
526 |
int32 CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 527 |
{ |
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
528 |
if (p2 & DEPOT_MASS_SEND) { |
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
529 |
/* Mass goto depot requested */ |
4546
507b7d9bd834
(svn r6378) -Codechange: Rename VLW_FLAGS to VLW_MASK as it is a mask
Darkvater
parents:
4544
diff
changeset
|
530 |
if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR; |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
531 |
return SendAllVehiclesToDepot(VEH_AIRCRAFT, flags, p2 & DEPOT_SERVICE, _current_player, (p2 & VLW_MASK), p1); |
4463
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
532 |
} |
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
533 |
|
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
534 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
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
|
535 |
|
6087 | 536 |
Vehicle *v = GetVehicle(p1); |
0 | 537 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
538 |
if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner) || IsAircraftInHangar(v)) return CMD_ERROR; |
4451
2e86da0081b5
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
539 |
|
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
540 |
if (v->current_order.type == OT_GOTO_DEPOT && !(p2 & DEPOT_LOCATE_HANGAR)) { |
4519
f53d829de680
(svn r6304) -Codechange r6295: Use !! instead of (bool) in commands to send vehicles to depots
bjarni
parents:
4510
diff
changeset
|
541 |
if (!!(p2 & DEPOT_SERVICE) == HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT)) { |
4510
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
542 |
/* We called with a different DEPOT_SERVICE setting. |
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
543 |
* Now we change the setting to apply the new one and let the vehicle head for the same hangar. |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4546
diff
changeset
|
544 |
* Note: the if is (true for requesting service == true for ordered to stop in hangar) */ |
4510
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
545 |
if (flags & DC_EXEC) { |
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
546 |
TOGGLEBIT(v->current_order.flags, OFB_HALT_IN_DEPOT); |
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
547 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
548 |
} |
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
549 |
return 0; |
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
550 |
} |
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
551 |
|
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
552 |
if (p2 & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of hangar orders |
0 | 553 |
if (flags & DC_EXEC) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
554 |
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
|
555 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
556 |
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
|
557 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 558 |
} |
559 |
} else { |
|
1262
e3473b1afda9
(svn r1766) - Feature: Aircrafts will now go to the nearest hangar if the next airport in the orders do not have one (helipads)
bjarni
parents:
1245
diff
changeset
|
560 |
bool next_airport_has_hangar = true; |
4412
cae52239a576
(svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents:
4389
diff
changeset
|
561 |
StationID next_airport_index = v->u.air.targetairport; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
562 |
const Station *st = GetStation(next_airport_index); |
4111
221355fcade6
(svn r5454) -Fix: [ 1394231 ] Autorenew glitch on helicopters
bjarni
parents:
4095
diff
changeset
|
563 |
/* If the station is not a valid airport or if it has no hangars */ |
6032 | 564 |
if (!st->IsValid() || st->airport_tile == 0 || st->Airport()->nof_depots == 0) { |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
565 |
/* the aircraft has to search for a hangar on its own */ |
6087 | 566 |
StationID station = FindNearestHangar(v); |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
567 |
|
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
568 |
next_airport_has_hangar = false; |
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
569 |
if (station == INVALID_STATION) return CMD_ERROR; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
570 |
next_airport_index = station; |
1262
e3473b1afda9
(svn r1766) - Feature: Aircrafts will now go to the nearest hangar if the next airport in the orders do not have one (helipads)
bjarni
parents:
1245
diff
changeset
|
571 |
} |
0 | 572 |
|
573 |
if (flags & DC_EXEC) { |
|
6502
8056fdc57aa9
(svn r9685) -Fix (r9683): Call v->LeaveStation() when a vehicle in a station is sent to a depot.
maedhros
parents:
6501
diff
changeset
|
574 |
if (v->current_order.type == OT_LOADING) v->LeaveStation(); |
8056fdc57aa9
(svn r9685) -Fix (r9683): Call v->LeaveStation() when a vehicle in a station is sent to a depot.
maedhros
parents:
6501
diff
changeset
|
575 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
576 |
v->current_order.type = OT_GOTO_DEPOT; |
4412
cae52239a576
(svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents:
4389
diff
changeset
|
577 |
v->current_order.flags = OF_NON_STOP; |
4991
a9f3eb46f329
(svn r6994) -Regression (r6291): When sending an aircrafts to a hangar the wrong bit gets tested to determine if a aircraft should stop there or just get serviced
tron
parents:
4845
diff
changeset
|
578 |
if (!(p2 & DEPOT_SERVICE)) SETBIT(v->current_order.flags, OFB_HALT_IN_DEPOT); |
5259
9d7de9a6b364
(svn r7389) -Fix: when forcing a vehicle to go to a depot, clear refit orders from current orders (caused refit error popup when not having no orders)
bjarni
parents:
5256
diff
changeset
|
579 |
v->current_order.refit_cargo = CT_INVALID; |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
580 |
v->current_order.dest = 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
|
581 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
5438
b03687991037
(svn r7657) -Fix (r6291): 'Goto Depot' did not work for helicopters going to an airport without depot (mart3p).
rubidium
parents:
5380
diff
changeset
|
582 |
if (v->u.air.state == FLYING && !next_airport_has_hangar) { |
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
583 |
/* The aircraft is now heading for a different hangar than the next in the orders */ |
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
|
584 |
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
|
585 |
} |
0 | 586 |
} |
587 |
} |
|
588 |
||
589 |
return 0; |
|
590 |
} |
|
591 |
||
592 |
||
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1793
diff
changeset
|
593 |
/** Refits an aircraft to the specified cargo type. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
594 |
* @param tile unused |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
595 |
* @param flags for command type |
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1793
diff
changeset
|
596 |
* @param p1 vehicle ID of the aircraft to refit |
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1793
diff
changeset
|
597 |
* @param p2 various bitstuffed elements |
2635 | 598 |
* - p2 = (bit 0-7) - the new cargo type to refit to |
3954
7b51d0046efb
(svn r5103) - Add cargo subtype parameter to refit commands (mart3p)
peter1138
parents:
3948
diff
changeset
|
599 |
* - p2 = (bit 8-15) - the new cargo subtype to refit to |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
600 |
* @return cost of refit or error |
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1793
diff
changeset
|
601 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
602 |
int32 CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 603 |
{ |
3954
7b51d0046efb
(svn r5103) - Add cargo subtype parameter to refit commands (mart3p)
peter1138
parents:
3948
diff
changeset
|
604 |
byte new_subtype = GB(p2, 8, 8); |
0 | 605 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
606 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
0 | 607 |
|
6087 | 608 |
Vehicle *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
|
609 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
610 |
if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR; |
3963
6cab57074a9a
(svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
3955
diff
changeset
|
611 |
if (!IsAircraftInHangarStopped(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED); |
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
|
612 |
|
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1793
diff
changeset
|
613 |
/* Check cargo */ |
6087 | 614 |
CargoID new_cid = GB(p2, 0, 8); |
6316
d2b70e10f106
(svn r9259) -Codechange: NUM_CARGO isn't a valid cargo type...
peter1138
parents:
6263
diff
changeset
|
615 |
if (new_cid >= NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR; |
0 | 616 |
|
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
|
617 |
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
|
618 |
|
3974
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
619 |
/* Check the refit capacity callback */ |
6087 | 620 |
uint16 callback = CALLBACK_FAILED; |
3974
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
621 |
if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_REFIT_CAPACITY)) { |
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
622 |
/* Back up the existing cargo type */ |
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
623 |
CargoID temp_cid = v->cargo_type; |
3988
fcb1549e4d4c
(svn r5187) - NewGRF: temporarily change a vehicle's cargo subtype when calling the refit capacity callback.
peter1138
parents:
3987
diff
changeset
|
624 |
byte temp_subtype = v->cargo_subtype; |
3974
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
625 |
v->cargo_type = new_cid; |
3988
fcb1549e4d4c
(svn r5187) - NewGRF: temporarily change a vehicle's cargo subtype when calling the refit capacity callback.
peter1138
parents:
3987
diff
changeset
|
626 |
v->cargo_subtype = new_subtype; |
3974
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
627 |
|
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
628 |
callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v); |
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
629 |
|
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
630 |
/* Restore the cargo type */ |
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
631 |
v->cargo_type = temp_cid; |
3988
fcb1549e4d4c
(svn r5187) - NewGRF: temporarily change a vehicle's cargo subtype when calling the refit capacity callback.
peter1138
parents:
3987
diff
changeset
|
632 |
v->cargo_subtype = temp_subtype; |
3974
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
633 |
} |
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
634 |
|
6087 | 635 |
const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type); |
636 |
||
637 |
uint pass; |
|
3974
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
638 |
if (callback == CALLBACK_FAILED) { |
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
639 |
/* If the callback failed, or wasn't executed, use the aircraft's |
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
640 |
* default cargo capacity */ |
6087 | 641 |
pass = AircraftDefaultCargoCapacity(new_cid, avi); |
3974
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
642 |
} else { |
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
643 |
pass = callback; |
0 | 644 |
} |
3008
cef26520c91e
(svn r3588) - Refit: Use only one global to return the refit capacity rather than one per vehicle type.
peter1138
parents:
3005
diff
changeset
|
645 |
_returned_refit_capacity = pass; |
0 | 646 |
|
6087 | 647 |
int32 cost = 0; |
4845
72bbb6e2694e
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4843
diff
changeset
|
648 |
if (IsHumanPlayer(v->owner) && new_cid != v->cargo_type) { |
4544
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4529
diff
changeset
|
649 |
cost = GetRefitCost(v->engine_type); |
0 | 650 |
} |
651 |
||
652 |
if (flags & DC_EXEC) { |
|
653 |
v->cargo_cap = pass; |
|
654 |
||
6087 | 655 |
Vehicle *u = v->next; |
6340
df75644b9f06
(svn r9352) -Codechange: Use cargo class to determine if an aircraft should carry mail
peter1138
parents:
6334
diff
changeset
|
656 |
uint mail = IsCargoInClass(new_cid, CC_PASSENGERS) ? avi->mail_capacity : 0; |
0 | 657 |
u->cargo_cap = mail; |
3955
b96f96b31403
(svn r5104) - When refitting a vehicle to its existing cargo type, don't lose the cargo onboard (useful when adding wagons to a train)
peter1138
parents:
3954
diff
changeset
|
658 |
if (v->cargo_type == new_cid) { |
b96f96b31403
(svn r5104) - When refitting a vehicle to its existing cargo type, don't lose the cargo onboard (useful when adding wagons to a train)
peter1138
parents:
3954
diff
changeset
|
659 |
v->cargo_count = min(pass, v->cargo_count); |
b96f96b31403
(svn r5104) - When refitting a vehicle to its existing cargo type, don't lose the cargo onboard (useful when adding wagons to a train)
peter1138
parents:
3954
diff
changeset
|
660 |
u->cargo_count = min(mail, u->cargo_count); |
b96f96b31403
(svn r5104) - When refitting a vehicle to its existing cargo type, don't lose the cargo onboard (useful when adding wagons to a train)
peter1138
parents:
3954
diff
changeset
|
661 |
} else { |
b96f96b31403
(svn r5104) - When refitting a vehicle to its existing cargo type, don't lose the cargo onboard (useful when adding wagons to a train)
peter1138
parents:
3954
diff
changeset
|
662 |
v->cargo_count = 0; |
b96f96b31403
(svn r5104) - When refitting a vehicle to its existing cargo type, don't lose the cargo onboard (useful when adding wagons to a train)
peter1138
parents:
3954
diff
changeset
|
663 |
u->cargo_count = 0; |
b96f96b31403
(svn r5104) - When refitting a vehicle to its existing cargo type, don't lose the cargo onboard (useful when adding wagons to a train)
peter1138
parents:
3954
diff
changeset
|
664 |
} |
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1793
diff
changeset
|
665 |
v->cargo_type = new_cid; |
3954
7b51d0046efb
(svn r5103) - Add cargo subtype parameter to refit commands (mart3p)
peter1138
parents:
3948
diff
changeset
|
666 |
v->cargo_subtype = new_subtype; |
0 | 667 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
3722
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
668 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
669 |
RebuildVehicleLists(); |
0 | 670 |
} |
671 |
||
672 |
return cost; |
|
673 |
} |
|
674 |
||
675 |
||
676 |
static void CheckIfAircraftNeedsService(Vehicle *v) |
|
677 |
{ |
|
2639 | 678 |
if (_patches.servint_aircraft == 0) return; |
679 |
if (!VehicleNeedsService(v)) return; |
|
680 |
if (v->vehstatus & VS_STOPPED) return; |
|
0 | 681 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
682 |
if (v->current_order.type == OT_GOTO_DEPOT && |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
683 |
v->current_order.flags & OF_HALT_IN_DEPOT) |
0 | 684 |
return; |
685 |
||
2639 | 686 |
if (_patches.gotodepot && VehicleHasDepotOrders(v)) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
687 |
|
4529
18bd5e7e35aa
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
688 |
if (IsAircraftInHangar(v)) { |
18bd5e7e35aa
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
689 |
VehicleServiceInDepot(v); |
18bd5e7e35aa
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
690 |
return; |
18bd5e7e35aa
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
691 |
} |
18bd5e7e35aa
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
692 |
|
6087 | 693 |
const Station *st = GetStation(v->current_order.dest); |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
694 |
/* only goto depot if the target airport has terminals (eg. it is airport) */ |
6032 | 695 |
if (st->IsValid() && st->airport_tile != 0 && st->Airport()->terminals != NULL) { |
0 | 696 |
// printf("targetairport = %d, st->index = %d\n", v->u.air.targetairport, st->index); |
697 |
// v->u.air.targetairport = st->index; |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
698 |
v->current_order.type = OT_GOTO_DEPOT; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
699 |
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
|
700 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
701 |
} else if (v->current_order.type == OT_GOTO_DEPOT) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
702 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
703 |
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
|
704 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 705 |
} |
706 |
} |
|
707 |
||
708 |
void OnNewDay_Aircraft(Vehicle *v) |
|
709 |
{ |
|
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
710 |
if (!IsNormalAircraft(v)) return; |
0 | 711 |
|
2639 | 712 |
if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v); |
0 | 713 |
|
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
714 |
CheckOrders(v); |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
11
diff
changeset
|
715 |
|
0 | 716 |
CheckVehicleBreakdown(v); |
717 |
AgeVehicle(v); |
|
718 |
CheckIfAircraftNeedsService(v); |
|
719 |
||
2639 | 720 |
if (v->vehstatus & VS_STOPPED) return; |
0 | 721 |
|
6495
4a4b06bee934
(svn r9678) -Codechange: Support changing of aircraft running cost via callback 36.
peter1138
parents:
6490
diff
changeset
|
722 |
int32 cost = GetVehicleProperty(v, 0x0E, AircraftVehInfo(v->engine_type)->running_cost) * _price.aircraft_running / 364; |
0 | 723 |
|
724 |
v->profit_this_year -= cost >> 8; |
|
725 |
||
726 |
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN); |
|
727 |
SubtractMoneyFromPlayerFract(v->owner, cost); |
|
728 |
||
729 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1055
cc4f60cc9102
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
730 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 731 |
} |
732 |
||
6247 | 733 |
void AircraftYearlyLoop() |
0 | 734 |
{ |
735 |
Vehicle *v; |
|
736 |
||
737 |
FOR_ALL_VEHICLES(v) { |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
738 |
if (v->type == VEH_AIRCRAFT && IsNormalAircraft(v)) { |
0 | 739 |
v->profit_last_year = v->profit_this_year; |
740 |
v->profit_this_year = 0; |
|
741 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
742 |
} |
|
743 |
} |
|
744 |
} |
|
745 |
||
746 |
static void AgeAircraftCargo(Vehicle *v) |
|
747 |
{ |
|
2639 | 748 |
if (_age_cargo_skip_counter != 0) return; |
0 | 749 |
|
750 |
do { |
|
2639 | 751 |
if (v->cargo_days != 0xFF) v->cargo_days++; |
752 |
v = v->next; |
|
753 |
} while (v != NULL); |
|
0 | 754 |
} |
755 |
||
756 |
static void HelicopterTickHandler(Vehicle *v) |
|
757 |
{ |
|
6087 | 758 |
Vehicle *u = v->next->next; |
0 | 759 |
|
2639 | 760 |
if (u->vehstatus & VS_HIDDEN) return; |
0 | 761 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
762 |
/* if true, helicopter rotors do not rotate. This should only be the case if a helicopter is |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
763 |
* loading/unloading at a terminal or stopped */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
764 |
if (v->current_order.type == OT_LOADING || (v->vehstatus & VS_STOPPED)) { |
0 | 765 |
if (u->cur_speed != 0) { |
766 |
u->cur_speed++; |
|
3710
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
767 |
if (u->cur_speed >= 0x80 && u->u.air.state == HRS_ROTOR_MOVING_3) { |
0 | 768 |
u->cur_speed = 0; |
769 |
} |
|
770 |
} |
|
771 |
} else { |
|
772 |
if (u->cur_speed == 0) |
|
773 |
u->cur_speed = 0x70; |
|
774 |
||
775 |
if (u->cur_speed >= 0x50) |
|
776 |
u->cur_speed--; |
|
777 |
} |
|
778 |
||
6087 | 779 |
int tick = ++u->tick_counter; |
780 |
int spd = u->cur_speed >> 4; |
|
0 | 781 |
|
6087 | 782 |
SpriteID img; |
0 | 783 |
if (spd == 0) { |
3710
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
784 |
u->u.air.state = HRS_ROTOR_STOPPED; |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
785 |
img = GetRotorImage(v); |
2549 | 786 |
if (u->cur_image == img) return; |
0 | 787 |
} else if (tick >= spd) { |
788 |
u->tick_counter = 0; |
|
3710
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
789 |
u->u.air.state++; |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
790 |
if (u->u.air.state > HRS_ROTOR_MOVING_3) u->u.air.state = HRS_ROTOR_MOVING_1; |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
791 |
img = GetRotorImage(v); |
2549 | 792 |
} else { |
0 | 793 |
return; |
2549 | 794 |
} |
0 | 795 |
|
2549 | 796 |
u->cur_image = img; |
0 | 797 |
|
798 |
BeginVehicleMove(u); |
|
799 |
VehiclePositionChanged(u); |
|
800 |
EndVehicleMove(u); |
|
801 |
} |
|
802 |
||
803 |
static void SetAircraftPosition(Vehicle *v, int x, int y, int z) |
|
804 |
{ |
|
805 |
v->x_pos = x; |
|
806 |
v->y_pos = y; |
|
807 |
v->z_pos = z; |
|
808 |
||
809 |
v->cur_image = GetAircraftImage(v, v->direction); |
|
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
810 |
if (v->subtype == AIR_HELICOPTER) v->next->next->cur_image = GetRotorImage(v); |
0 | 811 |
|
812 |
BeginVehicleMove(v); |
|
813 |
VehiclePositionChanged(v); |
|
814 |
EndVehicleMove(v); |
|
815 |
||
6087 | 816 |
Vehicle *u = v->next; |
0 | 817 |
|
6087 | 818 |
int safe_x = clamp(x, 0, MapMaxX() * TILE_SIZE); |
819 |
int safe_y = clamp(y - 1, 0, MapMaxY() * TILE_SIZE); |
|
0 | 820 |
u->x_pos = x; |
4259
422724d8c66a
(svn r5883) -Fix [FS#272]: use the height of the edge of the map for shadows of aircrafts that are outside the map; similar to r5841, caused by r5794.
rubidium
parents:
4244
diff
changeset
|
821 |
u->y_pos = y - ((v->z_pos-GetSlopeZ(safe_x, safe_y)) >> 3);; |
422724d8c66a
(svn r5883) -Fix [FS#272]: use the height of the edge of the map for shadows of aircrafts that are outside the map; similar to r5841, caused by r5794.
rubidium
parents:
4244
diff
changeset
|
822 |
|
422724d8c66a
(svn r5883) -Fix [FS#272]: use the height of the edge of the map for shadows of aircrafts that are outside the map; similar to r5841, caused by r5794.
rubidium
parents:
4244
diff
changeset
|
823 |
safe_y = clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE); |
422724d8c66a
(svn r5883) -Fix [FS#272]: use the height of the edge of the map for shadows of aircrafts that are outside the map; similar to r5841, caused by r5794.
rubidium
parents:
4244
diff
changeset
|
824 |
u->z_pos = GetSlopeZ(safe_x, safe_y); |
0 | 825 |
u->cur_image = v->cur_image; |
826 |
||
827 |
BeginVehicleMove(u); |
|
828 |
VehiclePositionChanged(u); |
|
829 |
EndVehicleMove(u); |
|
830 |
||
2639 | 831 |
u = u->next; |
832 |
if (u != NULL) { |
|
0 | 833 |
u->x_pos = x; |
834 |
u->y_pos = y; |
|
835 |
u->z_pos = z + 5; |
|
836 |
||
837 |
BeginVehicleMove(u); |
|
838 |
VehiclePositionChanged(u); |
|
839 |
EndVehicleMove(u); |
|
840 |
} |
|
841 |
} |
|
842 |
||
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
843 |
/** Handle Aircraft specific tasks when a an Aircraft enters a hangar |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
844 |
* @param *v Vehicle that enters the hangar |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
845 |
*/ |
4732
4f1c405ac96e
(svn r6644) -Fix(r6637): remove inline to allow MSVC compilation
belugas
parents:
4725
diff
changeset
|
846 |
void HandleAircraftEnterHangar(Vehicle *v) |
0 | 847 |
{ |
848 |
v->subspeed = 0; |
|
849 |
v->progress = 0; |
|
850 |
||
6087 | 851 |
Vehicle *u = v->next; |
0 | 852 |
u->vehstatus |= VS_HIDDEN; |
2639 | 853 |
u = u->next; |
854 |
if (u != NULL) { |
|
0 | 855 |
u->vehstatus |= VS_HIDDEN; |
856 |
u->cur_speed = 0; |
|
857 |
} |
|
858 |
||
859 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos); |
|
860 |
} |
|
861 |
||
2549 | 862 |
static void PlayAircraftSound(const Vehicle* v) |
0 | 863 |
{ |
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
864 |
if (!PlayVehicleSound(v, VSE_START)) { |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
865 |
SndPlayVehicleFx(AircraftVehInfo(v->engine_type)->sfx, v); |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
866 |
} |
0 | 867 |
} |
868 |
||
6490
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
869 |
|
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
870 |
void UpdateAircraftCache(Vehicle *v) |
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
871 |
{ |
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
872 |
uint max_speed = GetVehicleProperty(v, 0x0C, 0); |
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
873 |
if (max_speed != 0) { |
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
874 |
/* Convert from original units to (approx) km/h */ |
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
875 |
max_speed = (max_speed * 129) / 10; |
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
876 |
|
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
877 |
v->u.air.cached_max_speed = max_speed; |
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
878 |
} else { |
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
879 |
v->u.air.cached_max_speed = 0xFFFF; |
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
880 |
} |
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
881 |
} |
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
882 |
|
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
883 |
|
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
884 |
/** |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
885 |
* Special velocities for aircraft |
5945
fabc2fee32b3
(svn r8611) -Fix: Moved the aircraft speed limiting into UpdateAircraftSpeed and enummed some speed limits. This should give a more steady display in the status bar during taxiing
celestar
parents:
5944
diff
changeset
|
886 |
*/ |
fabc2fee32b3
(svn r8611) -Fix: Moved the aircraft speed limiting into UpdateAircraftSpeed and enummed some speed limits. This should give a more steady display in the status bar during taxiing
celestar
parents:
5944
diff
changeset
|
887 |
enum AircraftSpeedLimits { |
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
888 |
SPEED_LIMIT_TAXI = 50, ///< Maximum speed of an aircraft while taxiing |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
889 |
SPEED_LIMIT_APPROACH = 230, ///< Maximum speed of an aircraft on finals |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
890 |
SPEED_LIMIT_BROKEN = 320, ///< Maximum speed of an aircraft that is broken |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
891 |
SPEED_LIMIT_HOLD = 425, ///< Maximum speed of an aircraft that flies the holding pattern |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
892 |
SPEED_LIMIT_NONE = 0xFFFF ///< No environmental speed limit. Speed limit is type dependent |
5945
fabc2fee32b3
(svn r8611) -Fix: Moved the aircraft speed limiting into UpdateAircraftSpeed and enummed some speed limits. This should give a more steady display in the status bar during taxiing
celestar
parents:
5944
diff
changeset
|
893 |
}; |
fabc2fee32b3
(svn r8611) -Fix: Moved the aircraft speed limiting into UpdateAircraftSpeed and enummed some speed limits. This should give a more steady display in the status bar during taxiing
celestar
parents:
5944
diff
changeset
|
894 |
|
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
895 |
/** |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
896 |
* Sets the new speed for an aircraft |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
897 |
* @param v The vehicle for which the speed should be obtained |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
898 |
* @param speed_limit The maximum speed the vehicle may have. |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
899 |
* @param hard_limit If true, the limit is directly enforced, otherwise the plane is slowed down gradually |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
900 |
* @return The number of position updates needed within the tick |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
901 |
*/ |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
902 |
static int UpdateAircraftSpeed(Vehicle *v, uint speed_limit = SPEED_LIMIT_NONE, bool hard_limit = true) |
0 | 903 |
{ |
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
904 |
uint spd = v->acceleration * 16; |
0 | 905 |
byte t; |
906 |
||
6490
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
907 |
if (v->u.air.cached_max_speed < speed_limit) { |
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
908 |
if (v->cur_speed < speed_limit) hard_limit = false; |
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
909 |
speed_limit = v->u.air.cached_max_speed; |
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
910 |
} |
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
911 |
|
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
912 |
speed_limit = min(speed_limit, v->max_speed); |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
913 |
|
0 | 914 |
v->subspeed = (t=v->subspeed) + (byte)spd; |
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
915 |
|
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
916 |
if (!hard_limit && v->cur_speed > speed_limit) speed_limit = v->cur_speed - (v->cur_speed / 48); |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
917 |
|
5945
fabc2fee32b3
(svn r8611) -Fix: Moved the aircraft speed limiting into UpdateAircraftSpeed and enummed some speed limits. This should give a more steady display in the status bar during taxiing
celestar
parents:
5944
diff
changeset
|
918 |
spd = min(v->cur_speed + (spd >> 8) + (v->subspeed < t), speed_limit); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
919 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
920 |
/* adjust speed for broken vehicles */ |
5945
fabc2fee32b3
(svn r8611) -Fix: Moved the aircraft speed limiting into UpdateAircraftSpeed and enummed some speed limits. This should give a more steady display in the status bar during taxiing
celestar
parents:
5944
diff
changeset
|
921 |
if (v->vehstatus & VS_AIRCRAFT_BROKEN) spd = min(spd, SPEED_LIMIT_BROKEN); |
0 | 922 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
923 |
/* updates statusbar only if speed have changed to save CPU time */ |
0 | 924 |
if (spd != v->cur_speed) { |
925 |
v->cur_speed = spd; |
|
926 |
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
|
927 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 928 |
} |
929 |
||
2639 | 930 |
if (!(v->direction & 1)) spd = spd * 3 / 4; |
0 | 931 |
|
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
932 |
spd += v->progress; |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
933 |
v->progress = (byte)spd; |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
934 |
return spd >> 8; |
0 | 935 |
} |
936 |
||
5908
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
937 |
/** |
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
938 |
* Gets the cruise altitude of an aircraft. |
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
939 |
* The cruise altitude is determined by the velocity of the vehicle |
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
940 |
* and the direction it is moving |
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
941 |
* @param v The vehicle. Should be an aircraft |
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
942 |
* @returns Altitude in pixel units |
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
943 |
*/ |
0 | 944 |
static byte GetAircraftFlyingAltitude(const Vehicle *v) |
945 |
{ |
|
5908
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
946 |
/* Make sure Aircraft fly no lower so that they don't conduct |
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
947 |
* CFITs (controlled flight into terrain) |
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
948 |
*/ |
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
949 |
byte base_altitude = 150; |
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
950 |
|
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
951 |
/* Make sure eastbound and westbound planes do not "crash" into each |
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
952 |
* other by providing them with vertical seperation |
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
953 |
*/ |
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
954 |
switch (v->direction) { |
6087 | 955 |
case DIR_N: |
956 |
case DIR_NE: |
|
957 |
case DIR_E: |
|
958 |
case DIR_SE: |
|
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
959 |
base_altitude += 10; |
6087 | 960 |
break; |
961 |
||
5908
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
962 |
default: break; |
0 | 963 |
} |
5908
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
964 |
|
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
965 |
/* Make faster planes fly higher so that they can overtake slower ones */ |
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
966 |
base_altitude += min(20 * (v->max_speed / 200), 90); |
5908
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
967 |
|
5ff4fe308285
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
celestar
parents:
5886
diff
changeset
|
968 |
return base_altitude; |
0 | 969 |
} |
970 |
||
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
971 |
/** |
6394
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
972 |
* Find the entry point to an airport depending on direction which |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
973 |
* the airport is being approached from. Each airport can have up to |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
974 |
* four entry points for its approach system so that approaching |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
975 |
* aircraft do not fly through each other or are forced to do 180 |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
976 |
* degree turns during the approach. The arrivals are grouped into |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
977 |
* four sectors dependent on the DiagDirection from which the airport |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
978 |
* is approached. |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
979 |
* |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
980 |
* @param v The vehicle that is approaching the airport |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
981 |
* @param apc The Airport Class being approached. |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
982 |
* @returns The index of the entry point |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
983 |
*/ |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
984 |
static byte AircraftGetEntryPoint(const Vehicle *v, const AirportFTAClass *apc) |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
985 |
{ |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
986 |
assert(v != NULL); |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
987 |
assert(apc != NULL); |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
988 |
|
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
989 |
const Station *st = GetStation(v->u.air.targetairport); |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
990 |
/* Make sure we don't go to 0,0 if the airport has been removed. */ |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
991 |
TileIndex tile = (st->airport_tile != 0) ? st->airport_tile : st->xy; |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
992 |
|
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
993 |
int delta_x = v->x_pos - TileX(tile) * TILE_SIZE; |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
994 |
int delta_y = v->y_pos - TileY(tile) * TILE_SIZE; |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
995 |
|
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
996 |
DiagDirection dir; |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
997 |
if (abs(delta_y) < abs(delta_x)) { |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
998 |
/* We are northeast or southwest of the airport */ |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
999 |
dir = delta_x < 0 ? DIAGDIR_NE : DIAGDIR_SW; |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1000 |
} else { |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1001 |
/* We are northwest or southeast of the airport */ |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1002 |
dir = delta_y < 0 ? DIAGDIR_NW : DIAGDIR_SE; |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1003 |
} |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1004 |
return apc->entry_points[dir]; |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1005 |
} |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1006 |
|
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1007 |
/** |
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1008 |
* Controls the movement of an aircraft. This function actually moves the vehicle |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1009 |
* on the map and takes care of minor things like sound playback. |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1010 |
* @todo De-mystify the cur_speed values for helicopter rotors. |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1011 |
* @param v The vehicle that is moved. Must be the first vehicle of the chain |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1012 |
* @return Whether the position requested by the State Machine has been reached |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1013 |
*/ |
1401
44a7e0f04d28
(svn r1905) - Fix: [ 1118810 ] openttd: ship_cmd.c:642 ... Assertion failed. Mapwrap fixed in ship_cmd.c (was implicitely ok before biggermaps).
Darkvater
parents:
1359
diff
changeset
|
1014 |
static bool AircraftController(Vehicle *v) |
0 | 1015 |
{ |
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1016 |
int count; |
6087 | 1017 |
const Station *st = GetStation(v->u.air.targetairport); |
6394
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1018 |
const AirportFTAClass *afc = st->Airport(); |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1019 |
const AirportMovingData *amd; |
0 | 1020 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1021 |
/* prevent going to 0,0 if airport is deleted. */ |
6087 | 1022 |
TileIndex tile = st->airport_tile; |
6394
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1023 |
if (tile == 0) { |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1024 |
tile = st->xy; |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1025 |
|
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1026 |
/* Jump into our "holding pattern" state machine if possible */ |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1027 |
if (v->u.air.pos >= afc->nofelements) v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, afc); |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1028 |
} |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1029 |
|
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1030 |
/* get airport moving data */ |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1031 |
amd = afc->MovingData(v->u.air.pos); |
dabe045f6f14
(svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents:
6350
diff
changeset
|
1032 |
|
6087 | 1033 |
int x = TileX(tile) * TILE_SIZE; |
1034 |
int y = TileY(tile) * TILE_SIZE; |
|
0 | 1035 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1036 |
/* Helicopter raise */ |
0 | 1037 |
if (amd->flag & AMED_HELI_RAISE) { |
6087 | 1038 |
Vehicle *u = v->next->next; |
0 | 1039 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1040 |
/* Make sure the rotors don't rotate too fast */ |
0 | 1041 |
if (u->cur_speed > 32) { |
1042 |
v->cur_speed = 0; |
|
2639 | 1043 |
if (--u->cur_speed == 32) SndPlayVehicleFx(SND_18_HELICOPTER, v); |
0 | 1044 |
} else { |
1045 |
u->cur_speed = 32; |
|
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1046 |
count = UpdateAircraftSpeed(v); |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1047 |
if (count > 0) { |
0 | 1048 |
v->tile = 0; |
1049 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1050 |
/* Reached altitude? */ |
0 | 1051 |
if (v->z_pos >= 184) { |
1052 |
v->cur_speed = 0; |
|
1053 |
return true; |
|
1054 |
} |
|
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1055 |
SetAircraftPosition(v, v->x_pos, v->y_pos, min(v->z_pos + count, 184)); |
0 | 1056 |
} |
1057 |
} |
|
1058 |
return false; |
|
1059 |
} |
|
1060 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1061 |
/* Helicopter landing. */ |
0 | 1062 |
if (amd->flag & AMED_HELI_LOWER) { |
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1063 |
count = UpdateAircraftSpeed(v); |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1064 |
if (count > 0) { |
0 | 1065 |
if (st->airport_tile == 0) { |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1066 |
/* FIXME - AircraftController -> if station no longer exists, do not land |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1067 |
* helicopter will circle until sign disappears, then go to next order |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1068 |
* what to do when it is the only order left, right now it just stays in 1 place */ |
0 | 1069 |
v->u.air.state = FLYING; |
1070 |
AircraftNextAirportPos_and_Order(v); |
|
1071 |
return false; |
|
1072 |
} |
|
1073 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1074 |
/* Vehicle is now at the airport. */ |
0 | 1075 |
v->tile = st->airport_tile; |
1076 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1077 |
/* Find altitude of landing position. */ |
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1078 |
int z = GetSlopeZ(x, y) + 1 + afc->delta_z; |
0 | 1079 |
|
1080 |
if (z == v->z_pos) { |
|
6087 | 1081 |
Vehicle *u = v->next->next; |
0 | 1082 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1083 |
/* Increase speed of rotors. When speed is 80, we've landed. */ |
2639 | 1084 |
if (u->cur_speed >= 80) return true; |
1085 |
u->cur_speed += 4; |
|
0 | 1086 |
} else if (v->z_pos > z) { |
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1087 |
SetAircraftPosition(v, v->x_pos, v->y_pos, max(v->z_pos - count, z)); |
0 | 1088 |
} else { |
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1089 |
SetAircraftPosition(v, v->x_pos, v->y_pos, min(v->z_pos + count, z)); |
0 | 1090 |
} |
1091 |
} |
|
1092 |
return false; |
|
1093 |
} |
|
1094 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1095 |
/* Get distance from destination pos to current pos. */ |
6087 | 1096 |
uint dist = myabs(x + amd->x - v->x_pos) + myabs(y + amd->y - v->y_pos); |
0 | 1097 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1098 |
/* Need exact position? */ |
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1099 |
if (!(amd->flag & AMED_EXACTPOS) && dist <= (amd->flag & AMED_SLOWTURN ? 8U : 4U)) return true; |
0 | 1100 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1101 |
/* At final pos? */ |
0 | 1102 |
if (dist == 0) { |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1103 |
/* Change direction smoothly to final direction. */ |
6087 | 1104 |
DirDiff dirdiff = DirDifference(amd->direction, v->direction); |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1105 |
/* if distance is 0, and plane points in right direction, no point in calling |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1106 |
* UpdateAircraftSpeed(). So do it only afterwards */ |
3158
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
1107 |
if (dirdiff == DIRDIFF_SAME) { |
0 | 1108 |
v->cur_speed = 0; |
1109 |
return true; |
|
1110 |
} |
|
1111 |
||
5945
fabc2fee32b3
(svn r8611) -Fix: Moved the aircraft speed limiting into UpdateAircraftSpeed and enummed some speed limits. This should give a more steady display in the status bar during taxiing
celestar
parents:
5944
diff
changeset
|
1112 |
if (!UpdateAircraftSpeed(v, SPEED_LIMIT_TAXI)) return false; |
0 | 1113 |
|
3158
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
1114 |
v->direction = ChangeDir(v->direction, dirdiff > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT); |
0 | 1115 |
v->cur_speed >>= 1; |
1116 |
||
1117 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos); |
|
1118 |
return false; |
|
1119 |
} |
|
1120 |
||
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1121 |
uint speed_limit = SPEED_LIMIT_TAXI; |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1122 |
bool hard_limit = true; |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1123 |
|
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1124 |
if (amd->flag & AMED_NOSPDCLAMP) speed_limit = SPEED_LIMIT_NONE; |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1125 |
if (amd->flag & AMED_HOLD) { speed_limit = SPEED_LIMIT_HOLD; hard_limit = false; } |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1126 |
if (amd->flag & AMED_LAND) { speed_limit = SPEED_LIMIT_APPROACH; hard_limit = false; } |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1127 |
if (amd->flag & AMED_BRAKE) { speed_limit = SPEED_LIMIT_TAXI; hard_limit = false; } |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1128 |
|
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1129 |
count = UpdateAircraftSpeed(v, speed_limit, hard_limit); |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1130 |
if (count == 0) return false; |
0 | 1131 |
|
2639 | 1132 |
if (v->load_unload_time_rem != 0) v->load_unload_time_rem--; |
0 | 1133 |
|
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1134 |
do { |
6327
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1135 |
|
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1136 |
GetNewVehiclePosResult gp; |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1137 |
|
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1138 |
if (dist < 4) { |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1139 |
/* move vehicle one pixel towards target */ |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1140 |
gp.x = (v->x_pos != (x + amd->x)) ? |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1141 |
v->x_pos + ((x + amd->x > v->x_pos) ? 1 : -1) : |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1142 |
v->x_pos; |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1143 |
gp.y = (v->y_pos != (y + amd->y)) ? |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1144 |
v->y_pos + ((y + amd->y > v->y_pos) ? 1 : -1) : |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1145 |
v->y_pos; |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1146 |
|
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1147 |
/* Oilrigs must keep v->tile as st->airport_tile, since the landing pad is in a non-airport tile */ |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1148 |
gp.new_tile = (st->airport_type == AT_OILRIG) ? st->airport_tile : TileVirtXY(gp.x, gp.y); |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1149 |
|
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1150 |
} else { |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1151 |
|
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1152 |
/* Turn. Do it slowly if in the air. */ |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1153 |
Direction newdir = GetDirectionTowards(v, x + amd->x, y + amd->y); |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1154 |
if (newdir != v->direction) { |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1155 |
v->direction = newdir; |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1156 |
if (amd->flag & AMED_SLOWTURN) { |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1157 |
if (v->load_unload_time_rem == 0) v->load_unload_time_rem = 8; |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1158 |
} else { |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1159 |
v->cur_speed >>= 1; |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1160 |
} |
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1161 |
} |
6327
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1162 |
|
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1163 |
/* Move vehicle. */ |
1c98317eba09
(svn r9299) -Fix (FS#675,FS#660): Small micro-movements on airports (of <4 pixels) caused odd aircraft movements. On oilrigs, this caused a full crash as movement would take helicopter out of airport/station tile.
richk
parents:
6316
diff
changeset
|
1164 |
gp = GetNewVehiclePos(v); |
0 | 1165 |
} |
1166 |
||
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1167 |
v->tile = gp.new_tile; |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1168 |
/* If vehicle is in the air, use tile coordinate 0. */ |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1169 |
// if (amd->flag & (AMED_TAKEOFF | AMED_SLOWTURN | AMED_LAND)) v->tile = 0; |
0 | 1170 |
|
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1171 |
/* Adjust Z for land or takeoff? */ |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1172 |
uint z = v->z_pos; |
0 | 1173 |
|
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1174 |
if (amd->flag & AMED_TAKEOFF) { |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1175 |
z = min(z + 2, GetAircraftFlyingAltitude(v)); |
2639 | 1176 |
} |
0 | 1177 |
|
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1178 |
if ((amd->flag & AMED_HOLD) && (z > 150)) z--; |
0 | 1179 |
|
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1180 |
if (amd->flag & AMED_LAND) { |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1181 |
if (st->airport_tile == 0) { |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1182 |
/* Airport has been removed, abort the landing procedure */ |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1183 |
v->u.air.state = FLYING; |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1184 |
AircraftNextAirportPos_and_Order(v); |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1185 |
/* get aircraft back on running altitude */ |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1186 |
SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v)); |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1187 |
continue; |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1188 |
} |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1189 |
|
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1190 |
uint curz = GetSlopeZ(x, y) + 1; |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1191 |
|
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1192 |
if (curz > z) { |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1193 |
z++; |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1194 |
} else { |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1195 |
int t = max(1U, dist - 4); |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1196 |
|
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1197 |
z -= ((z - curz) + t - 1) / t; |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1198 |
if (z < curz) z = curz; |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1199 |
} |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1200 |
} |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1201 |
|
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1202 |
/* We've landed. Decrase speed when we're reaching end of runway. */ |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1203 |
if (amd->flag & AMED_BRAKE) { |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1204 |
uint curz = GetSlopeZ(x, y) + 1; |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1205 |
|
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1206 |
if (z > curz) { |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1207 |
z--; |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1208 |
} else if (z < curz) { |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1209 |
z++; |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1210 |
} |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1211 |
|
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1212 |
} |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1213 |
|
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1214 |
SetAircraftPosition(v, gp.x, gp.y, z); |
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
1215 |
} while (--count != 0); |
0 | 1216 |
return false; |
1217 |
} |
|
1218 |
||
1219 |
||
1220 |
static void HandleCrashedAircraft(Vehicle *v) |
|
1221 |
{ |
|
1222 |
v->u.air.crashed_counter++; |
|
1223 |
||
6087 | 1224 |
Station *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
|
1225 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1226 |
/* make aircraft crash down to the ground */ |
1150
7b5946a53372
(svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents:
1139
diff
changeset
|
1227 |
if (v->u.air.crashed_counter < 500 && st->airport_tile==0 && ((v->u.air.crashed_counter % 3) == 0) ) { |
6087 | 1228 |
uint 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
|
1229 |
v->z_pos -= 1; |
1150
7b5946a53372
(svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents:
1139
diff
changeset
|
1230 |
if (v->z_pos == z) { |
7b5946a53372
(svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents:
1139
diff
changeset
|
1231 |
v->u.air.crashed_counter = 500; |
7b5946a53372
(svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents:
1139
diff
changeset
|
1232 |
v->z_pos++; |
7b5946a53372
(svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents:
1139
diff
changeset
|
1233 |
} |
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
|
1234 |
} |
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
|
1235 |
|
0 | 1236 |
if (v->u.air.crashed_counter < 650) { |
6087 | 1237 |
uint32 r; |
0 | 1238 |
if (CHANCE16R(1,32,r)) { |
3160 | 1239 |
static const DirDiff delta[] = { |
1240 |
DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT |
|
1241 |
}; |
|
1242 |
||
1243 |
v->direction = ChangeDir(v->direction, delta[GB(r, 16, 2)]); |
|
0 | 1244 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos); |
1245 |
r = Random(); |
|
1246 |
CreateEffectVehicleRel(v, |
|
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
1247 |
GB(r, 0, 4) + 4, |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
1248 |
GB(r, 4, 4) + 4, |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
1249 |
GB(r, 8, 4), |
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1299
diff
changeset
|
1250 |
EV_EXPLOSION_SMALL); |
0 | 1251 |
} |
1252 |
} else if (v->u.air.crashed_counter >= 10000) { |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1253 |
/* remove rubble of crashed airplane */ |
0 | 1254 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1255 |
/* clear runway-in on all airports, set by crashing plane |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1256 |
* small airports use AIRPORT_BUSY, city airports use RUNWAY_IN_OUT_block, etc. |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1257 |
* but they all share the same number */ |
0 | 1258 |
CLRBITS(st->airport_flags, RUNWAY_IN_block); |
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4056
diff
changeset
|
1259 |
CLRBITS(st->airport_flags, RUNWAY_IN_OUT_block); // commuter airport |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1260 |
CLRBITS(st->airport_flags, RUNWAY_IN2_block); // intercontinental |
0 | 1261 |
|
1262 |
BeginVehicleMove(v); |
|
1263 |
EndVehicleMove(v); |
|
1264 |
||
1265 |
DoDeleteAircraft(v); |
|
1266 |
} |
|
1267 |
} |
|
1268 |
||
1269 |
static void HandleBrokenAircraft(Vehicle *v) |
|
1270 |
{ |
|
1271 |
if (v->breakdown_ctr != 1) { |
|
1272 |
v->breakdown_ctr = 1; |
|
1273 |
v->vehstatus |= VS_AIRCRAFT_BROKEN; |
|
1274 |
||
1275 |
if (v->breakdowns_since_last_service != 255) |
|
1276 |
v->breakdowns_since_last_service++; |
|
1277 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
|
1278 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1279 |
} |
|
1280 |
} |
|
1281 |
||
1282 |
||
1283 |
static void HandleAircraftSmoke(Vehicle *v) |
|
1284 |
{ |
|
2654
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1285 |
static const struct { |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1286 |
int8 x; |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1287 |
int8 y; |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1288 |
} smoke_pos[] = { |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1289 |
{ 5, 5 }, |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1290 |
{ 6, 0 }, |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1291 |
{ 5, -5 }, |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1292 |
{ 0, -6 }, |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1293 |
{ -5, -5 }, |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1294 |
{ -6, 0 }, |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1295 |
{ -5, 5 }, |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1296 |
{ 0, 6 } |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1297 |
}; |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1298 |
|
2639 | 1299 |
if (!(v->vehstatus & VS_AIRCRAFT_BROKEN)) return; |
0 | 1300 |
|
1301 |
if (v->cur_speed < 10) { |
|
1302 |
v->vehstatus &= ~VS_AIRCRAFT_BROKEN; |
|
1303 |
v->breakdown_ctr = 0; |
|
1304 |
return; |
|
1305 |
} |
|
1306 |
||
1307 |
if ((v->tick_counter & 0x1F) == 0) { |
|
1308 |
CreateEffectVehicleRel(v, |
|
2654
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1309 |
smoke_pos[v->direction].x, |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1310 |
smoke_pos[v->direction].y, |
0 | 1311 |
2, |
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1299
diff
changeset
|
1312 |
EV_SMOKE |
0 | 1313 |
); |
1314 |
} |
|
1315 |
} |
|
1316 |
||
1317 |
static void ProcessAircraftOrder(Vehicle *v) |
|
1318 |
{ |
|
3005
2590b9b4823b
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2989
diff
changeset
|
1319 |
switch (v->current_order.type) { |
2590b9b4823b
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2989
diff
changeset
|
1320 |
case OT_GOTO_DEPOT: |
2590b9b4823b
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2989
diff
changeset
|
1321 |
if (!(v->current_order.flags & OF_PART_OF_ORDERS)) return; |
2590b9b4823b
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2989
diff
changeset
|
1322 |
if (v->current_order.flags & OF_SERVICE_IF_NEEDED && |
2590b9b4823b
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2989
diff
changeset
|
1323 |
!VehicleNeedsService(v)) { |
2590b9b4823b
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2989
diff
changeset
|
1324 |
v->cur_order_index++; |
2590b9b4823b
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2989
diff
changeset
|
1325 |
} |
2590b9b4823b
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2989
diff
changeset
|
1326 |
break; |
2590b9b4823b
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2989
diff
changeset
|
1327 |
|
2590b9b4823b
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2989
diff
changeset
|
1328 |
case OT_LOADING: return; |
4351
c9799dd53eec
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4346
diff
changeset
|
1329 |
|
c9799dd53eec
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4346
diff
changeset
|
1330 |
default: break; |
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
|
1331 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1332 |
|
2639 | 1333 |
if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0; |
0 | 1334 |
|
6087 | 1335 |
const Order *order = GetVehicleOrder(v, v->cur_order_index); |
0 | 1336 |
|
6167
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1337 |
if (order == NULL|| (order->type == OT_DUMMY && !CheckForValidOrders(v))) { |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1338 |
/* |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1339 |
* We do not have an order. This can be divided into two cases: |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1340 |
* 1) we are heading to an invalid station. In this case we must |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1341 |
* find another airport to go to. If there is nowhere to go, |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1342 |
* we will destroy the aircraft as it otherwise will enter |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1343 |
* the holding pattern for the first airport, which can cause |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1344 |
* the plane to go into an undefined state when building an |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1345 |
* airport with the same StationID. |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1346 |
* 2) we are (still) heading to a (still) valid airport, then we |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1347 |
* can continue going there. This can happen when you are |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1348 |
* changing the aircraft's orders while in-flight or in for |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1349 |
* example a depot. However, when we have a current order to |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1350 |
* go to a depot, we have to keep that order so the aircraft |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1351 |
* actually stops. |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1352 |
*/ |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1353 |
const Station *st = GetStation(v->u.air.targetairport); |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1354 |
if (!st->IsValid() || st->airport_tile == 0) { |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1355 |
int32 ret; |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1356 |
PlayerID old_player = _current_player; |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1357 |
|
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1358 |
_current_player = v->owner; |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1359 |
ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR); |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1360 |
_current_player = old_player; |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1361 |
|
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1362 |
if (CmdFailed(ret)) CrashAirplane(v); |
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1363 |
} else if (v->current_order.type != OT_GOTO_DEPOT) { |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1364 |
v->current_order.Free(); |
6167
9add67b1eefa
(svn r8921) -Fix (FS#654): several issues related to removing all orders from an aircraft and removing the airport it was heading:
rubidium
parents:
6153
diff
changeset
|
1365 |
} |
0 | 1366 |
return; |
1367 |
} |
|
1368 |
||
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
1369 |
if (order->type == v->current_order.type && |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
1370 |
order->flags == v->current_order.flags && |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
1371 |
order->dest == v->current_order.dest) |
0 | 1372 |
return; |
1373 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1374 |
v->current_order = *order; |
0 | 1375 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1376 |
/* 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
|
1377 |
if (order->type == OT_GOTO_STATION && v->u.air.state == FLYING) { |
0 | 1378 |
AircraftNextAirportPos_and_Order(v); |
1379 |
} |
|
1380 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1381 |
InvalidateVehicleOrder(v); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1382 |
|
1055
cc4f60cc9102
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
1383 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 1384 |
} |
1385 |
||
3722
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1386 |
/** Mark all views dirty for an aircraft. |
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1387 |
* @param v vehicle to be redrawn. |
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1388 |
*/ |
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1389 |
static void MarkAircraftDirty(Vehicle *v) |
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1390 |
{ |
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1391 |
v->cur_image = GetAircraftImage(v, v->direction); |
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
1392 |
if (v->subtype == AIR_HELICOPTER) v->next->next->cur_image = GetRotorImage(v); |
3722
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1393 |
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); |
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1394 |
} |
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1395 |
|
0 | 1396 |
static void HandleAircraftLoading(Vehicle *v, int mode) |
1397 |
{ |
|
5856 | 1398 |
switch (v->current_order.type) { |
5858
a48c5b18747a
(svn r8434) -Fix (r8430): Missing braces caused compilation failure for some (most?) compilers...
peter1138
parents:
5856
diff
changeset
|
1399 |
case OT_LOADING: { |
5856 | 1400 |
if (mode != 0) return; |
1401 |
if (--v->load_unload_time_rem != 0) return; |
|
0 | 1402 |
|
5856 | 1403 |
if (CanFillVehicle(v) && ( |
1404 |
v->current_order.flags & OF_FULL_LOAD || |
|
6175
313c2b5e7ae2
(svn r8945) -Codechange: Rename v->load_status to v->vehicle_flags so it can be used for more than just the gradual loading status.
maedhros
parents:
6167
diff
changeset
|
1405 |
(_patches.gradual_loading && !HASBIT(v->vehicle_flags, VF_LOADING_FINISHED)) |
5856 | 1406 |
)) { |
1407 |
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC); |
|
1408 |
if (LoadUnloadVehicle(v, false)) { |
|
1409 |
InvalidateWindow(WC_AIRCRAFT_LIST, v->owner); |
|
1410 |
MarkAircraftDirty(v); |
|
1411 |
} |
|
1412 |
return; |
|
3722
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1413 |
} |
0 | 1414 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1415 |
Order b = v->current_order; |
6501
7df55f74f00c
(svn r9684) -Fix (r9683): Remove vehicles from the station loading list instead of adding
maedhros
parents:
6495
diff
changeset
|
1416 |
v->LeaveStation(); |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1417 |
v->current_order.Free(); |
3722
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1418 |
MarkAircraftDirty(v); |
2639 | 1419 |
if (!(b.flags & OF_NON_STOP)) return; |
5856 | 1420 |
break; |
5858
a48c5b18747a
(svn r8434) -Fix (r8430): Missing braces caused compilation failure for some (most?) compilers...
peter1138
parents:
5856
diff
changeset
|
1421 |
} |
5856 | 1422 |
|
1423 |
case OT_DUMMY: break; |
|
1424 |
||
1425 |
default: return; |
|
0 | 1426 |
} |
5856 | 1427 |
|
0 | 1428 |
v->cur_order_index++; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1429 |
InvalidateVehicleOrder(v); |
0 | 1430 |
} |
1431 |
||
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
|
1432 |
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
|
1433 |
{ |
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
|
1434 |
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
|
1435 |
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
|
1436 |
|
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1299
diff
changeset
|
1437 |
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); |
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
|
1438 |
|
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
|
1439 |
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
|
1440 |
|
6087 | 1441 |
uint amt = 2; |
6334
a8f01a805813
(svn r9322) -Codechange: Use cargo class to count crash/flood victims
peter1138
parents:
6327
diff
changeset
|
1442 |
if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) amt += v->cargo_count; |
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
|
1443 |
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
|
1444 |
|
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
|
1445 |
v->cargo_count = 0; |
5951 | 1446 |
v->next->cargo_count = 0; |
6087 | 1447 |
const Station *st = GetStation(v->u.air.targetairport); |
1448 |
StringID newsitem; |
|
2639 | 1449 |
if (st->airport_tile == 0) { |
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
|
1450 |
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
|
1451 |
} 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
|
1452 |
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
|
1453 |
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
|
1454 |
} |
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
|
1455 |
|
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
|
1456 |
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
|
1457 |
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
|
1458 |
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
|
1459 |
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
|
1460 |
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
|
1461 |
|
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
|
1462 |
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
|
1463 |
} |
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
|
1464 |
|
0 | 1465 |
static void MaybeCrashAirplane(Vehicle *v) |
1466 |
{ |
|
6087 | 1467 |
Station *st = GetStation(v->u.air.targetairport); |
0 | 1468 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1469 |
/* FIXME -- MaybeCrashAirplane -> increase crashing chances of very modern airplanes on smaller than AT_METROPOLITAN airports */ |
6087 | 1470 |
uint16 prob = 0x10000 / 1500; |
6032 | 1471 |
if (st->Airport()->flags & AirportFTAClass::SHORT_STRIP && |
6025 | 1472 |
AircraftVehInfo(v->engine_type)->subtype & AIR_FAST && |
1473 |
!_cheats.no_jetcrash.value) { |
|
0 | 1474 |
prob = 0x10000 / 20; |
1475 |
} |
|
1476 |
||
2484
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2477
diff
changeset
|
1477 |
if (GB(Random(), 0, 16) > prob) return; |
0 | 1478 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1479 |
/* Crash the airplane. Remove all goods stored at the station. */ |
6350
04b19f551aec
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents:
6340
diff
changeset
|
1480 |
for (CargoID i = 0; i < NUM_CARGO; i++) { |
0 | 1481 |
st->goods[i].rating = 1; |
2504
5ae89f643cdc
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2484
diff
changeset
|
1482 |
SB(st->goods[i].waiting_acceptance, 0, 12, 0); |
0 | 1483 |
} |
1484 |
||
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
|
1485 |
CrashAirplane(v); |
0 | 1486 |
} |
1487 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1488 |
/** we've landed and just arrived at a terminal */ |
0 | 1489 |
static void AircraftEntersTerminal(Vehicle *v) |
1490 |
{ |
|
2639 | 1491 |
if (v->current_order.type == OT_GOTO_DEPOT) return; |
0 | 1492 |
|
6087 | 1493 |
Station *st = GetStation(v->u.air.targetairport); |
0 | 1494 |
v->last_station_visited = v->u.air.targetairport; |
1495 |
||
1496 |
/* Check if station was ever visited before */ |
|
1497 |
if (!(st->had_vehicle_of_type & HVOT_AIRCRAFT)) { |
|
1498 |
uint32 flags; |
|
1499 |
||
1500 |
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
|
1501 |
SetDParam(0, st->index); |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1502 |
/* show newsitem of celebrating citizens */ |
0 | 1503 |
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); |
1504 |
AddNewsItem( |
|
1505 |
STR_A033_CITIZENS_CELEBRATE_FIRST, |
|
1506 |
flags, |
|
1507 |
v->index, |
|
1508 |
0); |
|
1509 |
} |
|
1510 |
||
6087 | 1511 |
Order old_order = v->current_order; |
5651
79496e6d8a56
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5601
diff
changeset
|
1512 |
v->BeginLoading(); |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1513 |
v->current_order.flags = 0; |
0 | 1514 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1515 |
if (old_order.type == OT_GOTO_STATION && |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
1516 |
v->current_order.dest == v->last_station_visited) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1517 |
v->current_order.flags = |
3872
a407dc67b041
(svn r4914) -Fix (FS#180) Aircraft can now serve as feeders
celestar
parents:
3870
diff
changeset
|
1518 |
(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER)) | OF_NON_STOP; |
0 | 1519 |
} |
1520 |
||
1521 |
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC); |
|
5211
fb4dc0ca975d
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5198
diff
changeset
|
1522 |
LoadUnloadVehicle(v, true); |
3722
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1523 |
MarkAircraftDirty(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
|
1524 |
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
|
1525 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 1526 |
} |
1527 |
||
1528 |
static void AircraftLand(Vehicle *v) |
|
1529 |
{ |
|
1530 |
v->sprite_width = v->sprite_height = 2; |
|
1531 |
} |
|
1532 |
||
1533 |
static void AircraftLandAirplane(Vehicle *v) |
|
1534 |
{ |
|
1535 |
AircraftLand(v); |
|
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
1536 |
if (!PlayVehicleSound(v, VSE_TOUCHDOWN)) { |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
1537 |
SndPlayVehicleFx(SND_17_SKID_PLANE, v); |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
1538 |
} |
0 | 1539 |
MaybeCrashAirplane(v); |
1540 |
} |
|
1541 |
||
6036
333637e97400
(svn r8759) -Feature: Allow airports to have up to 4 entry points depending on approach direction. Note: they're not yet used, but will be soon
celestar
parents:
6032
diff
changeset
|
1542 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1543 |
/** set the right pos when heading to other airports after takeoff */ |
0 | 1544 |
static void AircraftNextAirportPos_and_Order(Vehicle *v) |
1545 |
{ |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1546 |
if (v->current_order.type == OT_GOTO_STATION || |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1547 |
v->current_order.type == OT_GOTO_DEPOT) |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
1548 |
v->u.air.targetairport = v->current_order.dest; |
0 | 1549 |
|
6032 | 1550 |
const AirportFTAClass *apc = GetStation(v->u.air.targetairport)->Airport(); |
6036
333637e97400
(svn r8759) -Feature: Allow airports to have up to 4 entry points depending on approach direction. Note: they're not yet used, but will be soon
celestar
parents:
6032
diff
changeset
|
1551 |
v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, apc); |
0 | 1552 |
} |
1553 |
||
1554 |
static void AircraftLeaveHangar(Vehicle *v) |
|
1555 |
{ |
|
1556 |
v->cur_speed = 0; |
|
1557 |
v->subspeed = 0; |
|
1558 |
v->progress = 0; |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5585
diff
changeset
|
1559 |
v->direction = DIR_SE; |
0 | 1560 |
v->vehstatus &= ~VS_HIDDEN; |
1561 |
{ |
|
1562 |
Vehicle *u = v->next; |
|
1563 |
u->vehstatus &= ~VS_HIDDEN; |
|
1564 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1565 |
/* Rotor blades */ |
2639 | 1566 |
u = u->next; |
1567 |
if (u != NULL) { |
|
0 | 1568 |
u->vehstatus &= ~VS_HIDDEN; |
1569 |
u->cur_speed = 80; |
|
1570 |
} |
|
1571 |
} |
|
1572 |
||
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
|
1573 |
VehicleServiceInDepot(v); |
0 | 1574 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos); |
4739
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4732
diff
changeset
|
1575 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
1055
cc4f60cc9102
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
1576 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 1577 |
} |
1578 |
||
1579 |
||
1580 |
//////////////////////////////////////////////////////////////////////////////// |
|
1581 |
/////////////////// AIRCRAFT MOVEMENT SCHEME //////////////////////////////// |
|
1582 |
//////////////////////////////////////////////////////////////////////////////// |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1583 |
static void AircraftEventHandler_EnterTerminal(Vehicle *v, const AirportFTAClass *apc) |
0 | 1584 |
{ |
1585 |
AircraftEntersTerminal(v); |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1586 |
v->u.air.state = apc->layout[v->u.air.pos].heading; |
0 | 1587 |
} |
1588 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1589 |
static void AircraftEventHandler_EnterHangar(Vehicle *v, const AirportFTAClass *apc) |
0 | 1590 |
{ |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1591 |
VehicleEnterDepot(v); |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1592 |
v->u.air.state = apc->layout[v->u.air.pos].heading; |
0 | 1593 |
} |
1594 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1595 |
/** In an Airport Hangar */ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1596 |
static void AircraftEventHandler_InHangar(Vehicle *v, const AirportFTAClass *apc) |
0 | 1597 |
{ |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1598 |
/* if we just arrived, execute EnterHangar first */ |
0 | 1599 |
if (v->u.air.previous_pos != v->u.air.pos) { |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1600 |
AircraftEventHandler_EnterHangar(v, apc); |
0 | 1601 |
return; |
1602 |
} |
|
1603 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1604 |
/* if we were sent to the depot, stay there */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1605 |
if (v->current_order.type == OT_GOTO_DEPOT && (v->vehstatus & VS_STOPPED)) { |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1606 |
v->current_order.Free(); |
0 | 1607 |
return; |
1608 |
} |
|
1609 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1610 |
if (v->current_order.type != OT_GOTO_STATION && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1611 |
v->current_order.type != OT_GOTO_DEPOT) |
0 | 1612 |
return; |
1613 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1614 |
/* if the block of the next position is busy, stay put */ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1615 |
if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return; |
0 | 1616 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1617 |
/* We are already at the target airport, we need to find a terminal */ |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
1618 |
if (v->current_order.dest == v->u.air.targetairport) { |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1619 |
/* FindFreeTerminal: |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1620 |
* 1. Find a free terminal, 2. Occupy it, 3. Set the vehicle's state to that terminal */ |
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
1621 |
if (v->subtype == AIR_HELICOPTER) { |
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
1622 |
if (!AirportFindFreeHelipad(v, apc)) return; // helicopter |
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
1623 |
} else { |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1624 |
if (!AirportFindFreeTerminal(v, apc)) return; // airplane |
2549 | 1625 |
} |
1626 |
} else { // Else prepare for launch. |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1627 |
/* airplane goto state takeoff, helicopter to helitakeoff */ |
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
1628 |
v->u.air.state = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : TAKEOFF; |
0 | 1629 |
} |
1630 |
AircraftLeaveHangar(v); |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1631 |
AirportMove(v, apc); |
0 | 1632 |
} |
1633 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1634 |
/** At one of the Airport's Terminals */ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1635 |
static void AircraftEventHandler_AtTerminal(Vehicle *v, const AirportFTAClass *apc) |
0 | 1636 |
{ |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1637 |
/* if we just arrived, execute EnterTerminal first */ |
0 | 1638 |
if (v->u.air.previous_pos != v->u.air.pos) { |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1639 |
AircraftEventHandler_EnterTerminal(v, apc); |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1640 |
/* on an airport with helipads, a helicopter will always land there |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1641 |
* and get serviced at the same time - patch setting */ |
0 | 1642 |
if (_patches.serviceathelipad) { |
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
1643 |
if (v->subtype == AIR_HELICOPTER && apc->helipads != NULL) { |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1644 |
/* an exerpt of ServiceAircraft, without the invisibility stuff */ |
0 | 1645 |
v->date_of_last_service = _date; |
1646 |
v->breakdowns_since_last_service = 0; |
|
1926
530480d14685
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1901
diff
changeset
|
1647 |
v->reliability = GetEngine(v->engine_type)->reliability; |
0 | 1648 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
1649 |
} |
|
1650 |
} |
|
1651 |
return; |
|
1652 |
} |
|
1653 |
||
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1654 |
if (!v->current_order.IsValid()) return; |
0 | 1655 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1656 |
/* if the block of the next position is busy, stay put */ |
4843
4bef85baee3f
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
1657 |
if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return; |
0 | 1658 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1659 |
/* airport-road is free. We either have to go to another airport, or to the hangar |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1660 |
* ---> start moving */ |
0 | 1661 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1662 |
switch (v->current_order.type) { |
0 | 1663 |
case OT_GOTO_STATION: // ready to fly to another airport |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1664 |
/* airplane goto state takeoff, helicopter to helitakeoff */ |
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
1665 |
v->u.air.state = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : TAKEOFF; |
0 | 1666 |
break; |
1667 |
case OT_GOTO_DEPOT: // visit hangar for serivicing, sale, etc. |
|
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
1668 |
if (v->current_order.dest == v->u.air.targetairport) { |
0 | 1669 |
v->u.air.state = HANGAR; |
2639 | 1670 |
} else { |
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
1671 |
v->u.air.state = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : TAKEOFF; |
2639 | 1672 |
} |
0 | 1673 |
break; |
1674 |
default: // orders have been deleted (no orders), goto depot and don't bother us |
|
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1675 |
v->current_order.Free(); |
0 | 1676 |
v->u.air.state = HANGAR; |
1677 |
} |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1678 |
AirportMove(v, apc); |
0 | 1679 |
} |
1680 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1681 |
static void AircraftEventHandler_General(Vehicle *v, const AirportFTAClass *apc) |
0 | 1682 |
{ |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1683 |
assert("OK, you shouldn't be here, check your Airport Scheme!" && 0); |
0 | 1684 |
} |
1685 |
||
6087 | 1686 |
static void AircraftEventHandler_TakeOff(Vehicle *v, const AirportFTAClass *apc) |
1687 |
{ |
|
0 | 1688 |
PlayAircraftSound(v); // play takeoffsound for airplanes |
1689 |
v->u.air.state = STARTTAKEOFF; |
|
1690 |
} |
|
1691 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1692 |
static void AircraftEventHandler_StartTakeOff(Vehicle *v, const AirportFTAClass *apc) |
0 | 1693 |
{ |
1694 |
v->sprite_width = v->sprite_height = 24; // ??? no idea what this is |
|
1695 |
v->u.air.state = ENDTAKEOFF; |
|
1696 |
} |
|
1697 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1698 |
static void AircraftEventHandler_EndTakeOff(Vehicle *v, const AirportFTAClass *apc) |
0 | 1699 |
{ |
1700 |
v->u.air.state = FLYING; |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1701 |
/* get the next position to go to, differs per airport */ |
0 | 1702 |
AircraftNextAirportPos_and_Order(v); |
1703 |
} |
|
1704 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1705 |
static void AircraftEventHandler_HeliTakeOff(Vehicle *v, const AirportFTAClass *apc) |
0 | 1706 |
{ |
2475 | 1707 |
const Player* p = GetPlayer(v->owner); |
0 | 1708 |
v->sprite_width = v->sprite_height = 24; // ??? no idea what this is |
1709 |
v->u.air.state = FLYING; |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1710 |
/* get the next position to go to, differs per airport */ |
0 | 1711 |
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
|
1712 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1713 |
/* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1714 |
* unless it is due for renewal but the engine is no longer available */ |
2639 | 1715 |
if (v->owner == _local_player && ( |
2848 | 1716 |
EngineHasReplacementForPlayer(p, v->engine_type) || |
4111
221355fcade6
(svn r5454) -Fix: [ 1394231 ] Autorenew glitch on helicopters
bjarni
parents:
4095
diff
changeset
|
1717 |
((p->engine_renew && v->age - v->max_age > p->engine_renew_months * 30) && |
221355fcade6
(svn r5454) -Fix: [ 1394231 ] Autorenew glitch on helicopters
bjarni
parents:
4095
diff
changeset
|
1718 |
HASBIT(GetEngine(v->engine_type)->player_avail, _local_player)) |
2639 | 1719 |
)) { |
1520
d88442095697
(svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents:
1401
diff
changeset
|
1720 |
_current_player = _local_player; |
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
1721 |
DoCommandP(v->tile, v->index, DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR); |
1520
d88442095697
(svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents:
1401
diff
changeset
|
1722 |
_current_player = OWNER_NONE; |
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
|
1723 |
} |
0 | 1724 |
} |
1725 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1726 |
static void AircraftEventHandler_Flying(Vehicle *v, const AirportFTAClass *apc) |
0 | 1727 |
{ |
6087 | 1728 |
Station *st = GetStation(v->u.air.targetairport); |
0 | 1729 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1730 |
/* runway busy or not allowed to use this airstation, circle */ |
6027
ff15b8c7c087
(svn r8750) -Fix (r8747): PLANES defined in wingdi.h caused compilation error under Win32. Changed to AIRPLANES
KUDr
parents:
6025
diff
changeset
|
1731 |
if (apc->flags & (v->subtype == AIR_HELICOPTER ? AirportFTAClass::HELICOPTERS : AirportFTAClass::AIRPLANES) && |
2639 | 1732 |
st->airport_tile != 0 && |
1733 |
(st->owner == OWNER_NONE || st->owner == v->owner)) { |
|
0 | 1734 |
// {32,FLYING,NOTHING_block,37}, {32,LANDING,N,33}, {32,HELILANDING,N,41}, |
1735 |
// if it is an airplane, look for LANDING, for helicopter HELILANDING |
|
1736 |
// it is possible to choose from multiple landing runways, so loop until a free one is found |
|
6087 | 1737 |
byte landingtype = (v->subtype == AIR_HELICOPTER) ? HELILANDING : LANDING; |
1738 |
const AirportFTA *current = apc->layout[v->u.air.pos].next; |
|
0 | 1739 |
while (current != NULL) { |
1740 |
if (current->heading == landingtype) { |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1741 |
/* save speed before, since if AirportHasBlock is false, it resets them to 0 |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1742 |
* we don't want that for plane in air |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1743 |
* hack for speed thingie */ |
6087 | 1744 |
uint16 tcur_speed = v->cur_speed; |
1745 |
uint16 tsubspeed = v->subspeed; |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1746 |
if (!AirportHasBlock(v, current, apc)) { |
0 | 1747 |
v->u.air.state = landingtype; // LANDING / HELILANDING |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1748 |
/* it's a bit dirty, but I need to set position to next position, otherwise |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1749 |
* if there are multiple runways, plane won't know which one it took (because |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1750 |
* they all have heading LANDING). And also occupy that block! */ |
0 | 1751 |
v->u.air.pos = current->next_position; |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1752 |
SETBITS(st->airport_flags, apc->layout[v->u.air.pos].block); |
0 | 1753 |
return; |
1754 |
} |
|
1755 |
v->cur_speed = tcur_speed; |
|
1756 |
v->subspeed = tsubspeed; |
|
1757 |
} |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1758 |
current = current->next; |
0 | 1759 |
} |
1760 |
} |
|
1761 |
v->u.air.state = FLYING; |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1762 |
v->u.air.pos = apc->layout[v->u.air.pos].next_position; |
0 | 1763 |
} |
1764 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1765 |
static void AircraftEventHandler_Landing(Vehicle *v, const AirportFTAClass *apc) |
0 | 1766 |
{ |
1767 |
AircraftLandAirplane(v); // maybe crash airplane |
|
1768 |
v->u.air.state = ENDLANDING; |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1769 |
/* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */ |
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
|
1770 |
if (v->current_order.type != OT_GOTO_DEPOT && v->owner == _local_player) { |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1771 |
/* only the vehicle owner needs to calculate the rest (locally) */ |
6087 | 1772 |
const Player* p = GetPlayer(v->owner); |
2848 | 1773 |
if (EngineHasReplacementForPlayer(p, v->engine_type) || |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2244
diff
changeset
|
1774 |
(p->engine_renew && v->age - v->max_age > (p->engine_renew_months * 30))) { |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1775 |
/* send the aircraft to the hangar at next airport */ |
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
|
1776 |
_current_player = _local_player; |
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
1777 |
DoCommandP(v->tile, v->index, DEPOT_SERVICE, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR); |
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
|
1778 |
_current_player = OWNER_NONE; |
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
|
1779 |
} |
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
|
1780 |
} |
0 | 1781 |
} |
1782 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1783 |
static void AircraftEventHandler_HeliLanding(Vehicle *v, const AirportFTAClass *apc) |
0 | 1784 |
{ |
1785 |
AircraftLand(v); // helicopters don't crash |
|
1786 |
v->u.air.state = HELIENDLANDING; |
|
1787 |
} |
|
1788 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1789 |
static void AircraftEventHandler_EndLanding(Vehicle *v, const AirportFTAClass *apc) |
0 | 1790 |
{ |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1791 |
/* next block busy, don't do a thing, just wait */ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1792 |
if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return; |
0 | 1793 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1794 |
/* if going to terminal (OT_GOTO_STATION) choose one |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1795 |
* 1. in case all terminals are busy AirportFindFreeTerminal() returns false or |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1796 |
* 2. not going for terminal (but depot, no order), |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1797 |
* --> get out of the way to the hangar. */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1798 |
if (v->current_order.type == OT_GOTO_STATION) { |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1799 |
if (AirportFindFreeTerminal(v, apc)) return; |
0 | 1800 |
} |
1801 |
v->u.air.state = HANGAR; |
|
1802 |
||
1803 |
} |
|
1804 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1805 |
static void AircraftEventHandler_HeliEndLanding(Vehicle *v, const AirportFTAClass *apc) |
0 | 1806 |
{ |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1807 |
/* next block busy, don't do a thing, just wait */ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1808 |
if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return; |
0 | 1809 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1810 |
/* if going to helipad (OT_GOTO_STATION) choose one. If airport doesn't have helipads, choose terminal |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1811 |
* 1. in case all terminals/helipads are busy (AirportFindFreeHelipad() returns false) or |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1812 |
* 2. not going for terminal (but depot, no order), |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1813 |
* --> get out of the way to the hangar IF there are terminals on the airport. |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1814 |
* --> else TAKEOFF |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1815 |
* the reason behind this is that if an airport has a terminal, it also has a hangar. Airplanes |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1816 |
* must go to a hangar. */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1817 |
if (v->current_order.type == OT_GOTO_STATION) { |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1818 |
if (AirportFindFreeHelipad(v, apc)) return; |
0 | 1819 |
} |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1820 |
v->u.air.state = (apc->nof_depots != 0) ? HANGAR : HELITAKEOFF; |
0 | 1821 |
} |
1822 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1823 |
typedef void AircraftStateHandler(Vehicle *v, const AirportFTAClass *apc); |
0 | 1824 |
static AircraftStateHandler * const _aircraft_state_handlers[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1825 |
AircraftEventHandler_General, // TO_ALL = 0 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1826 |
AircraftEventHandler_InHangar, // HANGAR = 1 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1827 |
AircraftEventHandler_AtTerminal, // TERM1 = 2 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1828 |
AircraftEventHandler_AtTerminal, // TERM2 = 3 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1829 |
AircraftEventHandler_AtTerminal, // TERM3 = 4 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1830 |
AircraftEventHandler_AtTerminal, // TERM4 = 5 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1831 |
AircraftEventHandler_AtTerminal, // TERM5 = 6 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1832 |
AircraftEventHandler_AtTerminal, // TERM6 = 7 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1833 |
AircraftEventHandler_AtTerminal, // HELIPAD1 = 8 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1834 |
AircraftEventHandler_AtTerminal, // HELIPAD2 = 9 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1835 |
AircraftEventHandler_TakeOff, // TAKEOFF = 10 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1836 |
AircraftEventHandler_StartTakeOff, // STARTTAKEOFF = 11 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1837 |
AircraftEventHandler_EndTakeOff, // ENDTAKEOFF = 12 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1838 |
AircraftEventHandler_HeliTakeOff, // HELITAKEOFF = 13 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1839 |
AircraftEventHandler_Flying, // FLYING = 14 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1840 |
AircraftEventHandler_Landing, // LANDING = 15 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1841 |
AircraftEventHandler_EndLanding, // ENDLANDING = 16 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1842 |
AircraftEventHandler_HeliLanding, // HELILANDING = 17 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1843 |
AircraftEventHandler_HeliEndLanding, // HELIENDLANDING = 18 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1844 |
AircraftEventHandler_AtTerminal, // TERM7 = 19 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1845 |
AircraftEventHandler_AtTerminal, // TERM8 = 20 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1846 |
AircraftEventHandler_AtTerminal, // HELIPAD3 = 21 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1847 |
AircraftEventHandler_AtTerminal, // HELIPAD4 = 22 |
0 | 1848 |
}; |
1849 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1850 |
static void AirportClearBlock(const Vehicle *v, const AirportFTAClass *apc) |
0 | 1851 |
{ |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1852 |
/* we have left the previous block, and entered the new one. Free the previous block */ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1853 |
if (apc->layout[v->u.air.previous_pos].block != apc->layout[v->u.air.pos].block) { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4338
diff
changeset
|
1854 |
Station *st = GetStation(v->u.air.targetairport); |
2639 | 1855 |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1856 |
CLRBITS(st->airport_flags, apc->layout[v->u.air.previous_pos].block); |
0 | 1857 |
} |
1858 |
} |
|
1859 |
||
6099 | 1860 |
static void AirportGoToNextPosition(Vehicle *v) |
0 | 1861 |
{ |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1862 |
/* if aircraft is not in position, wait until it is */ |
2549 | 1863 |
if (!AircraftController(v)) return; |
0 | 1864 |
|
6099 | 1865 |
const AirportFTAClass *apc = GetStation(v->u.air.targetairport)->Airport(); |
1866 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1867 |
AirportClearBlock(v, apc); |
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1868 |
AirportMove(v, apc); // move aircraft to next position |
0 | 1869 |
} |
1870 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1871 |
/* gets pos from vehicle and next orders */ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1872 |
static bool AirportMove(Vehicle *v, const AirportFTAClass *apc) |
0 | 1873 |
{ |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1874 |
/* error handling */ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1875 |
if (v->u.air.pos >= apc->nofelements) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1876 |
DEBUG(misc, 0, "[Ap] position %d is not valid for current airport. Max position is %d", v->u.air.pos, apc->nofelements-1); |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1877 |
assert(v->u.air.pos < apc->nofelements); |
0 | 1878 |
} |
1879 |
||
6087 | 1880 |
const AirportFTA *current = &apc->layout[v->u.air.pos]; |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1881 |
/* we have arrived in an important state (eg terminal, hangar, etc.) */ |
0 | 1882 |
if (current->heading == v->u.air.state) { |
6087 | 1883 |
byte prev_pos = v->u.air.pos; // location could be changed in state, so save it before-hand |
6490
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
1884 |
byte prev_state = v->u.air.state; |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1885 |
_aircraft_state_handlers[v->u.air.state](v, apc); |
2549 | 1886 |
if (v->u.air.state != FLYING) v->u.air.previous_pos = prev_pos; |
6490
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6453
diff
changeset
|
1887 |
if (v->u.air.state != prev_state) UpdateAircraftCache(v); |
0 | 1888 |
return true; |
1889 |
} |
|
1890 |
||
1891 |
v->u.air.previous_pos = v->u.air.pos; // save previous location |
|
1892 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1893 |
/* there is only one choice to move to */ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1894 |
if (current->next == NULL) { |
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1895 |
if (AirportSetBlocks(v, current, apc)) { |
0 | 1896 |
v->u.air.pos = current->next_position; |
1897 |
} // move to next position |
|
3579
4a55e8ce3087
(svn r4465) -Codechange (FS#60): Remove a variable no one really needs. (DaleStan)
celestar
parents:
3491
diff
changeset
|
1898 |
return false; |
0 | 1899 |
} |
1900 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1901 |
/* there are more choices to choose from, choose the one that |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1902 |
* matches our heading */ |
0 | 1903 |
do { |
1904 |
if (v->u.air.state == current->heading || current->heading == TO_ALL) { |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1905 |
if (AirportSetBlocks(v, current, apc)) { |
2639 | 1906 |
v->u.air.pos = current->next_position; |
1907 |
} // move to next position |
|
3579
4a55e8ce3087
(svn r4465) -Codechange (FS#60): Remove a variable no one really needs. (DaleStan)
celestar
parents:
3491
diff
changeset
|
1908 |
return false; |
0 | 1909 |
} |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1910 |
current = current->next; |
0 | 1911 |
} while (current != NULL); |
1912 |
||
6036
333637e97400
(svn r8759) -Feature: Allow airports to have up to 4 entry points depending on approach direction. Note: they're not yet used, but will be soon
celestar
parents:
6032
diff
changeset
|
1913 |
DEBUG(misc, 0, "[Ap] cannot move further on Airport! (pos %d state %d) for vehicle %d", v->u.air.pos, v->u.air.state, v->index); |
0 | 1914 |
assert(0); |
1915 |
return false; |
|
1916 |
} |
|
1917 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1918 |
/* returns true if the road ahead is busy, eg. you must wait before proceeding */ |
4843
4bef85baee3f
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
1919 |
static bool AirportHasBlock(Vehicle *v, const AirportFTA *current_pos, const AirportFTAClass *apc) |
0 | 1920 |
{ |
4843
4bef85baee3f
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
1921 |
const AirportFTA *reference = &apc->layout[v->u.air.pos]; |
4bef85baee3f
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
1922 |
const AirportFTA *next = &apc->layout[current_pos->next_position]; |
0 | 1923 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1924 |
/* same block, then of course we can move */ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1925 |
if (apc->layout[current_pos->position].block != next->block) { |
4843
4bef85baee3f
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
1926 |
const Station *st = GetStation(v->u.air.targetairport); |
6011
04cd7c7f1d64
(svn r8733) -Fix(r8705): Forgot to change some more places where airport blocks are stored
celestar
parents:
5996
diff
changeset
|
1927 |
uint64 airport_flags = next->block; |
2630 | 1928 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1929 |
/* check additional possible extra blocks */ |
0 | 1930 |
if (current_pos != reference && current_pos->block != NOTHING_block) { |
1931 |
airport_flags |= current_pos->block; |
|
1932 |
} |
|
1933 |
||
1934 |
if (HASBITS(st->airport_flags, airport_flags)) { |
|
1935 |
v->cur_speed = 0; |
|
1936 |
v->subspeed = 0; |
|
1937 |
return true; |
|
1938 |
} |
|
1939 |
} |
|
1940 |
return false; |
|
1941 |
} |
|
1942 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1943 |
/** |
6409
2dc181151153
(svn r9545) -Documentation: Some corrections to previous doxygen work
belugas
parents:
6407
diff
changeset
|
1944 |
* "reserve" a block for the plane |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1945 |
* @param v airplane that requires the operation |
6409
2dc181151153
(svn r9545) -Documentation: Some corrections to previous doxygen work
belugas
parents:
6407
diff
changeset
|
1946 |
* @param current_pos of the vehicle in the list of blocks |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1947 |
* @param apc airport on which block is requsted to be set |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1948 |
* @returns true on success. Eg, next block was free and we have occupied it |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1949 |
*/ |
6087 | 1950 |
static bool AirportSetBlocks(Vehicle *v, const AirportFTA *current_pos, const AirportFTAClass *apc) |
0 | 1951 |
{ |
6087 | 1952 |
const AirportFTA *next = &apc->layout[current_pos->next_position]; |
1953 |
const AirportFTA *reference = &apc->layout[v->u.air.pos]; |
|
0 | 1954 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1955 |
/* if the next position is in another block, check it and wait until it is free */ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1956 |
if ((apc->layout[current_pos->position].block & next->block) != next->block) { |
6011
04cd7c7f1d64
(svn r8733) -Fix(r8705): Forgot to change some more places where airport blocks are stored
celestar
parents:
5996
diff
changeset
|
1957 |
uint64 airport_flags = next->block; |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1958 |
/* search for all all elements in the list with the same state, and blocks != N |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1959 |
* this means more blocks should be checked/set */ |
6087 | 1960 |
const AirportFTA *current = current_pos; |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1961 |
if (current == reference) current = current->next; |
0 | 1962 |
while (current != NULL) { |
1963 |
if (current->heading == current_pos->heading && current->block != 0) { |
|
1964 |
airport_flags |= current->block; |
|
1965 |
break; |
|
1966 |
} |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1967 |
current = current->next; |
0 | 1968 |
}; |
1969 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1970 |
/* if the block to be checked is in the next position, then exclude that from |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1971 |
* checking, because it has been set by the airplane before */ |
2549 | 1972 |
if (current_pos->block == next->block) airport_flags ^= next->block; |
0 | 1973 |
|
6087 | 1974 |
Station* st = GetStation(v->u.air.targetairport); |
0 | 1975 |
if (HASBITS(st->airport_flags, airport_flags)) { |
1976 |
v->cur_speed = 0; |
|
1977 |
v->subspeed = 0; |
|
1978 |
return false; |
|
1979 |
} |
|
1980 |
||
1981 |
if (next->block != NOTHING_block) { |
|
1982 |
SETBITS(st->airport_flags, airport_flags); // occupy next block |
|
1983 |
} |
|
1984 |
} |
|
1985 |
return true; |
|
1986 |
} |
|
1987 |
||
1988 |
static bool FreeTerminal(Vehicle *v, byte i, byte last_terminal) |
|
1989 |
{ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1990 |
Station *st = GetStation(v->u.air.targetairport); |
0 | 1991 |
for (; i < last_terminal; i++) { |
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4056
diff
changeset
|
1992 |
if (!HASBIT(st->airport_flags, _airport_terminal_flag[i])) { |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
1993 |
/* TERMINAL# HELIPAD# */ |
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4056
diff
changeset
|
1994 |
v->u.air.state = _airport_terminal_state[i]; // start moving to that terminal/helipad |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4056
diff
changeset
|
1995 |
SETBIT(st->airport_flags, _airport_terminal_flag[i]); // occupy terminal/helipad |
0 | 1996 |
return true; |
1997 |
} |
|
1998 |
} |
|
1999 |
return false; |
|
2000 |
} |
|
2001 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
2002 |
static uint GetNumTerminals(const AirportFTAClass *apc) |
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2003 |
{ |
2639 | 2004 |
uint num = 0; |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
2005 |
|
6087 | 2006 |
for (uint i = apc->terminals[0]; i > 0; i--) num += apc->terminals[i]; |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
2007 |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2008 |
return num; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2009 |
} |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2010 |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
2011 |
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *apc) |
0 | 2012 |
{ |
2013 |
/* example of more terminalgroups |
|
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4546
diff
changeset
|
2014 |
* {0,HANGAR,NOTHING_block,1}, {0,255,TERM_GROUP1_block,0}, {0,255,TERM_GROUP2_ENTER_block,1}, {0,0,N,1}, |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4546
diff
changeset
|
2015 |
* Heading 255 denotes a group. We see 2 groups here: |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4546
diff
changeset
|
2016 |
* 1. group 0 -- TERM_GROUP1_block (check block) |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4546
diff
changeset
|
2017 |
* 2. group 1 -- TERM_GROUP2_ENTER_block (check block) |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4546
diff
changeset
|
2018 |
* First in line is checked first, group 0. If the block (TERM_GROUP1_block) is free, it |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4546
diff
changeset
|
2019 |
* looks at the corresponding terminals of that group. If no free ones are found, other |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4546
diff
changeset
|
2020 |
* possible groups are checked (in this case group 1, since that is after group 0). If that |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4546
diff
changeset
|
2021 |
* fails, then attempt fails and plane waits |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4546
diff
changeset
|
2022 |
*/ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
2023 |
if (apc->terminals[0] > 1) { |
6087 | 2024 |
const Station *st = GetStation(v->u.air.targetairport); |
2025 |
const AirportFTA *temp = apc->layout[v->u.air.pos].next; |
|
4843
4bef85baee3f
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
2026 |
|
0 | 2027 |
while (temp != NULL) { |
2028 |
if (temp->heading == 255) { |
|
2029 |
if (!HASBITS(st->airport_flags, temp->block)) { |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2030 |
/* read which group do we want to go to? |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2031 |
* (the first free group) */ |
6087 | 2032 |
uint target_group = temp->next_position + 1; |
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2033 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2034 |
/* at what terminal does the group start? |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2035 |
* that means, sum up all terminals of |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2036 |
* groups with lower number */ |
6087 | 2037 |
uint group_start = 0; |
2038 |
for (uint i = 1; i < target_group; i++) { |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
2039 |
group_start += apc->terminals[i]; |
6087 | 2040 |
} |
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2041 |
|
6087 | 2042 |
uint group_end = group_start + apc->terminals[target_group]; |
2549 | 2043 |
if (FreeTerminal(v, group_start, group_end)) return true; |
0 | 2044 |
} |
2549 | 2045 |
} else { |
2046 |
/* once the heading isn't 255, we've exhausted the possible blocks. |
|
2047 |
* So we cannot move */ |
|
2048 |
return false; |
|
0 | 2049 |
} |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
2050 |
temp = temp->next; |
0 | 2051 |
} |
2052 |
} |
|
2053 |
||
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2054 |
/* if there is only 1 terminalgroup, all terminals are checked (starting from 0 to max) */ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
2055 |
return FreeTerminal(v, 0, GetNumTerminals(apc)); |
0 | 2056 |
} |
2057 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
2058 |
static uint GetNumHelipads(const AirportFTAClass *apc) |
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2059 |
{ |
2639 | 2060 |
uint num = 0; |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
2061 |
|
6087 | 2062 |
for (uint i = apc->helipads[0]; i > 0; i--) num += apc->helipads[i]; |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
2063 |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2064 |
return num; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2065 |
} |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2066 |
|
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2067 |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
2068 |
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *apc) |
0 | 2069 |
{ |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2070 |
/* if an airport doesn't have helipads, use terminals */ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
2071 |
if (apc->helipads == NULL) return AirportFindFreeTerminal(v, apc); |
0 | 2072 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2073 |
/* if there are more helicoptergroups, pick one, just as in AirportFindFreeTerminal() */ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
2074 |
if (apc->helipads[0] > 1) { |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4072
diff
changeset
|
2075 |
const Station* st = GetStation(v->u.air.targetairport); |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
2076 |
const AirportFTA* temp = apc->layout[v->u.air.pos].next; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4072
diff
changeset
|
2077 |
|
0 | 2078 |
while (temp != NULL) { |
2079 |
if (temp->heading == 255) { |
|
2080 |
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
|
2081 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2082 |
/* read which group do we want to go to? |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2083 |
* (the first free group) */ |
6087 | 2084 |
uint target_group = temp->next_position + 1; |
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2085 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2086 |
/* at what terminal does the group start? |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2087 |
* that means, sum up all terminals of |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2088 |
* groups with lower number */ |
6087 | 2089 |
uint group_start = 0; |
2090 |
for (uint i = 1; i < target_group; i++) { |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
2091 |
group_start += apc->helipads[i]; |
6087 | 2092 |
} |
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2093 |
|
6087 | 2094 |
uint group_end = group_start + apc->helipads[target_group]; |
2549 | 2095 |
if (FreeTerminal(v, group_start, group_end)) return true; |
0 | 2096 |
} |
2549 | 2097 |
} else { |
2098 |
/* once the heading isn't 255, we've exhausted the possible blocks. |
|
2099 |
* So we cannot move */ |
|
2100 |
return false; |
|
0 | 2101 |
} |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
2102 |
temp = temp->next; |
0 | 2103 |
} |
2549 | 2104 |
} else { |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2105 |
/* only 1 helicoptergroup, check all helipads |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2106 |
* The blocks for helipads start after the last terminal (MAX_TERMINALS) */ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
2107 |
return FreeTerminal(v, MAX_TERMINALS, GetNumHelipads(apc) + MAX_TERMINALS); |
0 | 2108 |
} |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4412
diff
changeset
|
2109 |
return false; // it shouldn't get here anytime, but just to be sure |
0 | 2110 |
} |
2111 |
||
2112 |
static void AircraftEventHandler(Vehicle *v, int loop) |
|
2113 |
{ |
|
2114 |
v->tick_counter++; |
|
2115 |
||
2116 |
if (v->vehstatus & VS_CRASHED) { |
|
2117 |
HandleCrashedAircraft(v); |
|
2118 |
return; |
|
2119 |
} |
|
2120 |
||
2639 | 2121 |
if (v->vehstatus & VS_STOPPED) return; |
0 | 2122 |
|
2123 |
/* aircraft is broken down? */ |
|
2124 |
if (v->breakdown_ctr != 0) { |
|
2125 |
if (v->breakdown_ctr <= 2) { |
|
2126 |
HandleBrokenAircraft(v); |
|
2127 |
} else { |
|
2128 |
v->breakdown_ctr--; |
|
2129 |
} |
|
2130 |
} |
|
2131 |
||
2132 |
HandleAircraftSmoke(v); |
|
2133 |
ProcessAircraftOrder(v); |
|
2134 |
HandleAircraftLoading(v, loop); |
|
2135 |
||
2639 | 2136 |
if (v->current_order.type >= OT_LOADING) return; |
0 | 2137 |
|
6099 | 2138 |
AirportGoToNextPosition(v); |
0 | 2139 |
} |
2140 |
||
2141 |
void Aircraft_Tick(Vehicle *v) |
|
2142 |
{ |
|
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
2143 |
if (!IsNormalAircraft(v)) return; |
0 | 2144 |
|
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
2145 |
if (v->subtype == AIR_HELICOPTER) HelicopterTickHandler(v); |
0 | 2146 |
|
2147 |
AgeAircraftCargo(v); |
|
2148 |
||
6193
6f20de9e4f1b
(svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents:
6176
diff
changeset
|
2149 |
for (uint i = 0; i != 2; i++) { |
0 | 2150 |
AircraftEventHandler(v, i); |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
2151 |
if (v->type != VEH_AIRCRAFT) // In case it was deleted |
0 | 2152 |
break; |
2153 |
} |
|
2154 |
} |
|
2155 |
||
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2156 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2157 |
/** need to be called to load aircraft from old version */ |
6247 | 2158 |
void UpdateOldAircraft() |
0 | 2159 |
{ |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2160 |
/* set airport_flags to 0 for all airports just to be sure */ |
0 | 2161 |
Station *st; |
2162 |
FOR_ALL_STATIONS(st) { |
|
2163 |
st->airport_flags = 0; // reset airport |
|
2164 |
} |
|
2165 |
||
6087 | 2166 |
Vehicle *v_oldstyle; |
0 | 2167 |
FOR_ALL_VEHICLES(v_oldstyle) { |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2168 |
/* airplane has another vehicle with subtype 4 (shadow), helicopter also has 3 (rotor) |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2169 |
* skip those */ |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
2170 |
if (v_oldstyle->type == VEH_AIRCRAFT && IsNormalAircraft(v_oldstyle)) { |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2171 |
/* airplane in terminal stopped doesn't hurt anyone, so goto next */ |
2639 | 2172 |
if (v_oldstyle->vehstatus & VS_STOPPED && v_oldstyle->u.air.state == 0) { |
0 | 2173 |
v_oldstyle->u.air.state = HANGAR; |
2174 |
continue; |
|
2175 |
} |
|
2176 |
||
2177 |
AircraftLeaveHangar(v_oldstyle); // make airplane visible if it was in a depot for example |
|
2178 |
v_oldstyle->vehstatus &= ~VS_STOPPED; // make airplane moving |
|
2179 |
v_oldstyle->u.air.state = FLYING; |
|
2180 |
AircraftNextAirportPos_and_Order(v_oldstyle); // move it to the entry point of the airport |
|
6153 | 2181 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v_oldstyle); |
0 | 2182 |
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
|
2183 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2184 |
/* correct speed of helicopter-rotors */ |
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5754
diff
changeset
|
2185 |
if (v_oldstyle->subtype == AIR_HELICOPTER) v_oldstyle->next->next->cur_speed = 32; |
0 | 2186 |
|
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2187 |
/* set new position x,y,z */ |
0 | 2188 |
SetAircraftPosition(v_oldstyle, gp.x, gp.y, GetAircraftFlyingAltitude(v_oldstyle)); |
2189 |
} |
|
2190 |
} |
|
2191 |
} |
|
2192 |
||
6415
cb61e1346600
(svn r9551) -Documentation: Some more doxygen work
belugas
parents:
6409
diff
changeset
|
2193 |
/** |
cb61e1346600
(svn r9551) -Documentation: Some more doxygen work
belugas
parents:
6409
diff
changeset
|
2194 |
* Updates the status of the Aircraft heading or in the station |
cb61e1346600
(svn r9551) -Documentation: Some more doxygen work
belugas
parents:
6409
diff
changeset
|
2195 |
* @param st Station been updated |
cb61e1346600
(svn r9551) -Documentation: Some more doxygen work
belugas
parents:
6409
diff
changeset
|
2196 |
*/ |
6087 | 2197 |
void UpdateAirplanesOnNewStation(const Station *st) |
0 | 2198 |
{ |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2199 |
/* only 1 station is updated per function call, so it is enough to get entry_point once */ |
6032 | 2200 |
const AirportFTAClass *ap = st->Airport(); |
6087 | 2201 |
|
2202 |
Vehicle *v; |
|
0 | 2203 |
FOR_ALL_VEHICLES(v) { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
2204 |
if (v->type == VEH_AIRCRAFT && IsNormalAircraft(v)) { |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4412
diff
changeset
|
2205 |
if (v->u.air.targetairport == st->index) { // if heading to this airport |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4412
diff
changeset
|
2206 |
/* update position of airplane. If plane is not flying, landing, or taking off |
6415
cb61e1346600
(svn r9551) -Documentation: Some more doxygen work
belugas
parents:
6409
diff
changeset
|
2207 |
* you cannot delete airport, so it doesn't matter */ |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4412
diff
changeset
|
2208 |
if (v->u.air.state >= FLYING) { // circle around |
6036
333637e97400
(svn r8759) -Feature: Allow airports to have up to 4 entry points depending on approach direction. Note: they're not yet used, but will be soon
celestar
parents:
6032
diff
changeset
|
2209 |
v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, ap); |
0 | 2210 |
v->u.air.state = FLYING; |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2211 |
/* landing plane needs to be reset to flying height (only if in pause mode upgrade, |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2212 |
* in normal mode, plane is reset in AircraftController. It doesn't hurt for FLYING */ |
6153 | 2213 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2214 |
/* set new position x,y,z */ |
0 | 2215 |
SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v)); |
2549 | 2216 |
} else { |
0 | 2217 |
assert(v->u.air.state == ENDTAKEOFF || v->u.air.state == HELITAKEOFF); |
6087 | 2218 |
byte takeofftype = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : ENDTAKEOFF; |
6123
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2219 |
/* search in airportdata for that heading |
04eb770ec17e
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6117
diff
changeset
|
2220 |
* easiest to do, since this doesn't happen a lot */ |
6087 | 2221 |
for (uint cnt = 0; cnt < ap->nofelements; cnt++) { |
0 | 2222 |
if (ap->layout[cnt].heading == takeofftype) { |
2223 |
v->u.air.pos = ap->layout[cnt].position; |
|
2224 |
break; |
|
2225 |
} |
|
2226 |
} |
|
2227 |
} |
|
2228 |
} |
|
2229 |
} |
|
2230 |
} |
|
2231 |
} |