author | rubidium |
Thu, 01 Feb 2007 15:49:12 +0000 | |
changeset 5893 | 7e431a4abebb |
parent 5886 | 10263c6c4026 |
child 5908 | 5ff4fe308285 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1877
diff
changeset
|
4 |
#include "openttd.h" |
3963
6cab57074a9a
(svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
3955
diff
changeset
|
5 |
#include "aircraft.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1282
diff
changeset
|
6 |
#include "debug.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2140
diff
changeset
|
7 |
#include "functions.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
|
8 |
#include "station_map.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
458
diff
changeset
|
9 |
#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
|
10 |
#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
|
11 |
#include "tile.h" |
0 | 12 |
#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
|
13 |
#include "depot.h" |
0 | 14 |
#include "engine.h" |
15 |
#include "command.h" |
|
16 |
#include "station.h" |
|
17 |
#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
|
18 |
#include "sound.h" |
0 | 19 |
#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
|
20 |
#include "aircraft.h" |
0 | 21 |
#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
|
22 |
#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
|
23 |
#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
|
24 |
#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
|
25 |
#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
|
26 |
#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
|
27 |
#include "newgrf_sound.h" |
4261
28670f743746
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4259
diff
changeset
|
28 |
#include "date.h" |
0 | 29 |
|
5754
086187883012
(svn r8305) -Codechange: defining 'static const' in a header is a bit weird.
truelight
parents:
5668
diff
changeset
|
30 |
// this maps the terminal to its corresponding state and block flag |
086187883012
(svn r8305) -Codechange: defining 'static const' in a header is a bit weird.
truelight
parents:
5668
diff
changeset
|
31 |
// currently set for 10 terms, 4 helipads |
086187883012
(svn r8305) -Codechange: defining 'static const' in a header is a bit weird.
truelight
parents:
5668
diff
changeset
|
32 |
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
|
33 |
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
|
34 |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
35 |
static bool AirportMove(Vehicle *v, const AirportFTAClass *apc); |
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
36 |
static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *apc); |
4843
4bef85baee3f
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
37 |
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
|
38 |
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
|
39 |
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *apc); |
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
40 |
static void AirportGoToNextPosition(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
|
41 |
static void CrashAirplane(Vehicle *v); |
0 | 42 |
|
43 |
static void AircraftNextAirportPos_and_Order(Vehicle *v); |
|
44 |
static byte GetAircraftFlyingAltitude(const Vehicle *v); |
|
45 |
||
46 |
static const SpriteID _aircraft_sprite[] = { |
|
47 |
0x0EB5, 0x0EBD, 0x0EC5, 0x0ECD, |
|
48 |
0x0ED5, 0x0EDD, 0x0E9D, 0x0EA5, |
|
49 |
0x0EAD, 0x0EE5, 0x0F05, 0x0F0D, |
|
50 |
0x0F15, 0x0F1D, 0x0F25, 0x0F2D, |
|
51 |
0x0EED, 0x0EF5, 0x0EFD, 0x0F35, |
|
52 |
0x0E9D, 0x0EA5, 0x0EAD, 0x0EB5, |
|
53 |
0x0EBD, 0x0EC5 |
|
54 |
}; |
|
55 |
||
3710
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
56 |
/* Helicopter rotor animation states */ |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
}; |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
63 |
|
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
|
64 |
/* Find the nearest hangar to v |
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
|
65 |
* 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
|
66 |
* airports (like helipads only) |
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
|
67 |
*/ |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
68 |
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
|
69 |
{ |
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 |
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
|
71 |
uint best = 0; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
72 |
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
|
73 |
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
|
74 |
|
2b25b1477623
(svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents:
1151
diff
changeset
|
75 |
FOR_ALL_STATIONS(st) { |
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
|
76 |
if (st->owner == v->owner && st->facilities & FACIL_AIRPORT && |
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 |
GetAirport(st->airport_type)->nof_depots > 0) { |
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 distance; |
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
|
79 |
|
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
|
80 |
// don't crash the plane if we know it can't land at the airport |
4284
ea9579c54725
(svn r5914) -Fix [FS#235]: Bugfix for errors in FindNearestHangar function in aircraft_cmd.c (mart3p).
Darkvater
parents:
4261
diff
changeset
|
81 |
if ((AircraftVehInfo(v->engine_type)->subtype & AIR_FAST) && |
ea9579c54725
(svn r5914) -Fix [FS#235]: Bugfix for errors in FindNearestHangar function in aircraft_cmd.c (mart3p).
Darkvater
parents:
4261
diff
changeset
|
82 |
(st->airport_type == AT_SMALL || st->airport_type == AT_COMMUTER) && |
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
|
83 |
!_cheats.no_jetcrash.value) |
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
|
84 |
continue; |
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
|
85 |
|
4284
ea9579c54725
(svn r5914) -Fix [FS#235]: Bugfix for errors in FindNearestHangar function in aircraft_cmd.c (mart3p).
Darkvater
parents:
4261
diff
changeset
|
86 |
// v->tile can't be used here, when aircraft is flying v->tile is set to 0 |
ea9579c54725
(svn r5914) -Fix [FS#235]: Bugfix for errors in FindNearestHangar function in aircraft_cmd.c (mart3p).
Darkvater
parents:
4261
diff
changeset
|
87 |
distance = DistanceSquare(vtile, st->airport_tile); |
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
|
88 |
if (distance < best || index == INVALID_STATION) { |
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
|
89 |
best = distance; |
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
|
90 |
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
|
91 |
} |
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
|
92 |
} |
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
|
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 |
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
|
95 |
} |
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
|
96 |
|
1614
f6f2c918356d
(svn r2118) - Fix: Fix compilation with network disabled, and comment out some of the warnings (unused function)
Darkvater
parents:
1533
diff
changeset
|
97 |
#if 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
|
98 |
// returns true if vehicle v have an airport in the schedule, that has a hangar |
2b25b1477623
(svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents:
1151
diff
changeset
|
99 |
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
|
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 |
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
|
102 |
|
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 |
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
|
104 |
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
|
105 |
if (st->owner == v->owner && st->facilities & FACIL_AIRPORT) { |
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4056
diff
changeset
|
106 |
// If an airport doesn't have a hangar, skip it |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4056
diff
changeset
|
107 |
if (GetAirport(st->airport_type)->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
|
108 |
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
|
109 |
} |
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 |
|
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 |
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
|
113 |
} |
1614
f6f2c918356d
(svn r2118) - Fix: Fix compilation with network disabled, and comment out some of the warnings (unused function)
Darkvater
parents:
1533
diff
changeset
|
114 |
#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
|
115 |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3140
diff
changeset
|
116 |
int GetAircraftImage(const Vehicle* v, Direction direction) |
0 | 117 |
{ |
118 |
int spritenum = v->spritenum; |
|
119 |
||
120 |
if (is_custom_sprite(spritenum)) { |
|
121 |
int sprite = GetCustomVehicleSprite(v, direction); |
|
122 |
||
2989 | 123 |
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
|
124 |
spritenum = orig_aircraft_vehicle_info[v->engine_type - AIRCRAFT_ENGINES_INDEX].image_index; |
0 | 125 |
} |
126 |
return direction + _aircraft_sprite[spritenum]; |
|
127 |
} |
|
128 |
||
3710
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
129 |
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
|
130 |
{ |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
131 |
const Vehicle *w; |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
132 |
|
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
|
133 |
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
|
134 |
|
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
135 |
w = v->next->next; |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
} |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
140 |
|
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
141 |
/* 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
|
142 |
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
|
143 |
} |
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
144 |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5651
diff
changeset
|
145 |
void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal) |
0 | 146 |
{ |
4023
5d84c056a2b1
(svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
tron
parents:
3988
diff
changeset
|
147 |
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
|
148 |
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
|
149 |
SpriteID sprite = (6 + _aircraft_sprite[spritenum]); |
0 | 150 |
|
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
|
151 |
if (is_custom_sprite(spritenum)) { |
3186
4317b5b295c4
(svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents:
3183
diff
changeset
|
152 |
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
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
} |
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
|
157 |
} |
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
|
158 |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5651
diff
changeset
|
159 |
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
|
160 |
|
4023
5d84c056a2b1
(svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
tron
parents:
3988
diff
changeset
|
161 |
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
|
162 |
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
|
163 |
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
|
164 |
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
|
165 |
} |
0 | 166 |
} |
167 |
||
2752 | 168 |
static int32 EstimateAircraftCost(EngineID engine_type) |
0 | 169 |
{ |
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
170 |
return AircraftVehInfo(engine_type)->base_cost * (_price.aircraft_base>>3)>>5; |
0 | 171 |
} |
172 |
||
173 |
||
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
|
174 |
/** |
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
|
175 |
* 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
|
176 |
* 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
|
177 |
* @param cid Which cargo type to calculate a capacity for. |
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
|
178 |
* @param engine Which engine to find a cargo capacity for. |
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
|
179 |
* @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
|
180 |
*/ |
3987
22972f38e240
(svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents:
3974
diff
changeset
|
181 |
uint16 AircraftDefaultCargoCapacity(CargoID cid, EngineID engine_type) |
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
|
182 |
{ |
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
|
183 |
const AircraftVehicleInfo *avi = AircraftVehInfo(engine_type); |
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
|
184 |
|
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
|
185 |
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
|
186 |
|
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
|
187 |
/* 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
|
188 |
* 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
|
189 |
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
|
190 |
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
|
191 |
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
|
192 |
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
|
193 |
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
|
194 |
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
|
195 |
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
|
196 |
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
|
197 |
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
|
198 |
} |
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
|
199 |
} |
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
|
200 |
|
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
|
201 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
202 |
/** 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
|
203 |
* @param tile tile of depot where aircraft is built |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
204 |
* @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
|
205 |
* @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
206 |
*/ |
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
|
207 |
int32 CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 208 |
{ |
209 |
int32 value; |
|
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
|
210 |
Vehicle *vl[3]; |
1282
ea2ae881814c
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1266
diff
changeset
|
211 |
UnitID unit_num; |
1877
ab6a315fa930
(svn r2383) - Fix: Monkey-testing turned up some command crashes.
Darkvater
parents:
1874
diff
changeset
|
212 |
const AircraftVehicleInfo *avi; |
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
|
213 |
const AirportFTAClass* ap; |
0 | 214 |
|
5215
b8fb685df4c5
(svn r7330) -Fix (r7304): Data invalidation doesn't always happen as the local
peter1138
parents:
5211
diff
changeset
|
215 |
if (!IsEngineBuildable(p1, VEH_Aircraft, _current_player)) return_cmd_error(STR_ENGINE_NOT_BUILDABLE); |
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
|
216 |
|
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
|
217 |
value = EstimateAircraftCost(p1); |
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
|
218 |
|
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
|
219 |
// to just query the cost, it is not neccessary to have a valid tile (automation/AI) |
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
|
220 |
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
|
221 |
|
3338
7cff208f0446
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
222 |
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
|
223 |
|
0 | 224 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
225 |
||
1877
ab6a315fa930
(svn r2383) - Fix: Monkey-testing turned up some command crashes.
Darkvater
parents:
1874
diff
changeset
|
226 |
avi = AircraftVehInfo(p1); |
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
|
227 |
|
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
|
228 |
// Prevent building aircraft types at places which can't handle them |
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
|
229 |
ap = GetAirport(GetStationByTile(tile)->airport_type); |
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
|
230 |
if ((avi->subtype & AIR_CTOL ? HELICOPTERS_ONLY : AIRCRAFT_ONLY) == ap->acc_planes) { |
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
|
231 |
return CMD_ERROR; |
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
|
232 |
} |
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
|
233 |
|
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
|
234 |
/* 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
|
235 |
* vl[0] = aircraft, vl[1] = shadow, [vl[2] = rotor] */ |
4023
5d84c056a2b1
(svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
tron
parents:
3988
diff
changeset
|
236 |
if (!AllocateVehicles(vl, avi->subtype & AIR_CTOL ? 2 : 3) || |
2639 | 237 |
IsOrderPoolFull()) { |
238 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
|
239 |
} |
|
0 | 240 |
|
4095
ad7a6bc2bf80
(svn r5427) - Codechange: testing for "== true" is redundant.
peter1138
parents:
4077
diff
changeset
|
241 |
unit_num = HASBIT(p2, 0) ? 0 : GetFreeUnitNumber(VEH_Aircraft); |
0 | 242 |
if (unit_num > _patches.max_aircraft) |
243 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
|
244 |
||
245 |
if (flags & DC_EXEC) { |
|
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
|
246 |
CargoID cargo; |
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
|
247 |
uint x; |
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
|
248 |
uint y; |
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
|
249 |
|
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
|
250 |
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
|
251 |
Vehicle *u = vl[1]; // shadow |
0 | 252 |
|
253 |
v->unitnumber = unit_num; |
|
254 |
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
|
255 |
v->direction = DIR_SE; |
0 | 256 |
|
257 |
v->owner = u->owner = _current_player; |
|
258 |
||
259 |
v->tile = tile; |
|
260 |
// u->tile = 0; |
|
261 |
||
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
262 |
x = TileX(tile) * TILE_SIZE + 5; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
263 |
y = TileY(tile) * TILE_SIZE + 3; |
0 | 264 |
|
265 |
v->x_pos = u->x_pos = x; |
|
266 |
v->y_pos = u->y_pos = y; |
|
267 |
||
268 |
u->z_pos = GetSlopeZ(x, y); |
|
269 |
v->z_pos = u->z_pos + 1; |
|
270 |
||
271 |
v->x_offs = v->y_offs = -1; |
|
272 |
// u->delta_x = u->delta_y = 0; |
|
273 |
||
274 |
v->sprite_width = v->sprite_height = 2; |
|
275 |
v->z_height = 5; |
|
276 |
||
277 |
u->sprite_width = u->sprite_height = 2; |
|
278 |
u->z_height = 1; |
|
279 |
||
280 |
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
|
281 |
u->vehstatus = VS_HIDDEN | VS_UNCLICKABLE | VS_SHADOW; |
0 | 282 |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
283 |
v->spritenum = avi->image_index; |
0 | 284 |
// v->cargo_count = u->number_of_pieces = 0; |
285 |
||
922
10035216cbaf
(svn r1410) Replaced all occurences of 'passanger' by 'passenger' in the code
celestar
parents:
919
diff
changeset
|
286 |
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
|
287 |
u->cargo_cap = avi->mail_capacity; |
0 | 288 |
|
289 |
v->cargo_type = CT_PASSENGERS; |
|
290 |
u->cargo_type = CT_MAIL; |
|
291 |
||
3870
d9ebc4ea750a
(svn r4910) - NewGRF: add and initialize cargo subtype for vehicle visual variations
peter1138
parents:
3816
diff
changeset
|
292 |
v->cargo_subtype = 0; |
d9ebc4ea750a
(svn r4910) - NewGRF: add and initialize cargo subtype for vehicle visual variations
peter1138
parents:
3816
diff
changeset
|
293 |
|
0 | 294 |
v->string_id = STR_SV_AIRCRAFT_NAME; |
295 |
// v->next_order_param = v->next_order = 0; |
|
296 |
||
297 |
// v->load_unload_time_rem = 0; |
|
298 |
// v->progress = 0; |
|
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1263
diff
changeset
|
299 |
v->last_station_visited = INVALID_STATION; |
0 | 300 |
// v->destination_coords = 0; |
301 |
||
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
302 |
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
|
303 |
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
|
304 |
v->engine_type = p1; |
0 | 305 |
|
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
|
306 |
v->subtype = (avi->subtype & AIR_CTOL ? AIR_AIRCRAFT : AIR_HELICOPTER); |
0 | 307 |
v->value = value; |
308 |
||
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
|
309 |
u->subtype = AIR_SHADOW; |
0 | 310 |
|
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
|
311 |
/* 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
|
312 |
* 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
|
313 |
* 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
|
314 |
* 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
|
315 |
* has no default cargo type specifier for planes... */ |
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
|
316 |
cargo = FindFirstRefittableCargo(p1); |
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
|
317 |
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
|
318 |
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
|
319 |
|
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
|
320 |
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
|
321 |
|
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
|
322 |
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
|
323 |
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
|
324 |
} |
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
|
325 |
|
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
|
326 |
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
|
327 |
/* Callback failed, or not executed; use the default cargo 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
|
328 |
v->cargo_cap = AircraftDefaultCargoCapacity(v->cargo_type, v->engine_type); |
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 |
} 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
|
330 |
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
|
331 |
} |
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 |
|
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 |
/* 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
|
334 |
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
|
335 |
} |
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 |
|
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
|
337 |
const Engine *e = GetEngine(p1); |
0 | 338 |
v->reliability = e->reliability; |
339 |
v->reliability_spd_dec = e->reliability_spd_dec; |
|
340 |
v->max_age = e->lifelength * 366; |
|
341 |
||
2564 | 342 |
_new_vehicle_id = v->index; |
0 | 343 |
|
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
|
344 |
v->u.air.pos = MAX_ELEMENTS; |
0 | 345 |
|
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
|
346 |
/* 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
|
347 |
* 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
|
348 |
* 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
|
349 |
* of all depots, it is simple */ |
0 | 350 |
{ |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3186
diff
changeset
|
351 |
const Station* st = GetStationByTile(tile); |
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
|
352 |
const AirportFTAClass* apc = GetAirport(st->airport_type); |
1533
613a5f81ad79
(svn r2037) uint -> TileIndex, remove pointless casts, const, misc.
tron
parents:
1532
diff
changeset
|
353 |
uint i; |
613a5f81ad79
(svn r2037) uint -> TileIndex, remove pointless casts, const, misc.
tron
parents:
1532
diff
changeset
|
354 |
|
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
|
355 |
for (i = 0; i < apc->nof_depots; i++) { |
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
|
356 |
if (st->airport_tile + ToTileIndexDiff(apc->airport_depots[i]) == tile) { |
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
|
357 |
assert(apc->layout[i].heading == HANGAR); |
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
|
358 |
v->u.air.pos = apc->layout[i].position; |
0 | 359 |
break; |
360 |
} |
|
361 |
} |
|
362 |
// to ensure v->u.air.pos has been given a value |
|
363 |
assert(v->u.air.pos != MAX_ELEMENTS); |
|
364 |
} |
|
365 |
||
366 |
v->u.air.state = HANGAR; |
|
367 |
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
|
368 |
v->u.air.targetairport = GetStationIndex(tile); |
0 | 369 |
v->next = u; |
370 |
||
371 |
v->service_interval = _patches.servint_aircraft; |
|
372 |
||
373 |
v->date_of_last_service = _date; |
|
4329
0e6e689f66e7
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4293
diff
changeset
|
374 |
v->build_year = u->build_year = _cur_year; |
0 | 375 |
|
376 |
v->cur_image = u->cur_image = 0xEA0; |
|
377 |
||
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
|
378 |
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
|
379 |
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
|
380 |
|
0 | 381 |
VehiclePositionChanged(v); |
382 |
VehiclePositionChanged(u); |
|
383 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
384 |
// 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
|
385 |
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
|
386 |
Vehicle *w = vl[2]; |
0 | 387 |
|
388 |
u->next = w; |
|
389 |
||
390 |
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
|
391 |
w->direction = DIR_N; |
0 | 392 |
w->owner = _current_player; |
393 |
w->x_pos = v->x_pos; |
|
394 |
w->y_pos = v->y_pos; |
|
395 |
w->z_pos = v->z_pos + 5; |
|
396 |
w->x_offs = w->y_offs = -1; |
|
397 |
w->sprite_width = w->sprite_height = 2; |
|
398 |
w->z_height = 1; |
|
399 |
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
|
400 |
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
|
401 |
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
|
402 |
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
|
403 |
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
|
404 |
/* 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
|
405 |
w->u.air.state = HRS_ROTOR_STOPPED; |
0 | 406 |
VehiclePositionChanged(w); |
407 |
} |
|
4574
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4549
diff
changeset
|
408 |
GetPlayer(_current_player)->num_engines[p1]++; |
0 | 409 |
|
4739
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4732
diff
changeset
|
410 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
588 | 411 |
RebuildVehicleLists(); |
0 | 412 |
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
|
413 |
if (IsLocalPlayer()) |
9691753519ac
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2601
diff
changeset
|
414 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Aircraft); //updates the replace Aircraft window |
0 | 415 |
} |
416 |
||
417 |
return value; |
|
418 |
} |
|
419 |
||
420 |
||
410 | 421 |
static void DoDeleteAircraft(Vehicle *v) |
0 | 422 |
{ |
423 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
588 | 424 |
RebuildVehicleLists(); |
0 | 425 |
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
|
426 |
DeleteDepotHighlightOfVehicle(v); |
0 | 427 |
DeleteVehicleChain(v); |
1055
cc4f60cc9102
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
428 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 429 |
} |
430 |
||
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
|
431 |
/** 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
|
432 |
* @param tile unused |
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
|
433 |
* @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
|
434 |
* @param p2 unused |
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
|
435 |
*/ |
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
|
436 |
int32 CmdSellAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 437 |
{ |
438 |
Vehicle *v; |
|
439 |
||
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
440 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
0 | 441 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
442 |
v = GetVehicle(p1); |
0 | 443 |
|
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3160
diff
changeset
|
444 |
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
|
445 |
if (!IsAircraftInHangarStopped(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED); |
0 | 446 |
|
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
|
447 |
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
|
448 |
|
0 | 449 |
if (flags & DC_EXEC) { |
450 |
// Invalidate depot |
|
451 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
452 |
DoDeleteAircraft(v); |
|
2618
9691753519ac
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2601
diff
changeset
|
453 |
if (IsLocalPlayer()) |
9691753519ac
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2601
diff
changeset
|
454 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Aircraft); // updates the replace Aircraft window |
0 | 455 |
} |
456 |
||
457 |
return -(int32)v->value; |
|
458 |
} |
|
459 |
||
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
|
460 |
/** 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
|
461 |
* @param tile unused |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
462 |
* @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
|
463 |
* @param p2 unused |
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
|
464 |
*/ |
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
|
465 |
int32 CmdStartStopAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 466 |
{ |
467 |
Vehicle *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
|
468 |
uint16 callback; |
0 | 469 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
470 |
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
|
471 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
472 |
v = GetVehicle(p1); |
0 | 473 |
|
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
|
474 |
if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 475 |
|
476 |
// 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
|
477 |
if (v->u.air.state >= STARTTAKEOFF && v->u.air.state < TERM7) |
0 | 478 |
return_cmd_error(STR_A017_AIRCRAFT_IS_IN_FLIGHT); |
479 |
||
4338
e079d33dc473
(svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents:
4329
diff
changeset
|
480 |
/* 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
|
481 |
* return 0xFF if it can. */ |
e079d33dc473
(svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents:
4329
diff
changeset
|
482 |
callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v); |
e079d33dc473
(svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents:
4329
diff
changeset
|
483 |
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
|
484 |
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
|
485 |
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
|
486 |
} |
e079d33dc473
(svn r6039) -Fix: [newGRF] FS#287 Bugfix for error in NewGRF callback 31 code for aircraft (Mart3p)
bjarni
parents:
4329
diff
changeset
|
487 |
|
0 | 488 |
if (flags & DC_EXEC) { |
3963
6cab57074a9a
(svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents:
3955
diff
changeset
|
489 |
if (IsAircraftInHangarStopped(v)) { |
3139
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3008
diff
changeset
|
490 |
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
|
491 |
} |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3008
diff
changeset
|
492 |
|
0 | 493 |
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
|
494 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 495 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
1055
cc4f60cc9102
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
496 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 497 |
} |
498 |
||
499 |
return 0; |
|
500 |
} |
|
501 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
502 |
/** 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
|
503 |
* @param tile unused |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
504 |
* @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
|
505 |
* @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
|
506 |
* - 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
|
507 |
* - p2 bit 8-10 - VLW flag (for mass goto depot) |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
508 |
*/ |
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
|
509 |
int32 CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 510 |
{ |
511 |
Vehicle *v; |
|
512 |
||
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
513 |
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
|
514 |
/* 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
|
515 |
if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR; |
507b7d9bd834
(svn r6378) -Codechange: Rename VLW_FLAGS to VLW_MASK as it is a mask
Darkvater
parents:
4544
diff
changeset
|
516 |
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
|
517 |
} |
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
518 |
|
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
519 |
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
|
520 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
521 |
v = GetVehicle(p1); |
0 | 522 |
|
4526 | 523 |
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
|
524 |
|
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
525 |
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
|
526 |
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
|
527 |
/* 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
|
528 |
* 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
|
529 |
* 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
|
530 |
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
|
531 |
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
|
532 |
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
|
533 |
} |
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
|
534 |
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
|
535 |
} |
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
|
536 |
|
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
537 |
if (p2 & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of hangar orders |
0 | 538 |
if (flags & DC_EXEC) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
539 |
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
|
540 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
541 |
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
|
542 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 543 |
} |
544 |
} 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
|
545 |
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
|
546 |
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
|
547 |
const Station *st = GetStation(next_airport_index); |
4111
221355fcade6
(svn r5454) -Fix: [ 1394231 ] Autorenew glitch on helicopters
bjarni
parents:
4095
diff
changeset
|
548 |
/* If the station is not a valid airport or if it has no hangars */ |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
549 |
if (!IsValidStation(st) || st->airport_tile == 0 || GetAirport(st->airport_type)->nof_depots == 0) { |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
550 |
StationID 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
|
551 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
552 |
// the aircraft has to search for a hangar on its own |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
553 |
station = FindNearestHangar(v); |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
554 |
|
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
555 |
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
|
556 |
if (station == INVALID_STATION) return CMD_ERROR; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
557 |
st = GetStation(station); |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
558 |
next_airport_index = station; |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
559 |
|
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 |
} |
0 | 561 |
|
562 |
if (flags & DC_EXEC) { |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
563 |
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
|
564 |
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
|
565 |
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
|
566 |
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
|
567 |
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
|
568 |
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
|
569 |
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
|
570 |
/* 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
|
571 |
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
|
572 |
v->u.air.targetairport = next_airport_index; |
2b25b1477623
(svn r1698) - Feature [autoreplace] helicopters will now go to the nearest hangar if they are set to autoreplace and don't have any airport with a hangar in
bjarni
parents:
1151
diff
changeset
|
573 |
} |
0 | 574 |
} |
575 |
} |
|
576 |
||
577 |
return 0; |
|
578 |
} |
|
579 |
||
580 |
||
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
|
581 |
/** 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
|
582 |
* @param tile unused |
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
|
583 |
* @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
|
584 |
* @param p2 various bitstuffed elements |
2635 | 585 |
* - 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
|
586 |
* - p2 = (bit 8-15) - the new cargo subtype to refit to |
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
|
587 |
*/ |
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
|
588 |
int32 CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 589 |
{ |
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
|
590 |
Vehicle *v; |
0 | 591 |
int pass, mail; |
592 |
int32 cost; |
|
2635 | 593 |
CargoID new_cid = GB(p2, 0, 8); |
3954
7b51d0046efb
(svn r5103) - Add cargo subtype parameter to refit commands (mart3p)
peter1138
parents:
3948
diff
changeset
|
594 |
byte new_subtype = GB(p2, 8, 8); |
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
|
595 |
const AircraftVehicleInfo *avi; |
3974
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
596 |
uint16 callback = CALLBACK_FAILED; |
0 | 597 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
598 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
0 | 599 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
600 |
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
|
601 |
|
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
|
602 |
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
|
603 |
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
|
604 |
|
924
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
605 |
avi = AircraftVehInfo(v->engine_type); |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
606 |
|
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
|
607 |
/* Check cargo */ |
2704
bdf6ae0cb27c
(svn r3248) - Codechange: Change interface of CanRefitTo() to supply the engine type directly instead of getting it from a vehicle. This allows the function to be used before vehicles are involved.
peter1138
parents:
2697
diff
changeset
|
608 |
if (new_cid > NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR; |
0 | 609 |
|
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
|
610 |
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
|
611 |
|
3974
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
612 |
/* Check the refit capacity callback */ |
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
613 |
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
|
614 |
/* Back up the existing cargo type */ |
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
615 |
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
|
616 |
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
|
617 |
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
|
618 |
v->cargo_subtype = new_subtype; |
3974
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
619 |
|
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
620 |
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
|
621 |
|
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
622 |
/* Restore the cargo type */ |
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
623 |
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
|
624 |
v->cargo_subtype = temp_subtype; |
3974
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
625 |
} |
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
626 |
|
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
627 |
if (callback == CALLBACK_FAILED) { |
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
628 |
/* 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
|
629 |
* default cargo capacity */ |
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
630 |
pass = AircraftDefaultCargoCapacity(new_cid, v->engine_type); |
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
631 |
} else { |
08b438ca3429
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
peter1138
parents:
3973
diff
changeset
|
632 |
pass = callback; |
0 | 633 |
} |
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
|
634 |
_returned_refit_capacity = pass; |
0 | 635 |
|
636 |
cost = 0; |
|
4845
72bbb6e2694e
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4843
diff
changeset
|
637 |
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
|
638 |
cost = GetRefitCost(v->engine_type); |
0 | 639 |
} |
640 |
||
641 |
if (flags & DC_EXEC) { |
|
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
|
642 |
Vehicle *u; |
0 | 643 |
v->cargo_cap = pass; |
644 |
||
645 |
u = v->next; |
|
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
|
646 |
mail = (new_cid != CT_PASSENGERS) ? 0 : avi->mail_capacity; |
0 | 647 |
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
|
648 |
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
|
649 |
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
|
650 |
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
|
651 |
} 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
|
652 |
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
|
653 |
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
|
654 |
} |
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
|
655 |
v->cargo_type = new_cid; |
3954
7b51d0046efb
(svn r5103) - Add cargo subtype parameter to refit commands (mart3p)
peter1138
parents:
3948
diff
changeset
|
656 |
v->cargo_subtype = new_subtype; |
0 | 657 |
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
|
658 |
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
|
659 |
RebuildVehicleLists(); |
0 | 660 |
} |
661 |
||
662 |
return cost; |
|
663 |
} |
|
664 |
||
665 |
||
666 |
static void CheckIfAircraftNeedsService(Vehicle *v) |
|
667 |
{ |
|
2630 | 668 |
const Station* st; |
0 | 669 |
|
2639 | 670 |
if (_patches.servint_aircraft == 0) return; |
671 |
if (!VehicleNeedsService(v)) return; |
|
672 |
if (v->vehstatus & VS_STOPPED) return; |
|
0 | 673 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
674 |
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
|
675 |
v->current_order.flags & OF_HALT_IN_DEPOT) |
0 | 676 |
return; |
677 |
||
2639 | 678 |
if (_patches.gotodepot && VehicleHasDepotOrders(v)) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
679 |
|
4529
18bd5e7e35aa
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
680 |
if (IsAircraftInHangar(v)) { |
18bd5e7e35aa
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
681 |
VehicleServiceInDepot(v); |
18bd5e7e35aa
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
682 |
return; |
18bd5e7e35aa
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
683 |
} |
18bd5e7e35aa
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
684 |
|
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
|
685 |
st = GetStation(v->current_order.dest); |
0 | 686 |
// only goto depot if the target airport has terminals (eg. it is airport) |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
687 |
if (IsValidStation(st) && st->airport_tile != 0 && GetAirport(st->airport_type)->terminals != NULL) { |
0 | 688 |
// printf("targetairport = %d, st->index = %d\n", v->u.air.targetairport, st->index); |
689 |
// v->u.air.targetairport = st->index; |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
690 |
v->current_order.type = OT_GOTO_DEPOT; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
691 |
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
|
692 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
693 |
} else if (v->current_order.type == OT_GOTO_DEPOT) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
694 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
695 |
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
|
696 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 697 |
} |
698 |
} |
|
699 |
||
700 |
void OnNewDay_Aircraft(Vehicle *v) |
|
701 |
{ |
|
702 |
int32 cost; |
|
703 |
||
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
|
704 |
if (!IsNormalAircraft(v)) return; |
0 | 705 |
|
2639 | 706 |
if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v); |
0 | 707 |
|
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
708 |
CheckOrders(v); |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
11
diff
changeset
|
709 |
|
0 | 710 |
CheckVehicleBreakdown(v); |
711 |
AgeVehicle(v); |
|
712 |
CheckIfAircraftNeedsService(v); |
|
713 |
||
2639 | 714 |
if (v->vehstatus & VS_STOPPED) return; |
0 | 715 |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
716 |
cost = AircraftVehInfo(v->engine_type)->running_cost * _price.aircraft_running / 364; |
0 | 717 |
|
718 |
v->profit_this_year -= cost >> 8; |
|
719 |
||
720 |
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN); |
|
721 |
SubtractMoneyFromPlayerFract(v->owner, cost); |
|
722 |
||
723 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1055
cc4f60cc9102
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
724 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 725 |
} |
726 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1064
diff
changeset
|
727 |
void AircraftYearlyLoop(void) |
0 | 728 |
{ |
729 |
Vehicle *v; |
|
730 |
||
731 |
FOR_ALL_VEHICLES(v) { |
|
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
|
732 |
if (v->type == VEH_Aircraft && IsNormalAircraft(v)) { |
0 | 733 |
v->profit_last_year = v->profit_this_year; |
734 |
v->profit_this_year = 0; |
|
735 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
736 |
} |
|
737 |
} |
|
738 |
} |
|
739 |
||
740 |
static void AgeAircraftCargo(Vehicle *v) |
|
741 |
{ |
|
2639 | 742 |
if (_age_cargo_skip_counter != 0) return; |
0 | 743 |
|
744 |
do { |
|
2639 | 745 |
if (v->cargo_days != 0xFF) v->cargo_days++; |
746 |
v = v->next; |
|
747 |
} while (v != NULL); |
|
0 | 748 |
} |
749 |
||
750 |
static void HelicopterTickHandler(Vehicle *v) |
|
751 |
{ |
|
752 |
Vehicle *u; |
|
753 |
int tick,spd; |
|
3710
44cf97e29c18
(svn r4653) - NewGRF: enable use of custom helicopter rotors in game (but not GUI windows yet) (mart3p)
peter1138
parents:
3701
diff
changeset
|
754 |
SpriteID img; |
0 | 755 |
|
756 |
u = v->next->next; |
|
757 |
||
2639 | 758 |
if (u->vehstatus & VS_HIDDEN) return; |
0 | 759 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
760 |
// if true, helicopter rotors do not rotate. This should only be the case if a helicopter is |
0 | 761 |
// loading/unloading at a terminal or stopped |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
762 |
if (v->current_order.type == OT_LOADING || (v->vehstatus & VS_STOPPED)) { |
0 | 763 |
if (u->cur_speed != 0) { |
764 |
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
|
765 |
if (u->cur_speed >= 0x80 && u->u.air.state == HRS_ROTOR_MOVING_3) { |
0 | 766 |
u->cur_speed = 0; |
767 |
} |
|
768 |
} |
|
769 |
} else { |
|
770 |
if (u->cur_speed == 0) |
|
771 |
u->cur_speed = 0x70; |
|
772 |
||
773 |
if (u->cur_speed >= 0x50) |
|
774 |
u->cur_speed--; |
|
775 |
} |
|
776 |
||
777 |
tick = ++u->tick_counter; |
|
778 |
spd = u->cur_speed >> 4; |
|
779 |
||
780 |
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
|
781 |
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
|
782 |
img = GetRotorImage(v); |
2549 | 783 |
if (u->cur_image == img) return; |
0 | 784 |
} else if (tick >= spd) { |
785 |
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
|
786 |
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
|
787 |
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
|
788 |
img = GetRotorImage(v); |
2549 | 789 |
} else { |
0 | 790 |
return; |
2549 | 791 |
} |
0 | 792 |
|
2549 | 793 |
u->cur_image = img; |
0 | 794 |
|
795 |
BeginVehicleMove(u); |
|
796 |
VehiclePositionChanged(u); |
|
797 |
EndVehicleMove(u); |
|
798 |
} |
|
799 |
||
800 |
static void SetAircraftPosition(Vehicle *v, int x, int y, int z) |
|
801 |
{ |
|
802 |
Vehicle *u; |
|
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
|
803 |
int safe_x; |
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
|
804 |
int safe_y; |
0 | 805 |
|
806 |
v->x_pos = x; |
|
807 |
v->y_pos = y; |
|
808 |
v->z_pos = z; |
|
809 |
||
810 |
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
|
811 |
if (v->subtype == AIR_HELICOPTER) v->next->next->cur_image = GetRotorImage(v); |
0 | 812 |
|
813 |
BeginVehicleMove(v); |
|
814 |
VehiclePositionChanged(v); |
|
815 |
EndVehicleMove(v); |
|
816 |
||
817 |
u = v->next; |
|
818 |
||
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
|
819 |
safe_x = clamp(x, 0, MapMaxX() * 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
|
820 |
safe_y = clamp(y - 1, 0, MapMaxY() * TILE_SIZE); |
0 | 821 |
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
|
822 |
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
|
823 |
|
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 |
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
|
825 |
u->z_pos = GetSlopeZ(safe_x, safe_y); |
0 | 826 |
u->cur_image = v->cur_image; |
827 |
||
828 |
BeginVehicleMove(u); |
|
829 |
VehiclePositionChanged(u); |
|
830 |
EndVehicleMove(u); |
|
831 |
||
2639 | 832 |
u = u->next; |
833 |
if (u != NULL) { |
|
0 | 834 |
u->x_pos = x; |
835 |
u->y_pos = y; |
|
836 |
u->z_pos = z + 5; |
|
837 |
||
838 |
BeginVehicleMove(u); |
|
839 |
VehiclePositionChanged(u); |
|
840 |
EndVehicleMove(u); |
|
841 |
} |
|
842 |
} |
|
843 |
||
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
844 |
/** 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
|
845 |
* @param *v Vehicle that enters the hangar |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
846 |
*/ |
4732
4f1c405ac96e
(svn r6644) -Fix(r6637): remove inline to allow MSVC compilation
belugas
parents:
4725
diff
changeset
|
847 |
void HandleAircraftEnterHangar(Vehicle *v) |
0 | 848 |
{ |
849 |
Vehicle *u; |
|
850 |
||
851 |
v->subspeed = 0; |
|
852 |
v->progress = 0; |
|
853 |
||
854 |
u = v->next; |
|
855 |
u->vehstatus |= VS_HIDDEN; |
|
2639 | 856 |
u = u->next; |
857 |
if (u != NULL) { |
|
0 | 858 |
u->vehstatus |= VS_HIDDEN; |
859 |
u->cur_speed = 0; |
|
860 |
} |
|
861 |
||
862 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos); |
|
863 |
} |
|
864 |
||
2549 | 865 |
static void PlayAircraftSound(const Vehicle* v) |
0 | 866 |
{ |
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
867 |
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
|
868 |
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
|
869 |
} |
0 | 870 |
} |
871 |
||
872 |
static bool UpdateAircraftSpeed(Vehicle *v) |
|
873 |
{ |
|
874 |
uint spd = v->acceleration * 2; |
|
875 |
byte t; |
|
876 |
||
877 |
v->subspeed = (t=v->subspeed) + (byte)spd; |
|
2639 | 878 |
spd = min(v->cur_speed + (spd >> 8) + (v->subspeed < t), v->max_speed); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
879 |
|
0 | 880 |
// adjust speed for broken vehicles |
2639 | 881 |
if (v->vehstatus & VS_AIRCRAFT_BROKEN) spd = min(spd, 27); |
0 | 882 |
|
883 |
//updates statusbar only if speed have changed to save CPU time |
|
884 |
if (spd != v->cur_speed) { |
|
885 |
v->cur_speed = spd; |
|
886 |
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
|
887 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 888 |
} |
889 |
||
2639 | 890 |
if (!(v->direction & 1)) spd = spd * 3 / 4; |
0 | 891 |
|
2639 | 892 |
if (spd == 0) return false; |
0 | 893 |
|
2639 | 894 |
if ((byte)++spd == 0) return true; |
0 | 895 |
|
896 |
v->progress = (t = v->progress) - (byte)spd; |
|
897 |
||
2639 | 898 |
return t < v->progress; |
0 | 899 |
} |
900 |
||
901 |
// get Aircraft running altitude |
|
902 |
static byte GetAircraftFlyingAltitude(const Vehicle *v) |
|
903 |
{ |
|
1897 | 904 |
switch (v->max_speed) { |
905 |
case 37: return 162; |
|
906 |
case 74: return 171; |
|
907 |
default: return 180; |
|
0 | 908 |
} |
909 |
} |
|
910 |
||
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
|
911 |
static bool AircraftController(Vehicle *v) |
0 | 912 |
{ |
913 |
Station *st; |
|
914 |
const AirportMovingData *amd; |
|
915 |
Vehicle *u; |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5585
diff
changeset
|
916 |
byte z, maxz, curz; |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5585
diff
changeset
|
917 |
Direction newdir; |
0 | 918 |
GetNewVehiclePosResult gp; |
919 |
uint dist; |
|
920 |
int x,y; |
|
921 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
922 |
st = GetStation(v->u.air.targetairport); |
0 | 923 |
|
924 |
// prevent going to 0,0 if airport is deleted. |
|
925 |
{ |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1926
diff
changeset
|
926 |
TileIndex tile = st->airport_tile; |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1926
diff
changeset
|
927 |
|
0 | 928 |
if (tile == 0) tile = st->xy; |
929 |
// xy of destination |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
930 |
x = TileX(tile) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3338
diff
changeset
|
931 |
y = TileY(tile) * TILE_SIZE; |
0 | 932 |
} |
933 |
||
934 |
// get airport moving data |
|
3701
fdbb6bcab8a2
(svn r4642) - Codechange: reorganise airport.h and airport_movement.h to avoid having 8 copies of the airport FTAs, and make the enums used available elsewhere.
peter1138
parents:
3579
diff
changeset
|
935 |
amd = GetAirportMovingData(st->airport_type, v->u.air.pos); |
0 | 936 |
|
937 |
// Helicopter raise |
|
938 |
if (amd->flag & AMED_HELI_RAISE) { |
|
939 |
u = v->next->next; |
|
940 |
||
941 |
// Make sure the rotors don't rotate too fast |
|
942 |
if (u->cur_speed > 32) { |
|
943 |
v->cur_speed = 0; |
|
2639 | 944 |
if (--u->cur_speed == 32) SndPlayVehicleFx(SND_18_HELICOPTER, v); |
0 | 945 |
} else { |
946 |
u->cur_speed = 32; |
|
947 |
if (UpdateAircraftSpeed(v)) { |
|
948 |
v->tile = 0; |
|
949 |
||
950 |
// Reached altitude? |
|
951 |
if (v->z_pos >= 184) { |
|
952 |
v->cur_speed = 0; |
|
953 |
return true; |
|
954 |
} |
|
955 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos+1); |
|
956 |
} |
|
957 |
} |
|
958 |
return false; |
|
959 |
} |
|
960 |
||
961 |
// Helicopter landing. |
|
962 |
if (amd->flag & AMED_HELI_LOWER) { |
|
963 |
if (UpdateAircraftSpeed(v)) { |
|
964 |
if (st->airport_tile == 0) { |
|
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
|
965 |
// FIXME - AircraftController -> if station no longer exists, do not land |
0 | 966 |
// helicopter will circle until sign disappears, then go to next order |
967 |
// * what to do when it is the only order left, right now it just stays in 1 place |
|
968 |
v->u.air.state = FLYING; |
|
969 |
AircraftNextAirportPos_and_Order(v); |
|
970 |
return false; |
|
971 |
} |
|
972 |
||
973 |
// Vehicle is now at the airport. |
|
974 |
v->tile = st->airport_tile; |
|
975 |
||
976 |
// Find altitude of landing position. |
|
977 |
z = GetSlopeZ(x, y) + 1; |
|
978 |
if (st->airport_type == AT_OILRIG) z += 54; |
|
979 |
if (st->airport_type == AT_HELIPORT) z += 60; |
|
980 |
||
981 |
if (z == v->z_pos) { |
|
982 |
u = v->next->next; |
|
983 |
||
984 |
// Increase speed of rotors. When speed is 80, we've landed. |
|
2639 | 985 |
if (u->cur_speed >= 80) return true; |
986 |
u->cur_speed += 4; |
|
0 | 987 |
} else if (v->z_pos > z) { |
988 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos-1); |
|
989 |
} else { |
|
990 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos+1); |
|
991 |
} |
|
992 |
} |
|
993 |
return false; |
|
994 |
} |
|
995 |
||
996 |
// Get distance from destination pos to current pos. |
|
997 |
dist = myabs(x + amd->x - v->x_pos) + myabs(y + amd->y - v->y_pos); |
|
998 |
||
999 |
// Need exact position? |
|
2364
9685b222ab72
(svn r2890) Fix some signed/unsigned comparison warnings (tokai)
tron
parents:
2316
diff
changeset
|
1000 |
if (!(amd->flag & AMED_EXACTPOS) && dist <= (amd->flag & AMED_SLOWTURN ? 8U : 4U)) |
0 | 1001 |
return true; |
1002 |
||
1003 |
// At final pos? |
|
1004 |
if (dist == 0) { |
|
3158
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
1005 |
DirDiff dirdiff; |
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
1006 |
|
2639 | 1007 |
if (v->cur_speed > 12) v->cur_speed = 12; |
0 | 1008 |
|
1009 |
// Change direction smoothly to final direction. |
|
3158
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
1010 |
dirdiff = DirDifference(amd->direction, v->direction); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1011 |
// if distance is 0, and plane points in right direction, no point in calling |
0 | 1012 |
// UpdateAircraftSpeed(). So do it only afterwards |
3158
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
1013 |
if (dirdiff == DIRDIFF_SAME) { |
0 | 1014 |
v->cur_speed = 0; |
1015 |
return true; |
|
1016 |
} |
|
1017 |
||
2639 | 1018 |
if (!UpdateAircraftSpeed(v)) return false; |
0 | 1019 |
|
3158
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
1020 |
v->direction = ChangeDir(v->direction, dirdiff > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT); |
0 | 1021 |
v->cur_speed >>= 1; |
1022 |
||
1023 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos); |
|
1024 |
return false; |
|
1025 |
} |
|
1026 |
||
2639 | 1027 |
if (!(amd->flag & AMED_NOSPDCLAMP) && v->cur_speed > 12) v->cur_speed = 12; |
0 | 1028 |
|
2639 | 1029 |
if (!UpdateAircraftSpeed(v)) return false; |
0 | 1030 |
|
2639 | 1031 |
if (v->load_unload_time_rem != 0) v->load_unload_time_rem--; |
0 | 1032 |
|
1033 |
// Turn. Do it slowly if in the air. |
|
1034 |
newdir = GetDirectionTowards(v, x + amd->x, y + amd->y); |
|
1035 |
if (newdir != v->direction) { |
|
1036 |
if (amd->flag & AMED_SLOWTURN) { |
|
2639 | 1037 |
if (v->load_unload_time_rem == 0) v->load_unload_time_rem = 8; |
99 | 1038 |
v->direction = newdir; |
0 | 1039 |
} else { |
1040 |
v->cur_speed >>= 1; |
|
1041 |
v->direction = newdir; |
|
1042 |
} |
|
1043 |
} |
|
1044 |
||
1045 |
// Move vehicle. |
|
1046 |
GetNewVehiclePos(v, &gp); |
|
1047 |
v->tile = gp.new_tile; |
|
1048 |
||
1049 |
// If vehicle is in the air, use tile coordinate 0. |
|
2639 | 1050 |
if (amd->flag & (AMED_TAKEOFF | AMED_SLOWTURN | AMED_LAND)) v->tile = 0; |
0 | 1051 |
|
1052 |
// Adjust Z for land or takeoff? |
|
1053 |
z = v->z_pos; |
|
1054 |
||
1055 |
if (amd->flag & AMED_TAKEOFF) { |
|
2639 | 1056 |
z += 2; |
0 | 1057 |
maxz = GetAircraftFlyingAltitude(v); |
2639 | 1058 |
if (z > maxz) z = maxz; |
0 | 1059 |
} |
1060 |
||
1061 |
if (amd->flag & AMED_LAND) { |
|
1062 |
if (st->airport_tile == 0) { |
|
1063 |
v->u.air.state = FLYING; |
|
1064 |
AircraftNextAirportPos_and_Order(v); |
|
1065 |
// get aircraft back on running altitude |
|
1066 |
SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v)); |
|
1067 |
return false; |
|
1068 |
} |
|
1069 |
||
1070 |
curz = GetSlopeZ(x, y) + 1; |
|
1071 |
||
1072 |
if (curz > z) { |
|
1073 |
z++; |
|
1074 |
} else { |
|
5601
d58f82901b2f
(svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents:
5587
diff
changeset
|
1075 |
int t = max(1U, dist - 4); |
0 | 1076 |
|
1077 |
z -= ((z - curz) + t - 1) / t; |
|
1078 |
if (z < curz) z = curz; |
|
1079 |
} |
|
1080 |
} |
|
1081 |
||
1082 |
// We've landed. Decrase speed when we're reaching end of runway. |
|
1083 |
if (amd->flag & AMED_BRAKE) { |
|
1084 |
curz = GetSlopeZ(x, y) + 1; |
|
1085 |
||
2639 | 1086 |
if (z > curz) { |
1087 |
z--; |
|
1088 |
} else if (z < curz) { |
|
1089 |
z++; |
|
1090 |
} |
|
0 | 1091 |
|
2639 | 1092 |
if (dist < 64 && v->cur_speed > 12) v->cur_speed -= 4; |
0 | 1093 |
} |
1094 |
||
1095 |
SetAircraftPosition(v, gp.x, gp.y, z); |
|
1096 |
return false; |
|
1097 |
} |
|
1098 |
||
1099 |
||
1100 |
static void HandleCrashedAircraft(Vehicle *v) |
|
1101 |
{ |
|
1102 |
uint32 r; |
|
1103 |
Station *st; |
|
899
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1104 |
int z; |
0 | 1105 |
|
1106 |
v->u.air.crashed_counter++; |
|
1107 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1108 |
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
|
1109 |
|
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
|
1110 |
// make aircraft crash down to the ground |
1150
7b5946a53372
(svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents:
1139
diff
changeset
|
1111 |
if (v->u.air.crashed_counter < 500 && st->airport_tile==0 && ((v->u.air.crashed_counter % 3) == 0) ) { |
7b5946a53372
(svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents:
1139
diff
changeset
|
1112 |
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
|
1113 |
v->z_pos -= 1; |
1150
7b5946a53372
(svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents:
1139
diff
changeset
|
1114 |
if (v->z_pos == z) { |
7b5946a53372
(svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents:
1139
diff
changeset
|
1115 |
v->u.air.crashed_counter = 500; |
7b5946a53372
(svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents:
1139
diff
changeset
|
1116 |
v->z_pos++; |
7b5946a53372
(svn r1651) Fix: [ 1098696 ] Airport shadow remains after crashing
dominik
parents:
1139
diff
changeset
|
1117 |
} |
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
|
1118 |
} |
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
|
1119 |
|
0 | 1120 |
if (v->u.air.crashed_counter < 650) { |
1121 |
if (CHANCE16R(1,32,r)) { |
|
3160 | 1122 |
static const DirDiff delta[] = { |
1123 |
DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT |
|
1124 |
}; |
|
1125 |
||
1126 |
v->direction = ChangeDir(v->direction, delta[GB(r, 16, 2)]); |
|
0 | 1127 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos); |
1128 |
r = Random(); |
|
1129 |
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
|
1130 |
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
|
1131 |
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
|
1132 |
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
|
1133 |
EV_EXPLOSION_SMALL); |
0 | 1134 |
} |
1135 |
} else if (v->u.air.crashed_counter >= 10000) { |
|
1136 |
// remove rubble of crashed airplane |
|
1137 |
||
1138 |
// clear runway-in on all airports, set by crashing plane |
|
1139 |
// small airports use AIRPORT_BUSY, city airports use RUNWAY_IN_OUT_block, etc. |
|
1140 |
// but they all share the same number |
|
1141 |
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
|
1142 |
CLRBITS(st->airport_flags, RUNWAY_IN_OUT_block); // commuter airport |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4056
diff
changeset
|
1143 |
CLRBITS(st->airport_flags, RUNWAY_IN2_block); // intercontinental |
0 | 1144 |
|
1145 |
BeginVehicleMove(v); |
|
1146 |
EndVehicleMove(v); |
|
1147 |
||
1148 |
DoDeleteAircraft(v); |
|
1149 |
} |
|
1150 |
} |
|
1151 |
||
1152 |
static void HandleBrokenAircraft(Vehicle *v) |
|
1153 |
{ |
|
1154 |
if (v->breakdown_ctr != 1) { |
|
1155 |
v->breakdown_ctr = 1; |
|
1156 |
v->vehstatus |= VS_AIRCRAFT_BROKEN; |
|
1157 |
||
1158 |
if (v->breakdowns_since_last_service != 255) |
|
1159 |
v->breakdowns_since_last_service++; |
|
1160 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
|
1161 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1162 |
} |
|
1163 |
} |
|
1164 |
||
1165 |
||
1166 |
static void HandleAircraftSmoke(Vehicle *v) |
|
1167 |
{ |
|
2654
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1168 |
static const struct { |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1169 |
int8 x; |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1170 |
int8 y; |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1171 |
} smoke_pos[] = { |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1172 |
{ 5, 5 }, |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1173 |
{ 6, 0 }, |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1174 |
{ 5, -5 }, |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1175 |
{ 0, -6 }, |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1176 |
{ -5, -5 }, |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1177 |
{ -6, 0 }, |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1178 |
{ -5, 5 }, |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1179 |
{ 0, 6 } |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1180 |
}; |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1181 |
|
2639 | 1182 |
if (!(v->vehstatus & VS_AIRCRAFT_BROKEN)) return; |
0 | 1183 |
|
1184 |
if (v->cur_speed < 10) { |
|
1185 |
v->vehstatus &= ~VS_AIRCRAFT_BROKEN; |
|
1186 |
v->breakdown_ctr = 0; |
|
1187 |
return; |
|
1188 |
} |
|
1189 |
||
1190 |
if ((v->tick_counter & 0x1F) == 0) { |
|
1191 |
CreateEffectVehicleRel(v, |
|
2654
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1192 |
smoke_pos[v->direction].x, |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2639
diff
changeset
|
1193 |
smoke_pos[v->direction].y, |
0 | 1194 |
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
|
1195 |
EV_SMOKE |
0 | 1196 |
); |
1197 |
} |
|
1198 |
} |
|
1199 |
||
1200 |
static void ProcessAircraftOrder(Vehicle *v) |
|
1201 |
{ |
|
1043
44508ede2f92
(svn r1544) -Fix: SwapOrder did not use AssignOrder, which caused the saveroutine to
truelight
parents:
1035
diff
changeset
|
1202 |
const Order *order; |
0 | 1203 |
|
3005
2590b9b4823b
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2989
diff
changeset
|
1204 |
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
|
1205 |
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
|
1206 |
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
|
1207 |
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
|
1208 |
!VehicleNeedsService(v)) { |
2590b9b4823b
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2989
diff
changeset
|
1209 |
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
|
1210 |
} |
2590b9b4823b
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2989
diff
changeset
|
1211 |
break; |
2590b9b4823b
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2989
diff
changeset
|
1212 |
|
2590b9b4823b
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2989
diff
changeset
|
1213 |
case OT_LOADING: return; |
4351
c9799dd53eec
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4346
diff
changeset
|
1214 |
|
c9799dd53eec
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4346
diff
changeset
|
1215 |
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
|
1216 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1217 |
|
2639 | 1218 |
if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0; |
0 | 1219 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1220 |
order = GetVehicleOrder(v, v->cur_order_index); |
0 | 1221 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1222 |
if (order == NULL) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1223 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1224 |
v->current_order.flags = 0; |
0 | 1225 |
return; |
1226 |
} |
|
1227 |
||
3005
2590b9b4823b
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2989
diff
changeset
|
1228 |
if (order->type == OT_DUMMY && !CheckForValidOrders(v)) CrashAirplane(v); |
901
0e42c4b151e3
(svn r1387) Fix: Airplanes now also crash when only one invalid order is in the schedule
dominik
parents:
899
diff
changeset
|
1229 |
|
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
|
1230 |
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
|
1231 |
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
|
1232 |
order->dest == v->current_order.dest) |
0 | 1233 |
return; |
1234 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1235 |
v->current_order = *order; |
0 | 1236 |
|
1237 |
// 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
|
1238 |
if (order->type == OT_GOTO_STATION && v->u.air.state == FLYING) { |
0 | 1239 |
AircraftNextAirportPos_and_Order(v); |
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
|
1240 |
v->u.air.targetairport = order->dest; |
0 | 1241 |
} |
1242 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1243 |
InvalidateVehicleOrder(v); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1244 |
|
1055
cc4f60cc9102
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
1245 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 1246 |
} |
1247 |
||
3722
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1248 |
/** 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
|
1249 |
* @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
|
1250 |
*/ |
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1251 |
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
|
1252 |
{ |
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1253 |
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
|
1254 |
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
|
1255 |
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
|
1256 |
} |
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1257 |
|
0 | 1258 |
static void HandleAircraftLoading(Vehicle *v, int mode) |
1259 |
{ |
|
5856 | 1260 |
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
|
1261 |
case OT_LOADING: { |
5856 | 1262 |
if (mode != 0) return; |
1263 |
if (--v->load_unload_time_rem != 0) return; |
|
0 | 1264 |
|
5856 | 1265 |
if (CanFillVehicle(v) && ( |
1266 |
v->current_order.flags & OF_FULL_LOAD || |
|
1267 |
(_patches.gradual_loading && !HASBIT(v->load_status, LS_LOADING_FINISHED)) |
|
1268 |
)) { |
|
1269 |
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC); |
|
1270 |
if (LoadUnloadVehicle(v, false)) { |
|
1271 |
InvalidateWindow(WC_AIRCRAFT_LIST, v->owner); |
|
1272 |
MarkAircraftDirty(v); |
|
1273 |
} |
|
1274 |
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
|
1275 |
} |
0 | 1276 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1277 |
Order b = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1278 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1279 |
v->current_order.flags = 0; |
3722
0984901a2744
(svn r4693) - NewGRF: invalidate aircraft in viewports during loading stages so that graphic changes are visible. (mart3p)
peter1138
parents:
3710
diff
changeset
|
1280 |
MarkAircraftDirty(v); |
2639 | 1281 |
if (!(b.flags & OF_NON_STOP)) return; |
5856 | 1282 |
break; |
5858
a48c5b18747a
(svn r8434) -Fix (r8430): Missing braces caused compilation failure for some (most?) compilers...
peter1138
parents:
5856
diff
changeset
|
1283 |
} |
5856 | 1284 |
|
1285 |
case OT_DUMMY: break; |
|
1286 |
||
1287 |
default: return; |
|
0 | 1288 |
} |
5856 | 1289 |
|
0 | 1290 |
v->cur_order_index++; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1291 |
InvalidateVehicleOrder(v); |
0 | 1292 |
} |
1293 |
||
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
|
1294 |
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
|
1295 |
{ |
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
|
1296 |
uint16 amt; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1297 |
Station *st; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1298 |
StringID newsitem; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1299 |
|
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
|
1300 |
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
|
1301 |
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
|
1302 |
|
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
|
1303 |
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
|
1304 |
|
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
|
1305 |
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
|
1306 |
|
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
|
1307 |
amt = 2; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1308 |
if (v->cargo_type == CT_PASSENGERS) amt += v->cargo_count; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1309 |
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
|
1310 |
|
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
|
1311 |
v->cargo_count = 0; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1312 |
v->next->cargo_count = 0, |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1313 |
st = GetStation(v->u.air.targetairport); |
2639 | 1314 |
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
|
1315 |
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
|
1316 |
} 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
|
1317 |
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
|
1318 |
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
|
1319 |
} |
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
|
1320 |
|
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
|
1321 |
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
|
1322 |
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
|
1323 |
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
|
1324 |
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
|
1325 |
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
|
1326 |
|
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
|
1327 |
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
|
1328 |
} |
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
|
1329 |
|
0 | 1330 |
static void MaybeCrashAirplane(Vehicle *v) |
1331 |
{ |
|
1332 |
Station *st; |
|
1333 |
uint16 prob; |
|
2549 | 1334 |
uint i; |
0 | 1335 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1336 |
st = GetStation(v->u.air.targetairport); |
0 | 1337 |
|
1338 |
//FIXME -- MaybeCrashAirplane -> increase crashing chances of very modern airplanes on smaller than AT_METROPOLITAN airports |
|
1339 |
prob = 0x10000 / 1500; |
|
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4056
diff
changeset
|
1340 |
if (((st->airport_type == AT_SMALL) || (st->airport_type == AT_COMMUTER)) && (AircraftVehInfo(v->engine_type)->subtype & AIR_FAST) && !_cheats.no_jetcrash.value) { |
0 | 1341 |
prob = 0x10000 / 20; |
1342 |
} |
|
1343 |
||
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
|
1344 |
if (GB(Random(), 0, 16) > prob) return; |
0 | 1345 |
|
1346 |
// Crash the airplane. Remove all goods stored at the station. |
|
2549 | 1347 |
for (i = 0; i != NUM_CARGO; i++) { |
0 | 1348 |
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
|
1349 |
SB(st->goods[i].waiting_acceptance, 0, 12, 0); |
0 | 1350 |
} |
1351 |
||
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
|
1352 |
CrashAirplane(v); |
0 | 1353 |
} |
1354 |
||
1355 |
// we've landed and just arrived at a terminal |
|
1356 |
static void AircraftEntersTerminal(Vehicle *v) |
|
1357 |
{ |
|
1358 |
Station *st; |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1359 |
Order old_order; |
0 | 1360 |
|
2639 | 1361 |
if (v->current_order.type == OT_GOTO_DEPOT) return; |
0 | 1362 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1363 |
st = GetStation(v->u.air.targetairport); |
0 | 1364 |
v->last_station_visited = v->u.air.targetairport; |
1365 |
||
1366 |
/* Check if station was ever visited before */ |
|
1367 |
if (!(st->had_vehicle_of_type & HVOT_AIRCRAFT)) { |
|
1368 |
uint32 flags; |
|
1369 |
||
1370 |
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
|
1371 |
SetDParam(0, st->index); |
0 | 1372 |
// show newsitem of celebrating citizens |
1373 |
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); |
|
1374 |
AddNewsItem( |
|
1375 |
STR_A033_CITIZENS_CELEBRATE_FIRST, |
|
1376 |
flags, |
|
1377 |
v->index, |
|
1378 |
0); |
|
1379 |
} |
|
1380 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1381 |
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
|
1382 |
v->BeginLoading(); |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1383 |
v->current_order.flags = 0; |
0 | 1384 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1385 |
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
|
1386 |
v->current_order.dest == v->last_station_visited) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1387 |
v->current_order.flags = |
3872
a407dc67b041
(svn r4914) -Fix (FS#180) Aircraft can now serve as feeders
celestar
parents:
3870
diff
changeset
|
1388 |
(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER)) | OF_NON_STOP; |
0 | 1389 |
} |
1390 |
||
1391 |
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
|
1392 |
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
|
1393 |
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
|
1394 |
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
|
1395 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 1396 |
} |
1397 |
||
1398 |
static void AircraftLand(Vehicle *v) |
|
1399 |
{ |
|
1400 |
v->sprite_width = v->sprite_height = 2; |
|
1401 |
} |
|
1402 |
||
1403 |
static void AircraftLandAirplane(Vehicle *v) |
|
1404 |
{ |
|
1405 |
AircraftLand(v); |
|
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
1406 |
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
|
1407 |
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
|
1408 |
} |
0 | 1409 |
MaybeCrashAirplane(v); |
1410 |
} |
|
1411 |
||
1412 |
// set the right pos when heading to other airports after takeoff |
|
1413 |
static void AircraftNextAirportPos_and_Order(Vehicle *v) |
|
1414 |
{ |
|
2630 | 1415 |
const Station* st; |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1416 |
const AirportFTAClass *apc; |
0 | 1417 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1418 |
if (v->current_order.type == OT_GOTO_STATION || |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1419 |
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
|
1420 |
v->u.air.targetairport = v->current_order.dest; |
0 | 1421 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1422 |
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
|
1423 |
apc = GetAirport(st->airport_type); |
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1424 |
v->u.air.pos = v->u.air.previous_pos = apc->entry_point; |
0 | 1425 |
} |
1426 |
||
1427 |
static void AircraftLeaveHangar(Vehicle *v) |
|
1428 |
{ |
|
1429 |
v->cur_speed = 0; |
|
1430 |
v->subspeed = 0; |
|
1431 |
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
|
1432 |
v->direction = DIR_SE; |
0 | 1433 |
v->vehstatus &= ~VS_HIDDEN; |
1434 |
{ |
|
1435 |
Vehicle *u = v->next; |
|
1436 |
u->vehstatus &= ~VS_HIDDEN; |
|
1437 |
||
1438 |
// Rotor blades |
|
2639 | 1439 |
u = u->next; |
1440 |
if (u != NULL) { |
|
0 | 1441 |
u->vehstatus &= ~VS_HIDDEN; |
1442 |
u->cur_speed = 80; |
|
1443 |
} |
|
1444 |
} |
|
1445 |
||
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
|
1446 |
VehicleServiceInDepot(v); |
0 | 1447 |
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
|
1448 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
1055
cc4f60cc9102
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
1449 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 1450 |
} |
1451 |
||
1452 |
||
1453 |
//////////////////////////////////////////////////////////////////////////////// |
|
1454 |
/////////////////// AIRCRAFT MOVEMENT SCHEME //////////////////////////////// |
|
1455 |
//////////////////////////////////////////////////////////////////////////////// |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1456 |
static void AircraftEventHandler_EnterTerminal(Vehicle *v, const AirportFTAClass *apc) |
0 | 1457 |
{ |
1458 |
AircraftEntersTerminal(v); |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1459 |
v->u.air.state = apc->layout[v->u.air.pos].heading; |
0 | 1460 |
} |
1461 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1462 |
static void AircraftEventHandler_EnterHangar(Vehicle *v, const AirportFTAClass *apc) |
0 | 1463 |
{ |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1464 |
VehicleEnterDepot(v); |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1465 |
v->u.air.state = apc->layout[v->u.air.pos].heading; |
0 | 1466 |
} |
1467 |
||
1468 |
// In an Airport Hangar |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1469 |
static void AircraftEventHandler_InHangar(Vehicle *v, const AirportFTAClass *apc) |
0 | 1470 |
{ |
1471 |
// if we just arrived, execute EnterHangar first |
|
1472 |
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
|
1473 |
AircraftEventHandler_EnterHangar(v, apc); |
0 | 1474 |
return; |
1475 |
} |
|
1476 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1477 |
// if we were sent to the depot, stay there |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1478 |
if (v->current_order.type == OT_GOTO_DEPOT && (v->vehstatus & VS_STOPPED)) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1479 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1480 |
v->current_order.flags = 0; |
0 | 1481 |
return; |
1482 |
} |
|
1483 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1484 |
if (v->current_order.type != OT_GOTO_STATION && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1485 |
v->current_order.type != OT_GOTO_DEPOT) |
0 | 1486 |
return; |
1487 |
||
1488 |
// 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
|
1489 |
if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return; |
0 | 1490 |
|
1491 |
// 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
|
1492 |
if (v->current_order.dest == v->u.air.targetairport) { |
0 | 1493 |
// FindFreeTerminal: |
1494 |
// 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
|
1495 |
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
|
1496 |
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
|
1497 |
} else { |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1498 |
if (!AirportFindFreeTerminal(v, apc)) return; // airplane |
2549 | 1499 |
} |
1500 |
} else { // Else prepare for launch. |
|
0 | 1501 |
// 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
|
1502 |
v->u.air.state = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : TAKEOFF; |
0 | 1503 |
} |
1504 |
AircraftLeaveHangar(v); |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1505 |
AirportMove(v, apc); |
0 | 1506 |
} |
1507 |
||
1508 |
// 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
|
1509 |
static void AircraftEventHandler_AtTerminal(Vehicle *v, const AirportFTAClass *apc) |
0 | 1510 |
{ |
1511 |
// if we just arrived, execute EnterTerminal first |
|
1512 |
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
|
1513 |
AircraftEventHandler_EnterTerminal(v, apc); |
0 | 1514 |
// on an airport with helipads, a helicopter will always land there |
1515 |
// and get serviced at the same time - patch setting |
|
1516 |
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
|
1517 |
if (v->subtype == AIR_HELICOPTER && apc->helipads != NULL) { |
0 | 1518 |
// an exerpt of ServiceAircraft, without the invisibility stuff |
1519 |
v->date_of_last_service = _date; |
|
1520 |
v->breakdowns_since_last_service = 0; |
|
1926
530480d14685
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1901
diff
changeset
|
1521 |
v->reliability = GetEngine(v->engine_type)->reliability; |
0 | 1522 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
1523 |
} |
|
1524 |
} |
|
1525 |
return; |
|
1526 |
} |
|
1527 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1528 |
if (v->current_order.type == OT_NOTHING) return; |
0 | 1529 |
|
1530 |
// 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
|
1531 |
if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return; |
0 | 1532 |
|
1533 |
// airport-road is free. We either have to go to another airport, or to the hangar |
|
1534 |
// ---> start moving |
|
1535 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1536 |
switch (v->current_order.type) { |
0 | 1537 |
case OT_GOTO_STATION: // ready to fly to another airport |
1538 |
// 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
|
1539 |
v->u.air.state = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : TAKEOFF; |
0 | 1540 |
break; |
1541 |
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
|
1542 |
if (v->current_order.dest == v->u.air.targetairport) { |
0 | 1543 |
v->u.air.state = HANGAR; |
2639 | 1544 |
} 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
|
1545 |
v->u.air.state = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : TAKEOFF; |
2639 | 1546 |
} |
0 | 1547 |
break; |
1548 |
default: // orders have been deleted (no orders), goto depot and don't bother us |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1549 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1550 |
v->current_order.flags = 0; |
0 | 1551 |
v->u.air.state = HANGAR; |
1552 |
} |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1553 |
AirportMove(v, apc); |
0 | 1554 |
} |
1555 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1556 |
static void AircraftEventHandler_General(Vehicle *v, const AirportFTAClass *apc) |
0 | 1557 |
{ |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1558 |
assert("OK, you shouldn't be here, check your Airport Scheme!" && 0); |
0 | 1559 |
} |
1560 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1561 |
static void AircraftEventHandler_TakeOff(Vehicle *v, const AirportFTAClass *apc) { |
0 | 1562 |
PlayAircraftSound(v); // play takeoffsound for airplanes |
1563 |
v->u.air.state = STARTTAKEOFF; |
|
1564 |
} |
|
1565 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1566 |
static void AircraftEventHandler_StartTakeOff(Vehicle *v, const AirportFTAClass *apc) |
0 | 1567 |
{ |
1568 |
v->sprite_width = v->sprite_height = 24; // ??? no idea what this is |
|
1569 |
v->u.air.state = ENDTAKEOFF; |
|
1570 |
} |
|
1571 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1572 |
static void AircraftEventHandler_EndTakeOff(Vehicle *v, const AirportFTAClass *apc) |
0 | 1573 |
{ |
1574 |
v->u.air.state = FLYING; |
|
1575 |
// get the next position to go to, differs per airport |
|
1576 |
AircraftNextAirportPos_and_Order(v); |
|
1577 |
} |
|
1578 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1579 |
static void AircraftEventHandler_HeliTakeOff(Vehicle *v, const AirportFTAClass *apc) |
0 | 1580 |
{ |
2475 | 1581 |
const Player* p = GetPlayer(v->owner); |
0 | 1582 |
v->sprite_width = v->sprite_height = 24; // ??? no idea what this is |
1583 |
v->u.air.state = FLYING; |
|
1584 |
// get the next position to go to, differs per airport |
|
1585 |
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
|
1586 |
|
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
|
1587 |
// check if the aircraft needs to be replaced or renewed and send it to a hangar if needed |
4111
221355fcade6
(svn r5454) -Fix: [ 1394231 ] Autorenew glitch on helicopters
bjarni
parents:
4095
diff
changeset
|
1588 |
// unless it is due for renewal but the engine is no longer available |
2639 | 1589 |
if (v->owner == _local_player && ( |
2848 | 1590 |
EngineHasReplacementForPlayer(p, v->engine_type) || |
4111
221355fcade6
(svn r5454) -Fix: [ 1394231 ] Autorenew glitch on helicopters
bjarni
parents:
4095
diff
changeset
|
1591 |
((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
|
1592 |
HASBIT(GetEngine(v->engine_type)->player_avail, _local_player)) |
2639 | 1593 |
)) { |
1520
d88442095697
(svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents:
1401
diff
changeset
|
1594 |
_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
|
1595 |
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
|
1596 |
_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
|
1597 |
} |
0 | 1598 |
} |
1599 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1600 |
static void AircraftEventHandler_Flying(Vehicle *v, const AirportFTAClass *apc) |
0 | 1601 |
{ |
1602 |
Station *st; |
|
1603 |
byte landingtype; |
|
1604 |
AirportFTA *current; |
|
1605 |
uint16 tcur_speed, tsubspeed; |
|
1606 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1607 |
st = GetStation(v->u.air.targetairport); |
0 | 1608 |
// flying device is accepted at this station |
1609 |
// small airport --> no helicopters (AIRCRAFT_ONLY) |
|
1610 |
// all other airports --> all types of flying devices (ALL) |
|
1611 |
// heliport/oilrig, etc --> no airplanes (HELICOPTERS_ONLY) |
|
1612 |
// runway busy or not allowed to use this airstation, circle |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1613 |
if (v->subtype != apc->acc_planes && |
2639 | 1614 |
st->airport_tile != 0 && |
1615 |
(st->owner == OWNER_NONE || st->owner == v->owner)) { |
|
0 | 1616 |
// {32,FLYING,NOTHING_block,37}, {32,LANDING,N,33}, {32,HELILANDING,N,41}, |
1617 |
// if it is an airplane, look for LANDING, for helicopter HELILANDING |
|
1618 |
// it is possible to choose from multiple landing runways, so loop until a free one is found |
|
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
|
1619 |
landingtype = (v->subtype == AIR_HELICOPTER) ? HELILANDING : LANDING; |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1620 |
current = apc->layout[v->u.air.pos].next; |
0 | 1621 |
while (current != NULL) { |
1622 |
if (current->heading == landingtype) { |
|
1623 |
// save speed before, since if AirportHasBlock is false, it resets them to 0 |
|
1624 |
// we don't want that for plane in air |
|
1625 |
// hack for speed thingie |
|
1626 |
tcur_speed = v->cur_speed; |
|
1627 |
tsubspeed = v->subspeed; |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1628 |
if (!AirportHasBlock(v, current, apc)) { |
0 | 1629 |
v->u.air.state = landingtype; // LANDING / HELILANDING |
1630 |
// it's a bit dirty, but I need to set position to next position, otherwise |
|
1631 |
// if there are multiple runways, plane won't know which one it took (because |
|
1632 |
// they all have heading LANDING). And also occupy that block! |
|
1633 |
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
|
1634 |
SETBITS(st->airport_flags, apc->layout[v->u.air.pos].block); |
0 | 1635 |
return; |
1636 |
} |
|
1637 |
v->cur_speed = tcur_speed; |
|
1638 |
v->subspeed = tsubspeed; |
|
1639 |
} |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1640 |
current = current->next; |
0 | 1641 |
} |
1642 |
} |
|
1643 |
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
|
1644 |
v->u.air.pos = apc->layout[v->u.air.pos].next_position; |
0 | 1645 |
} |
1646 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1647 |
static void AircraftEventHandler_Landing(Vehicle *v, const AirportFTAClass *apc) |
0 | 1648 |
{ |
2475 | 1649 |
const Player* p = GetPlayer(v->owner); |
0 | 1650 |
AircraftLandAirplane(v); // maybe crash airplane |
1651 |
v->u.air.state = ENDLANDING; |
|
1195
54d50ac3311a
(svn r1699) - Feature [autoreplace] a plane will now go to the hangar right after landing if it needs to be replaced
bjarni
parents:
1194
diff
changeset
|
1652 |
// check if the aircraft needs to be replaced or renewed and send it to a hangar if needed |
54d50ac3311a
(svn r1699) - Feature [autoreplace] a plane will now go to the hangar right after landing if it needs to be replaced
bjarni
parents:
1194
diff
changeset
|
1653 |
if (v->current_order.type != OT_GOTO_DEPOT && v->owner == _local_player) { |
54d50ac3311a
(svn r1699) - Feature [autoreplace] a plane will now go to the hangar right after landing if it needs to be replaced
bjarni
parents:
1194
diff
changeset
|
1654 |
// only the vehicle owner needs to calculate the rest (locally) |
2848 | 1655 |
if (EngineHasReplacementForPlayer(p, v->engine_type) || |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2244
diff
changeset
|
1656 |
(p->engine_renew && v->age - v->max_age > (p->engine_renew_months * 30))) { |
4412
cae52239a576
(svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents:
4389
diff
changeset
|
1657 |
// 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
|
1658 |
_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
|
1659 |
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
|
1660 |
_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
|
1661 |
} |
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
|
1662 |
} |
0 | 1663 |
} |
1664 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1665 |
static void AircraftEventHandler_HeliLanding(Vehicle *v, const AirportFTAClass *apc) |
0 | 1666 |
{ |
1667 |
AircraftLand(v); // helicopters don't crash |
|
1668 |
v->u.air.state = HELIENDLANDING; |
|
1669 |
} |
|
1670 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1671 |
static void AircraftEventHandler_EndLanding(Vehicle *v, const AirportFTAClass *apc) |
0 | 1672 |
{ |
1673 |
// 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
|
1674 |
if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return; |
0 | 1675 |
|
1676 |
// if going to terminal (OT_GOTO_STATION) choose one |
|
1677 |
// 1. in case all terminals are busy AirportFindFreeTerminal() returns false or |
|
1678 |
// 2. not going for terminal (but depot, no order), |
|
1679 |
// --> get out of the way to the hangar. |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1680 |
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
|
1681 |
if (AirportFindFreeTerminal(v, apc)) return; |
0 | 1682 |
} |
1683 |
v->u.air.state = HANGAR; |
|
1684 |
||
1685 |
} |
|
1686 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1687 |
static void AircraftEventHandler_HeliEndLanding(Vehicle *v, const AirportFTAClass *apc) |
0 | 1688 |
{ |
1689 |
// 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
|
1690 |
if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return; |
0 | 1691 |
|
1692 |
// if going to helipad (OT_GOTO_STATION) choose one. If airport doesn't have helipads, choose terminal |
|
1693 |
// 1. in case all terminals/helipads are busy (AirportFindFreeHelipad() returns false) or |
|
1694 |
// 2. not going for terminal (but depot, no order), |
|
1695 |
// --> get out of the way to the hangar IF there are terminals on the airport. |
|
1696 |
// --> else TAKEOFF |
|
1697 |
// the reason behind this is that if an airport has a terminal, it also has a hangar. Airplanes |
|
1698 |
// must go to a hangar. |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1699 |
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
|
1700 |
if (AirportFindFreeHelipad(v, apc)) return; |
0 | 1701 |
} |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1702 |
v->u.air.state = (apc->nof_depots != 0) ? HANGAR : HELITAKEOFF; |
0 | 1703 |
} |
1704 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1705 |
typedef void AircraftStateHandler(Vehicle *v, const AirportFTAClass *apc); |
0 | 1706 |
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
|
1707 |
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
|
1708 |
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
|
1709 |
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
|
1710 |
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
|
1711 |
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
|
1712 |
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
|
1713 |
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
|
1714 |
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
|
1715 |
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
|
1716 |
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
|
1717 |
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
|
1718 |
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
|
1719 |
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
|
1720 |
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
|
1721 |
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
|
1722 |
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
|
1723 |
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
|
1724 |
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
|
1725 |
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
|
1726 |
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
|
1727 |
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
|
1728 |
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
|
1729 |
AircraftEventHandler_AtTerminal, // HELIPAD4 = 22 |
0 | 1730 |
}; |
1731 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1732 |
static void AirportClearBlock(const Vehicle *v, const AirportFTAClass *apc) |
0 | 1733 |
{ |
1734 |
// 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
|
1735 |
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
|
1736 |
Station *st = GetStation(v->u.air.targetairport); |
2639 | 1737 |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1738 |
CLRBITS(st->airport_flags, apc->layout[v->u.air.previous_pos].block); |
0 | 1739 |
} |
1740 |
} |
|
1741 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1742 |
static void AirportGoToNextPosition(Vehicle *v, const AirportFTAClass *apc) |
0 | 1743 |
{ |
1744 |
// if aircraft is not in position, wait until it is |
|
2549 | 1745 |
if (!AircraftController(v)) return; |
0 | 1746 |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1747 |
AirportClearBlock(v, apc); |
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1748 |
AirportMove(v, apc); // move aircraft to next position |
0 | 1749 |
} |
1750 |
||
1751 |
// 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
|
1752 |
static bool AirportMove(Vehicle *v, const AirportFTAClass *apc) |
0 | 1753 |
{ |
1754 |
AirportFTA *current; |
|
1755 |
byte prev_pos; |
|
1756 |
||
1757 |
// error handling |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1758 |
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
|
1759 |
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
|
1760 |
assert(v->u.air.pos < apc->nofelements); |
0 | 1761 |
} |
1762 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1763 |
current = &apc->layout[v->u.air.pos]; |
0 | 1764 |
// we have arrived in an important state (eg terminal, hangar, etc.) |
1765 |
if (current->heading == v->u.air.state) { |
|
1766 |
prev_pos = v->u.air.pos; // location could be changed in state, so save it before-hand |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1767 |
_aircraft_state_handlers[v->u.air.state](v, apc); |
2549 | 1768 |
if (v->u.air.state != FLYING) v->u.air.previous_pos = prev_pos; |
0 | 1769 |
return true; |
1770 |
} |
|
1771 |
||
1772 |
v->u.air.previous_pos = v->u.air.pos; // save previous location |
|
1773 |
||
1774 |
// 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
|
1775 |
if (current->next == NULL) { |
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1776 |
if (AirportSetBlocks(v, current, apc)) { |
0 | 1777 |
v->u.air.pos = current->next_position; |
1778 |
} // move to next position |
|
3579
4a55e8ce3087
(svn r4465) -Codechange (FS#60): Remove a variable no one really needs. (DaleStan)
celestar
parents:
3491
diff
changeset
|
1779 |
return false; |
0 | 1780 |
} |
1781 |
||
1782 |
// there are more choices to choose from, choose the one that |
|
1783 |
// matches our heading |
|
1784 |
do { |
|
1785 |
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
|
1786 |
if (AirportSetBlocks(v, current, apc)) { |
2639 | 1787 |
v->u.air.pos = current->next_position; |
1788 |
} // move to next position |
|
3579
4a55e8ce3087
(svn r4465) -Codechange (FS#60): Remove a variable no one really needs. (DaleStan)
celestar
parents:
3491
diff
changeset
|
1789 |
return false; |
0 | 1790 |
} |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1791 |
current = current->next; |
0 | 1792 |
} while (current != NULL); |
1793 |
||
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1794 |
DEBUG(misc, 0, "[Ap] cannot move further on Airport! (pos %d state %d)", v->u.air.pos, v->u.air.state); |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1795 |
DEBUG(misc, 0, "[Ap] airport entry point: %d, Vehicle: %d", apc->entry_point, v->index); |
0 | 1796 |
assert(0); |
1797 |
return false; |
|
1798 |
} |
|
1799 |
||
1800 |
// 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
|
1801 |
static bool AirportHasBlock(Vehicle *v, const AirportFTA *current_pos, const AirportFTAClass *apc) |
0 | 1802 |
{ |
4843
4bef85baee3f
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
1803 |
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
|
1804 |
const AirportFTA *next = &apc->layout[current_pos->next_position]; |
0 | 1805 |
|
1806 |
// 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
|
1807 |
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
|
1808 |
const Station *st = GetStation(v->u.air.targetairport); |
2630 | 1809 |
uint32 airport_flags = next->block; |
1810 |
||
0 | 1811 |
// check additional possible extra blocks |
1812 |
if (current_pos != reference && current_pos->block != NOTHING_block) { |
|
1813 |
airport_flags |= current_pos->block; |
|
1814 |
} |
|
1815 |
||
1816 |
if (HASBITS(st->airport_flags, airport_flags)) { |
|
1817 |
v->cur_speed = 0; |
|
1818 |
v->subspeed = 0; |
|
1819 |
return true; |
|
1820 |
} |
|
1821 |
} |
|
1822 |
return false; |
|
1823 |
} |
|
1824 |
||
1825 |
// returns true on success. Eg, next block was free and we have occupied it |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1826 |
static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *apc) |
0 | 1827 |
{ |
4843
4bef85baee3f
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
1828 |
AirportFTA *next = &apc->layout[current_pos->next_position]; |
4bef85baee3f
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
1829 |
AirportFTA *reference = &apc->layout[v->u.air.pos]; |
0 | 1830 |
|
1831 |
// 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
|
1832 |
if ((apc->layout[current_pos->position].block & next->block) != next->block) { |
2639 | 1833 |
uint32 airport_flags = next->block; |
1834 |
Station* st = GetStation(v->u.air.targetairport); |
|
0 | 1835 |
//search for all all elements in the list with the same state, and blocks != N |
1836 |
// this means more blocks should be checked/set |
|
4843
4bef85baee3f
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
1837 |
AirportFTA *current = current_pos; |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1838 |
if (current == reference) current = current->next; |
0 | 1839 |
while (current != NULL) { |
1840 |
if (current->heading == current_pos->heading && current->block != 0) { |
|
1841 |
airport_flags |= current->block; |
|
1842 |
break; |
|
1843 |
} |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1844 |
current = current->next; |
0 | 1845 |
}; |
1846 |
||
1847 |
// if the block to be checked is in the next position, then exclude that from |
|
1848 |
// checking, because it has been set by the airplane before |
|
2549 | 1849 |
if (current_pos->block == next->block) airport_flags ^= next->block; |
0 | 1850 |
|
1851 |
if (HASBITS(st->airport_flags, airport_flags)) { |
|
1852 |
v->cur_speed = 0; |
|
1853 |
v->subspeed = 0; |
|
1854 |
return false; |
|
1855 |
} |
|
1856 |
||
1857 |
if (next->block != NOTHING_block) { |
|
1858 |
SETBITS(st->airport_flags, airport_flags); // occupy next block |
|
1859 |
} |
|
1860 |
} |
|
1861 |
return true; |
|
1862 |
} |
|
1863 |
||
1864 |
static bool FreeTerminal(Vehicle *v, byte i, byte last_terminal) |
|
1865 |
{ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1866 |
Station *st = GetStation(v->u.air.targetairport); |
0 | 1867 |
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
|
1868 |
if (!HASBIT(st->airport_flags, _airport_terminal_flag[i])) { |
0 | 1869 |
// TERMINAL# HELIPAD# |
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4056
diff
changeset
|
1870 |
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
|
1871 |
SETBIT(st->airport_flags, _airport_terminal_flag[i]); // occupy terminal/helipad |
0 | 1872 |
return true; |
1873 |
} |
|
1874 |
} |
|
1875 |
return false; |
|
1876 |
} |
|
1877 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1878 |
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
|
1879 |
{ |
2639 | 1880 |
uint num = 0; |
1881 |
uint i; |
|
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
1882 |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1883 |
for (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
|
1884 |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1885 |
return num; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1886 |
} |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1887 |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1888 |
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *apc) |
0 | 1889 |
{ |
1890 |
/* example of more terminalgroups |
|
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4546
diff
changeset
|
1891 |
* {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
|
1892 |
* 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
|
1893 |
* 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
|
1894 |
* 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
|
1895 |
* 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
|
1896 |
* 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
|
1897 |
* 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
|
1898 |
* 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
|
1899 |
*/ |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1900 |
if (apc->terminals[0] > 1) { |
4843
4bef85baee3f
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
1901 |
Station *st = GetStation(v->u.air.targetairport); |
4bef85baee3f
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
1902 |
AirportFTA *temp = apc->layout[v->u.air.pos].next; |
4bef85baee3f
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
1903 |
|
0 | 1904 |
while (temp != NULL) { |
1905 |
if (temp->heading == 255) { |
|
1906 |
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
|
1907 |
int target_group; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1908 |
int i; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1909 |
int group_start = 0; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1910 |
int group_end; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1911 |
|
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1912 |
//read which group do we want to go to? |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1913 |
//(the first free group) |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1914 |
target_group = temp->next_position + 1; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1915 |
|
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1916 |
//at what terminal does the group start? |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1917 |
//that means, sum up all terminals of |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1918 |
//groups with lower number |
2549 | 1919 |
for (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
|
1920 |
group_start += apc->terminals[i]; |
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1921 |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1922 |
group_end = group_start + apc->terminals[target_group]; |
2549 | 1923 |
if (FreeTerminal(v, group_start, group_end)) return true; |
0 | 1924 |
} |
2549 | 1925 |
} else { |
1926 |
/* once the heading isn't 255, we've exhausted the possible blocks. |
|
1927 |
* So we cannot move */ |
|
1928 |
return false; |
|
0 | 1929 |
} |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1930 |
temp = temp->next; |
0 | 1931 |
} |
1932 |
} |
|
1933 |
||
1934 |
// 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
|
1935 |
return FreeTerminal(v, 0, GetNumTerminals(apc)); |
0 | 1936 |
} |
1937 |
||
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1938 |
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
|
1939 |
{ |
2639 | 1940 |
uint num = 0; |
1941 |
uint i; |
|
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
1942 |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1943 |
for (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
|
1944 |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1945 |
return num; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1946 |
} |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1947 |
|
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1948 |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1949 |
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *apc) |
0 | 1950 |
{ |
1951 |
// 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
|
1952 |
if (apc->helipads == NULL) return AirportFindFreeTerminal(v, apc); |
0 | 1953 |
|
1954 |
// 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
|
1955 |
if (apc->helipads[0] > 1) { |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4072
diff
changeset
|
1956 |
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
|
1957 |
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
|
1958 |
|
0 | 1959 |
while (temp != NULL) { |
1960 |
if (temp->heading == 255) { |
|
1961 |
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
|
1962 |
int target_group; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1963 |
int i; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1964 |
int group_start = 0; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1965 |
int group_end; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1966 |
|
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1967 |
//read which group do we want to go to? |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1968 |
//(the first free group) |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1969 |
target_group = temp->next_position + 1; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1970 |
|
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1971 |
//at what terminal does the group start? |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1972 |
//that means, sum up all terminals of |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1973 |
//groups with lower number |
2952 | 1974 |
for (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
|
1975 |
group_start += apc->helipads[i]; |
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1976 |
|
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1977 |
group_end = group_start + apc->helipads[target_group]; |
2549 | 1978 |
if (FreeTerminal(v, group_start, group_end)) return true; |
0 | 1979 |
} |
2549 | 1980 |
} else { |
1981 |
/* once the heading isn't 255, we've exhausted the possible blocks. |
|
1982 |
* So we cannot move */ |
|
1983 |
return false; |
|
0 | 1984 |
} |
4842
79c4c9167d93
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents:
4739
diff
changeset
|
1985 |
temp = temp->next; |
0 | 1986 |
} |
2549 | 1987 |
} else { |
1988 |
// only 1 helicoptergroup, check all helipads |
|
1989 |
// 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
|
1990 |
return FreeTerminal(v, MAX_TERMINALS, GetNumHelipads(apc) + MAX_TERMINALS); |
0 | 1991 |
} |
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
|
1992 |
return false; // it shouldn't get here anytime, but just to be sure |
0 | 1993 |
} |
1994 |
||
1995 |
static void AircraftEventHandler(Vehicle *v, int loop) |
|
1996 |
{ |
|
1997 |
v->tick_counter++; |
|
1998 |
||
1999 |
if (v->vehstatus & VS_CRASHED) { |
|
2000 |
HandleCrashedAircraft(v); |
|
2001 |
return; |
|
2002 |
} |
|
2003 |
||
2639 | 2004 |
if (v->vehstatus & VS_STOPPED) return; |
0 | 2005 |
|
2006 |
/* aircraft is broken down? */ |
|
2007 |
if (v->breakdown_ctr != 0) { |
|
2008 |
if (v->breakdown_ctr <= 2) { |
|
2009 |
HandleBrokenAircraft(v); |
|
2010 |
} else { |
|
2011 |
v->breakdown_ctr--; |
|
2012 |
} |
|
2013 |
} |
|
2014 |
||
2015 |
HandleAircraftSmoke(v); |
|
2016 |
ProcessAircraftOrder(v); |
|
2017 |
HandleAircraftLoading(v, loop); |
|
2018 |
||
2639 | 2019 |
if (v->current_order.type >= OT_LOADING) return; |
0 | 2020 |
|
2021 |
// pass the right airport structure to the functions |
|
2022 |
// DEREF_STATION gets target airport (Station *st), its type is passed to GetAirport |
|
2023 |
// that returns the correct layout depending on type |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2024 |
AirportGoToNextPosition(v, GetAirport(GetStation(v->u.air.targetairport)->airport_type)); |
0 | 2025 |
} |
2026 |
||
2027 |
void Aircraft_Tick(Vehicle *v) |
|
2028 |
{ |
|
2029 |
int i; |
|
2030 |
||
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
|
2031 |
if (!IsNormalAircraft(v)) return; |
0 | 2032 |
|
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
|
2033 |
if (v->subtype == AIR_HELICOPTER) HelicopterTickHandler(v); |
0 | 2034 |
|
2035 |
AgeAircraftCargo(v); |
|
2036 |
||
2639 | 2037 |
for (i = 0; i != 6; i++) { |
0 | 2038 |
AircraftEventHandler(v, i); |
2039 |
if (v->type != VEH_Aircraft) // In case it was deleted |
|
2040 |
break; |
|
2041 |
} |
|
2042 |
} |
|
2043 |
||
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2044 |
|
0 | 2045 |
// need to be called to load aircraft from old version |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1064
diff
changeset
|
2046 |
void UpdateOldAircraft(void) |
0 | 2047 |
{ |
2048 |
Station *st; |
|
2049 |
Vehicle *v_oldstyle; |
|
2050 |
GetNewVehiclePosResult gp; |
|
2051 |
||
2052 |
// set airport_flags to 0 for all airports just to be sure |
|
2053 |
FOR_ALL_STATIONS(st) { |
|
2054 |
st->airport_flags = 0; // reset airport |
|
2055 |
} |
|
2056 |
||
2057 |
FOR_ALL_VEHICLES(v_oldstyle) { |
|
2058 |
// airplane has another vehicle with subtype 4 (shadow), helicopter also has 3 (rotor) |
|
2059 |
// skip those |
|
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
|
2060 |
if (v_oldstyle->type == VEH_Aircraft && IsNormalAircraft(v_oldstyle)) { |
0 | 2061 |
// airplane in terminal stopped doesn't hurt anyone, so goto next |
2639 | 2062 |
if (v_oldstyle->vehstatus & VS_STOPPED && v_oldstyle->u.air.state == 0) { |
0 | 2063 |
v_oldstyle->u.air.state = HANGAR; |
2064 |
continue; |
|
2065 |
} |
|
2066 |
||
2067 |
AircraftLeaveHangar(v_oldstyle); // make airplane visible if it was in a depot for example |
|
2068 |
v_oldstyle->vehstatus &= ~VS_STOPPED; // make airplane moving |
|
2069 |
v_oldstyle->u.air.state = FLYING; |
|
2070 |
AircraftNextAirportPos_and_Order(v_oldstyle); // move it to the entry point of the airport |
|
2071 |
GetNewVehiclePos(v_oldstyle, &gp); // get the position of the plane (to be used for setting) |
|
2072 |
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
|
2073 |
|
0 | 2074 |
// 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
|
2075 |
if (v_oldstyle->subtype == AIR_HELICOPTER) v_oldstyle->next->next->cur_speed = 32; |
0 | 2076 |
|
2077 |
// set new position x,y,z |
|
2078 |
SetAircraftPosition(v_oldstyle, gp.x, gp.y, GetAircraftFlyingAltitude(v_oldstyle)); |
|
2079 |
} |
|
2080 |
} |
|
2081 |
} |
|
2082 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2083 |
void UpdateAirplanesOnNewStation(Station *st) |
0 | 2084 |
{ |
2085 |
GetNewVehiclePosResult gp; |
|
2086 |
Vehicle *v; |
|
2087 |
byte takeofftype; |
|
2088 |
uint16 cnt; |
|
2089 |
// only 1 station is updated per function call, so it is enough to get entry_point once |
|
2090 |
const AirportFTAClass *ap = GetAirport(st->airport_type); |
|
2091 |
FOR_ALL_VEHICLES(v) { |
|
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
|
2092 |
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
|
2093 |
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
|
2094 |
/* update position of airplane. If plane is not flying, landing, or taking off |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4412
diff
changeset
|
2095 |
*you cannot delete airport, so it doesn't matter |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4412
diff
changeset
|
2096 |
*/ |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4412
diff
changeset
|
2097 |
if (v->u.air.state >= FLYING) { // circle around |
0 | 2098 |
v->u.air.pos = v->u.air.previous_pos = ap->entry_point; |
2099 |
v->u.air.state = FLYING; |
|
2100 |
// landing plane needs to be reset to flying height (only if in pause mode upgrade, |
|
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
|
2101 |
// in normal mode, plane is reset in AircraftController. It doesn't hurt for FLYING |
0 | 2102 |
GetNewVehiclePos(v, &gp); |
2103 |
// set new position x,y,z |
|
2104 |
SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v)); |
|
2549 | 2105 |
} else { |
0 | 2106 |
assert(v->u.air.state == ENDTAKEOFF || v->u.air.state == 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
|
2107 |
takeofftype = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : ENDTAKEOFF; |
0 | 2108 |
// search in airportdata for that heading |
2109 |
// easiest to do, since this doesn't happen a lot |
|
2110 |
for (cnt = 0; cnt < ap->nofelements; cnt++) { |
|
2111 |
if (ap->layout[cnt].heading == takeofftype) { |
|
2112 |
v->u.air.pos = ap->layout[cnt].position; |
|
2113 |
break; |
|
2114 |
} |
|
2115 |
} |
|
2116 |
} |
|
2117 |
} |
|
2118 |
} |
|
2119 |
} |
|
2120 |
} |