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