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