author | Darkvater |
Tue, 22 Feb 2005 19:38:44 +0000 | |
changeset 1401 | 56d372a75b74 |
parent 1359 | 8ba976aed634 |
child 1520 | c85dc79795e0 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1282
diff
changeset
|
3 |
#include "debug.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
458
diff
changeset
|
4 |
#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
|
5 |
#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
|
6 |
#include "tile.h" |
0 | 7 |
#include "vehicle.h" |
8 |
#include "engine.h" |
|
9 |
#include "command.h" |
|
10 |
#include "station.h" |
|
11 |
#include "news.h" |
|
12 |
#include "gfx.h" |
|
337
66647f97e7c0
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
13 |
#include "sound.h" |
0 | 14 |
#include "player.h" |
15 |
#include "airport.h" |
|
16 |
||
17 |
static bool AirportMove(Vehicle *v, const AirportFTAClass *Airport); |
|
18 |
static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport); |
|
19 |
static bool AirportHasBlock(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport); |
|
20 |
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport); |
|
21 |
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport); |
|
22 |
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
|
23 |
static void CrashAirplane(Vehicle *v); |
0 | 24 |
|
25 |
static void AircraftNextAirportPos_and_Order(Vehicle *v); |
|
26 |
static byte GetAircraftFlyingAltitude(const Vehicle *v); |
|
27 |
||
28 |
static const SpriteID _aircraft_sprite[] = { |
|
29 |
0x0EB5, 0x0EBD, 0x0EC5, 0x0ECD, |
|
30 |
0x0ED5, 0x0EDD, 0x0E9D, 0x0EA5, |
|
31 |
0x0EAD, 0x0EE5, 0x0F05, 0x0F0D, |
|
32 |
0x0F15, 0x0F1D, 0x0F25, 0x0F2D, |
|
33 |
0x0EED, 0x0EF5, 0x0EFD, 0x0F35, |
|
34 |
0x0E9D, 0x0EA5, 0x0EAD, 0x0EB5, |
|
35 |
0x0EBD, 0x0EC5 |
|
36 |
}; |
|
37 |
||
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
|
38 |
// use this to find the nearest hangar to 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
|
39 |
// bit 16 is set in the return value if the player do not have any airports with a hangar (like helipads only) |
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
|
40 |
static uint32 FindNearestHangar(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
|
41 |
{ |
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
|
42 |
Station *st; |
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
|
43 |
uint temp_distance, distance = 0xFFFF; |
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
|
44 |
uint16 index_to_target = 0; |
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
|
45 |
|
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
|
46 |
FOR_ALL_STATIONS(st) { |
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 |
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
|
48 |
if (GetAirport(st->airport_type)->terminals != NULL) { |
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
|
49 |
// don't crash the planes if we know they can't land at the airport |
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
|
50 |
if (HASBIT(v->subtype,1) && st->airport_type == AT_SMALL && !_cheats.no_jetcrash.value) continue; |
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
|
51 |
|
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1238
diff
changeset
|
52 |
temp_distance = DistanceSquare(v->tile, st->airport_tile); |
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
|
53 |
if (temp_distance < distance) { |
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
|
54 |
distance = temp_distance; |
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
|
55 |
index_to_target = st->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
|
56 |
} |
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
|
57 |
} |
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
|
58 |
} |
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
|
59 |
} |
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
|
60 |
if (distance == 65000) |
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
|
61 |
SETBIT(index_to_target, 16); |
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
|
62 |
return index_to_target; |
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
|
63 |
} |
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
|
64 |
|
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
|
65 |
// 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
|
66 |
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
|
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 |
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
|
69 |
|
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 |
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
|
71 |
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
|
72 |
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
|
73 |
// 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
|
74 |
// 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
|
75 |
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
|
76 |
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
|
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 |
} |
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 |
|
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 |
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
|
81 |
} |
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 |
|
0 | 83 |
int GetAircraftImage(Vehicle *v, byte direction) |
84 |
{ |
|
85 |
int spritenum = v->spritenum; |
|
86 |
||
87 |
if (is_custom_sprite(spritenum)) { |
|
88 |
int sprite = GetCustomVehicleSprite(v, direction); |
|
89 |
||
90 |
if (sprite) return sprite; |
|
91 |
spritenum = _engine_original_sprites[v->engine_type]; |
|
92 |
} |
|
93 |
return direction + _aircraft_sprite[spritenum]; |
|
94 |
} |
|
95 |
||
96 |
void DrawAircraftEngine(int x, int y, int engine, uint32 image_ormod) |
|
97 |
{ |
|
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
98 |
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
|
99 |
int sprite = (6 + _aircraft_sprite[spritenum]); |
0 | 100 |
|
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
|
101 |
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
|
102 |
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
|
103 |
if (!sprite) |
a2036275549e
(svn r1704) - Fix: [newgrf] rotors of custom helicopters are displayed correctly in the hangar window
dominik
parents:
1197
diff
changeset
|
104 |
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
|
105 |
} |
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
|
106 |
|
1200
a2036275549e
(svn r1704) - Fix: [newgrf] rotors of custom helicopters are displayed correctly in the hangar window
dominik
parents:
1197
diff
changeset
|
107 |
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
|
108 |
|
1200
a2036275549e
(svn r1704) - Fix: [newgrf] rotors of custom helicopters are displayed correctly in the hangar window
dominik
parents:
1197
diff
changeset
|
109 |
if ((AircraftVehInfo(engine)->subtype & 1) == 0) { |
0 | 110 |
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
|
111 |
} |
0 | 112 |
} |
113 |
||
114 |
void DrawAircraftEngineInfo(int engine, int x, int y, int maxw) |
|
115 |
{ |
|
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
116 |
const AircraftVehicleInfo *avi = AircraftVehInfo(engine); |
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
117 |
SetDParam(0, ((_price.aircraft_base >> 3) * avi->base_cost) >> 5); |
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
118 |
SetDParam(1, avi->max_speed << 3); |
922
fc040662bd43
(svn r1410) Replaced all occurences of 'passanger' by 'passenger' in the code
celestar
parents:
919
diff
changeset
|
119 |
SetDParam(2, 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
|
120 |
SetDParam(3, avi->mail_capacity); |
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
121 |
SetDParam(4, avi->running_cost * _price.aircraft_running >> 8); |
0 | 122 |
|
123 |
DrawStringMultiCenter(x, y, STR_A02E_COST_MAX_SPEED_CAPACITY, maxw); |
|
124 |
} |
|
125 |
||
126 |
/* Allocate many vehicles */ |
|
410 | 127 |
static bool AllocateVehicles(Vehicle **vl, int num) |
0 | 128 |
{ |
129 |
int i; |
|
130 |
Vehicle *v; |
|
131 |
bool success = true; |
|
132 |
||
133 |
for(i=0; i!=num; i++) { |
|
134 |
vl[i] = v = AllocateVehicle(); |
|
135 |
if (v == NULL) { |
|
136 |
success = false; |
|
137 |
break; |
|
138 |
} |
|
139 |
v->type = 1; |
|
140 |
} |
|
141 |
||
142 |
while (--i >= 0) { |
|
143 |
vl[i]->type = 0; |
|
144 |
} |
|
145 |
||
146 |
return success; |
|
147 |
} |
|
148 |
||
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
149 |
int32 EstimateAircraftCost(uint16 engine_type) |
0 | 150 |
{ |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
151 |
return AircraftVehInfo(engine_type)->base_cost * (_price.aircraft_base>>3)>>5; |
0 | 152 |
} |
153 |
||
154 |
||
155 |
/* p1 = engine */ |
|
156 |
int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
157 |
{ |
|
158 |
int32 value; |
|
159 |
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
|
160 |
UnitID unit_num; |
0 | 161 |
uint tile = TILE_FROM_XY(x,y); |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
162 |
const AircraftVehicleInfo *avi = AircraftVehInfo(p1); |
0 | 163 |
Engine *e; |
164 |
||
1197 | 165 |
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
|
166 |
|
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
|
167 |
// Workaround: TODO: make AI players try to build planes in a hangar instead of just an airport tile. |
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 |
if (!IsAircraftHangarTile((TileIndex)tile) && IS_HUMAN_PLAYER(_current_player)) return CMD_ERROR; |
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
|
169 |
|
1238
f546fcc6b0c9
(svn r1742) - Fix: fixed bug introduced in r1730 where AI players had problems when building aircrafts
bjarni
parents:
1237
diff
changeset
|
170 |
if (_map_owner[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
|
171 |
|
0 | 172 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
173 |
||
174 |
value = EstimateAircraftCost(p1); |
|
175 |
||
176 |
if (flags & DC_QUERY_COST) |
|
177 |
return value; |
|
178 |
||
179 |
// 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
|
180 |
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
|
181 |
IsOrderPoolFull()) |
0 | 182 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
183 |
||
184 |
unit_num = GetFreeUnitNumber(VEH_Aircraft); |
|
185 |
if (unit_num > _patches.max_aircraft) |
|
186 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
|
187 |
||
188 |
if (flags & DC_EXEC) { |
|
189 |
v = vl[0]; |
|
190 |
u = vl[1]; |
|
191 |
||
192 |
v->unitnumber = unit_num; |
|
193 |
v->type = u->type = VEH_Aircraft; |
|
194 |
v->direction = 3; |
|
195 |
||
196 |
v->owner = u->owner = _current_player; |
|
197 |
||
198 |
v->tile = tile; |
|
199 |
// u->tile = 0; |
|
200 |
||
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
|
201 |
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
|
202 |
y = TileY(tile) * 16 + 3; |
0 | 203 |
|
204 |
v->x_pos = u->x_pos = x; |
|
205 |
v->y_pos = u->y_pos = y; |
|
206 |
||
207 |
u->z_pos = GetSlopeZ(x, y); |
|
208 |
v->z_pos = u->z_pos + 1; |
|
209 |
||
210 |
v->x_offs = v->y_offs = -1; |
|
211 |
// u->delta_x = u->delta_y = 0; |
|
212 |
||
213 |
v->sprite_width = v->sprite_height = 2; |
|
214 |
v->z_height = 5; |
|
215 |
||
216 |
u->sprite_width = u->sprite_height = 2; |
|
217 |
u->z_height = 1; |
|
218 |
||
219 |
v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL; |
|
220 |
u->vehstatus = VS_HIDDEN | VS_UNCLICKABLE | VS_DISASTER; |
|
221 |
||
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
222 |
v->spritenum = avi->image_index; |
0 | 223 |
// v->cargo_count = u->number_of_pieces = 0; |
224 |
||
922
fc040662bd43
(svn r1410) Replaced all occurences of 'passanger' by 'passenger' in the code
celestar
parents:
919
diff
changeset
|
225 |
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
|
226 |
u->cargo_cap = avi->mail_capacity; |
0 | 227 |
|
228 |
v->cargo_type = CT_PASSENGERS; |
|
229 |
u->cargo_type = CT_MAIL; |
|
230 |
||
231 |
v->string_id = STR_SV_AIRCRAFT_NAME; |
|
232 |
// v->next_order_param = v->next_order = 0; |
|
233 |
||
234 |
// v->load_unload_time_rem = 0; |
|
235 |
// v->progress = 0; |
|
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1263
diff
changeset
|
236 |
v->last_station_visited = INVALID_STATION; |
0 | 237 |
// v->destination_coords = 0; |
238 |
||
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
239 |
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
|
240 |
v->acceleration = avi->acceleration; |
0 | 241 |
v->engine_type = (byte)p1; |
242 |
||
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
243 |
v->subtype = (avi->subtype & 1) == 0 ? 0 : 2; |
0 | 244 |
v->value = value; |
245 |
||
246 |
u->subtype = 4; |
|
247 |
||
248 |
e = &_engines[p1]; |
|
249 |
v->reliability = e->reliability; |
|
250 |
v->reliability_spd_dec = e->reliability_spd_dec; |
|
251 |
v->max_age = e->lifelength * 366; |
|
252 |
||
253 |
_new_aircraft_id = v->index; |
|
254 |
||
255 |
// the AI doesn't click on a tile to build airplanes, so the below code will |
|
256 |
// 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
|
257 |
// On hold for NewAI |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
76
diff
changeset
|
258 |
v->u.air.pos = (!_patches.ainew_active && _is_ai_player) ? 0:MAX_ELEMENTS; |
0 | 259 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
260 |
/* 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
|
261 |
its position in the array of depots the airport has.....we can search |
0 | 262 |
->layout for #th position of depot. Since layout must start with depots, it is simple |
263 |
*/ |
|
264 |
{ |
|
265 |
Station *st; |
|
266 |
const AirportFTAClass *Airport; |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
901
diff
changeset
|
267 |
const TileIndexDiffC *cur_depot; |
0 | 268 |
byte i = 0; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
269 |
st = GetStation(_map2[tile]); |
0 | 270 |
Airport = GetAirport(st->airport_type); |
699
02b8b9c9194f
(svn r1149) Fix hack which abuses first TileIndex of airport depot array as number of depots (similar change as in map branch)
tron
parents:
679
diff
changeset
|
271 |
for (cur_depot = Airport->airport_depots; i != Airport->nof_depots; cur_depot++) { |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
901
diff
changeset
|
272 |
if ((uint)(st->airport_tile + ToTileIndexDiff(*cur_depot)) == tile) { |
0 | 273 |
assert(Airport->layout[i].heading == HANGAR); |
274 |
v->u.air.pos = Airport->layout[i].position; |
|
275 |
break; |
|
276 |
} |
|
277 |
i++; |
|
278 |
} |
|
279 |
// to ensure v->u.air.pos has been given a value |
|
280 |
assert(v->u.air.pos != MAX_ELEMENTS); |
|
281 |
} |
|
282 |
||
283 |
v->u.air.state = HANGAR; |
|
284 |
v->u.air.previous_pos = v->u.air.pos; |
|
285 |
v->u.air.targetairport = _map2[tile]; |
|
286 |
v->next = u; |
|
287 |
||
288 |
v->service_interval = _patches.servint_aircraft; |
|
289 |
||
290 |
v->date_of_last_service = _date; |
|
291 |
v->build_year = _cur_year; |
|
292 |
||
293 |
v->cur_image = u->cur_image = 0xEA0; |
|
294 |
||
295 |
VehiclePositionChanged(v); |
|
296 |
VehiclePositionChanged(u); |
|
297 |
||
298 |
// Aircraft with 3 vehicles? |
|
299 |
if (v->subtype == 0) { |
|
300 |
w = vl[2]; |
|
301 |
||
302 |
u->next = w; |
|
303 |
||
304 |
w->type = VEH_Aircraft; |
|
305 |
w->direction = 0; |
|
306 |
w->owner = _current_player; |
|
307 |
w->x_pos = v->x_pos; |
|
308 |
w->y_pos = v->y_pos; |
|
309 |
w->z_pos = v->z_pos + 5; |
|
310 |
w->x_offs = w->y_offs = -1; |
|
311 |
w->sprite_width = w->sprite_height = 2; |
|
312 |
w->z_height = 1; |
|
313 |
w->vehstatus = VS_HIDDEN | VS_UNCLICKABLE; |
|
314 |
w->subtype = 6; |
|
315 |
w->cur_image = 0xF3D; |
|
316 |
VehiclePositionChanged(w); |
|
317 |
} |
|
318 |
||
319 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 320 |
RebuildVehicleLists(); |
0 | 321 |
InvalidateWindow(WC_COMPANY, v->owner); |
322 |
} |
|
323 |
||
1128
d3ffc98b92ad
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1093
diff
changeset
|
324 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Aircraft); //updates the replace Aircraft window |
d3ffc98b92ad
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1093
diff
changeset
|
325 |
|
0 | 326 |
return value; |
327 |
} |
|
328 |
||
329 |
bool IsAircraftHangarTile(TileIndex tile) |
|
330 |
{ |
|
331 |
// 0x56 - hangar facing other way international airport (86) |
|
332 |
// 0x20 - hangar large airport (32) |
|
333 |
// 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
|
334 |
return IsTileType(tile, MP_STATION) && |
0 | 335 |
(_map5[tile] == 32 || _map5[tile] == 65 || _map5[tile] == 86); |
336 |
} |
|
337 |
||
338 |
static bool CheckStoppedInHangar(Vehicle *v) |
|
339 |
{ |
|
340 |
if (!(v->vehstatus&VS_STOPPED) || |
|
341 |
!IsAircraftHangarTile(v->tile)) { |
|
342 |
_error_message = STR_A01B_AIRCRAFT_MUST_BE_STOPPED; |
|
343 |
return false; |
|
344 |
} |
|
345 |
||
346 |
return true; |
|
347 |
} |
|
348 |
||
349 |
||
410 | 350 |
static void DoDeleteAircraft(Vehicle *v) |
0 | 351 |
{ |
352 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
588 | 353 |
RebuildVehicleLists(); |
0 | 354 |
InvalidateWindow(WC_COMPANY, v->owner); |
355 |
DeleteVehicleChain(v); |
|
1055
3aae1d6f12aa
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
356 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 357 |
} |
358 |
||
359 |
// p1 = vehicle |
|
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 |
||
377 |
DoDeleteAircraft(v); |
|
378 |
||
379 |
} |
|
380 |
||
1128
d3ffc98b92ad
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1093
diff
changeset
|
381 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Aircraft); // updates the replace Aircraft window |
d3ffc98b92ad
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1093
diff
changeset
|
382 |
|
0 | 383 |
return -(int32)v->value; |
384 |
} |
|
385 |
||
386 |
// p1 = vehicle |
|
387 |
int32 CmdStartStopAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
388 |
{ |
|
389 |
Vehicle *v; |
|
390 |
||
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
|
391 |
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
|
392 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
393 |
v = GetVehicle(p1); |
0 | 394 |
|
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
|
395 |
if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) |
0 | 396 |
return CMD_ERROR; |
397 |
||
398 |
// cannot stop airplane when in flight, or when taking off / landing |
|
399 |
if (v->u.air.state >= STARTTAKEOFF) { |
|
400 |
return_cmd_error(STR_A017_AIRCRAFT_IS_IN_FLIGHT); |
|
401 |
} |
|
402 |
||
403 |
if (flags & DC_EXEC) { |
|
404 |
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
|
405 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 406 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
1055
3aae1d6f12aa
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
407 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 408 |
} |
409 |
||
410 |
return 0; |
|
411 |
} |
|
412 |
||
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
|
413 |
/* Send an aircraft to the hangar in the next station |
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
|
414 |
p1 = index of the aircraft |
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
|
415 |
p2 = bit 0..15 = index of station with hangar to use (only used if bit 17 is set) |
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
|
416 |
bit 16 = set v->set_for_replacement & do not stop in hangar |
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
|
417 |
bit 17 = goto the hangar in airport given in bit 0..15 instead of next stop |
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
|
418 |
bit 18 = clear v->set_for_replacement */ |
0 | 419 |
int32 CmdSendAircraftToHangar(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
420 |
{ |
|
421 |
Vehicle *v; |
|
422 |
Station *st; |
|
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
|
423 |
uint16 next_airport_index; |
0 | 424 |
|
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
|
425 |
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
|
426 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
427 |
v = GetVehicle(p1); |
0 | 428 |
|
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
|
429 |
if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) |
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
|
430 |
return CMD_ERROR; |
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
|
431 |
|
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
|
432 |
if (HASBIT(p2, 16)) v->set_for_replacement = true; //now all clients knows that the vehicle wants to be replaced |
1139
c63f257aa7fb
(svn r1640) fix: now helicopters will use a hangar in schedule to be replaced in, even if they are only set to service there. Since helicopters are serviced at helipads, they will only go there if they needs to be replaced or renewed.
bjarni
parents:
1135
diff
changeset
|
433 |
|
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
|
434 |
if (HASBIT(p2, 18)) { |
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
|
435 |
v->set_for_replacement = false; |
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
|
436 |
return CMD_ERROR; // no need to send aircraft to a depot. We just told that it don't have to anymore |
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
|
437 |
} |
0 | 438 |
|
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
|
439 |
if (v->current_order.type == OT_GOTO_DEPOT && p2 == 0) { |
0 | 440 |
if (flags & DC_EXEC) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
441 |
if (v->current_order.flags & OF_UNLOAD) v->cur_order_index++; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
442 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
443 |
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
|
444 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 445 |
} |
446 |
} 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
|
447 |
bool next_airport_has_hangar = true; |
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
|
448 |
next_airport_index = (HASBIT(p2, 17)) ? (int16)p2 : v->u.air.targetairport; |
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
|
449 |
st = GetStation(next_airport_index); |
0 | 450 |
// If an airport doesn't have terminals (so no landing space for airports), |
451 |
// it surely doesn't have any hangars |
|
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
|
452 |
if (st->xy == 0 || st->airport_tile == 0 || GetAirport(st->airport_type)->terminals == NULL) { |
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
|
453 |
if (p2 == 0) { |
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
|
454 |
// the aircraft have to search for a hangar on it's own |
1263
f1812befa312
(svn r1767) fixed mixed declarations and code in last commit (oops)
bjarni
parents:
1262
diff
changeset
|
455 |
uint32 temp = FindNearestHangar(v); |
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 |
next_airport_has_hangar = false; |
1263
f1812befa312
(svn r1767) fixed mixed declarations and code in last commit (oops)
bjarni
parents:
1262
diff
changeset
|
457 |
if (HASBIT(temp, 16)) return CMD_ERROR; // the player does not own a hangar |
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
|
458 |
st = GetStation(temp); |
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
|
459 |
next_airport_index = (uint16)temp; |
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 |
} else { |
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
|
461 |
return CMD_ERROR; |
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
|
462 |
} |
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 |
} |
0 | 464 |
|
465 |
if (flags & DC_EXEC) { |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
466 |
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
|
467 |
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
|
468 |
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
|
469 |
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
|
470 |
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
|
471 |
// 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
|
472 |
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
|
473 |
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
|
474 |
} |
0 | 475 |
} |
476 |
} |
|
477 |
||
478 |
return 0; |
|
479 |
} |
|
480 |
||
481 |
// p1 = vehicle |
|
482 |
// p2 = new service int |
|
483 |
int32 CmdChangeAircraftServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
484 |
{ |
|
485 |
Vehicle *v; |
|
486 |
||
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
|
487 |
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
|
488 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
489 |
v = GetVehicle(p1); |
0 | 490 |
|
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
|
491 |
if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) |
0 | 492 |
return CMD_ERROR; |
493 |
||
494 |
if (flags & DC_EXEC) { |
|
495 |
v->service_interval = (uint16)p2; |
|
496 |
InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 7); |
|
497 |
} |
|
498 |
||
499 |
return 0; |
|
500 |
} |
|
501 |
||
502 |
// p1 = vehicle |
|
842 | 503 |
// p2 = new cargo type(0xFF) |
504 |
// p2 = skip check for stopped in hanger (0x0100) |
|
0 | 505 |
int32 CmdRefitAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
506 |
{ |
|
507 |
Vehicle *v,*u; |
|
508 |
int pass, mail; |
|
509 |
int32 cost; |
|
842 | 510 |
byte SkipStoppedInHangerCheck = (p2 & 0x100) >> 8; //excludes the cargo value |
511 |
byte new_cargo_type = p2 & 0xFF; //gets the cargo number |
|
924
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
512 |
AircraftVehicleInfo *avi; |
0 | 513 |
|
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
|
514 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
0 | 515 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
516 |
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
|
517 |
|
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 |
if (v->type != VEH_Aircraft) 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
|
519 |
|
924
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
520 |
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
|
521 |
|
842 | 522 |
if (!CheckOwnership(v->owner) || (!CheckStoppedInHangar(v) && !(SkipStoppedInHangerCheck))) |
0 | 523 |
return CMD_ERROR; |
524 |
||
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
|
525 |
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
|
526 |
|
924
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
527 |
switch (new_cargo_type) { |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
528 |
case CT_PASSENGERS: |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
529 |
pass = avi->passenger_capacity; |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
530 |
break; |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
531 |
case CT_MAIL: |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
532 |
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
|
533 |
break; |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
534 |
case CT_GOODS: |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
535 |
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
|
536 |
pass /= 2; |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
537 |
break; |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
538 |
default: |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
539 |
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
|
540 |
pass /= 4; |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
541 |
break; |
0 | 542 |
} |
543 |
_aircraft_refit_capacity = pass; |
|
544 |
||
545 |
cost = 0; |
|
842 | 546 |
if (IS_HUMAN_PLAYER(v->owner) && new_cargo_type != v->cargo_type) { |
0 | 547 |
cost = _price.aircraft_base >> 7; |
548 |
} |
|
549 |
||
550 |
if (flags & DC_EXEC) { |
|
551 |
v->cargo_cap = pass; |
|
552 |
||
553 |
u = v->next; |
|
924
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
554 |
mail = avi->mail_capacity; |
842 | 555 |
if (new_cargo_type != CT_PASSENGERS) { |
0 | 556 |
mail = 0; |
557 |
} |
|
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; |
|
563 |
v->cargo_type = new_cargo_type; |
|
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 && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
589 |
v->current_order.flags & OF_FULL_LOAD) |
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 |
{ |
|
816 |
byte maxz = 162; |
|
817 |
if (v->max_speed != 37) { |
|
818 |
maxz = 171; |
|
819 |
if (v->max_speed != 74) {maxz = 180;} |
|
820 |
} |
|
821 |
return maxz; |
|
822 |
} |
|
823 |
||
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
|
824 |
static bool AircraftController(Vehicle *v) |
0 | 825 |
{ |
826 |
Station *st; |
|
827 |
const AirportMovingData *amd; |
|
828 |
Vehicle *u; |
|
829 |
byte z,dirdiff,newdir,maxz,curz; |
|
830 |
GetNewVehiclePosResult gp; |
|
831 |
uint dist; |
|
832 |
int x,y; |
|
833 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
834 |
st = GetStation(v->u.air.targetairport); |
0 | 835 |
|
836 |
// prevent going to 0,0 if airport is deleted. |
|
837 |
{ |
|
838 |
uint tile = st->airport_tile; |
|
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? |
|
915 |
if (!(amd->flag & AMED_EXACTPOS) && dist <= (uint)((amd->flag&AMED_SLOWTURN)?8:4)) |
|
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)) { |
|
1051 |
v->direction = (v->direction+_crashed_aircraft_moddir[(r >> 16)&3]) & 7; |
|
1052 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos); |
|
1053 |
r = Random(); |
|
1054 |
CreateEffectVehicleRel(v, |
|
1055 |
4 + (r&0xF), |
|
1056 |
4 + ((r>>4)&0xF), |
|
1057 |
((r>>8)&0xF), |
|
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 && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1127 |
(v->current_order.flags & (OF_UNLOAD | OF_FULL_LOAD)) == (OF_UNLOAD | OF_FULL_LOAD) && |
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
|
1128 |
!VehicleNeedsService(v) && |
1139
c63f257aa7fb
(svn r1640) fix: now helicopters will use a hangar in schedule to be replaced in, even if they are only set to service there. Since helicopters are serviced at helipads, they will only go there if they needs to be replaced or renewed.
bjarni
parents:
1135
diff
changeset
|
1129 |
v->set_for_replacement == false) { |
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
|
1130 |
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
|
1131 |
} |
0 | 1132 |
|
1133 |
if (v->cur_order_index >= v->num_orders) |
|
1134 |
v->cur_order_index = 0; |
|
1135 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1136 |
order = GetVehicleOrder(v, v->cur_order_index); |
0 | 1137 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1138 |
if (order == NULL) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1139 |
v->current_order.type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1140 |
v->current_order.flags = 0; |
0 | 1141 |
return; |
1142 |
} |
|
1143 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1144 |
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
|
1145 |
CrashAirplane(v); |
c92d5da1acb3
(svn r1387) Fix: Airplanes now also crash when only one invalid order is in the schedule
dominik
parents:
899
diff
changeset
|
1146 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1147 |
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
|
1148 |
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
|
1149 |
order->station == v->current_order.station) |
0 | 1150 |
return; |
1151 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1152 |
v->current_order = *order; |
0 | 1153 |
|
1154 |
// 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
|
1155 |
if (order->type == OT_GOTO_STATION && v->u.air.state == FLYING) { |
0 | 1156 |
AircraftNextAirportPos_and_Order(v); |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1157 |
v->u.air.targetairport = order->station; |
0 | 1158 |
} |
1159 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1160 |
InvalidateVehicleOrder(v); |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1161 |
|
1055
3aae1d6f12aa
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
1162 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 1163 |
} |
1164 |
||
1165 |
static void HandleAircraftLoading(Vehicle *v, int mode) |
|
1166 |
{ |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1167 |
if (v->current_order.type == OT_NOTHING) |
0 | 1168 |
return; |
1169 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1170 |
if (v->current_order.type != OT_DUMMY) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1171 |
if (v->current_order.type != OT_LOADING) |
0 | 1172 |
return; |
1173 |
||
1174 |
if (mode != 0) |
|
1175 |
return; |
|
1176 |
||
1177 |
if (--v->load_unload_time_rem) |
|
1178 |
return; |
|
1179 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1180 |
if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) { |
0 | 1181 |
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC); |
1182 |
LoadUnloadVehicle(v); |
|
1183 |
return; |
|
1184 |
} |
|
1185 |
||
1186 |
{ |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1187 |
Order b = v->current_order; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1188 |
v->current_order.type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1189 |
v->current_order.flags = 0; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1190 |
if (!(b.flags & OF_NON_STOP)) |
0 | 1191 |
return; |
1192 |
} |
|
1193 |
} |
|
1194 |
v->cur_order_index++; |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1195 |
InvalidateVehicleOrder(v); |
0 | 1196 |
} |
1197 |
||
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
|
1198 |
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
|
1199 |
{ |
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 |
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
|
1201 |
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
|
1202 |
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
|
1203 |
|
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->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
|
1205 |
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
|
1206 |
|
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
|
1207 |
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
|
1208 |
|
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 |
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
|
1210 |
|
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 |
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
|
1212 |
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
|
1213 |
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
|
1214 |
|
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->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
|
1216 |
v->next->cargo_count = 0, |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1217 |
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
|
1218 |
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
|
1219 |
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
|
1220 |
} 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
|
1221 |
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
|
1222 |
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
|
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 |
|
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 |
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
|
1226 |
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
|
1227 |
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
|
1228 |
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
|
1229 |
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
|
1230 |
|
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 |
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
|
1232 |
} |
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
|
1233 |
|
0 | 1234 |
static void MaybeCrashAirplane(Vehicle *v) |
1235 |
{ |
|
1236 |
Station *st; |
|
1237 |
uint16 prob; |
|
1238 |
int i; |
|
1239 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1240 |
st = GetStation(v->u.air.targetairport); |
0 | 1241 |
|
1242 |
//FIXME -- MaybeCrashAirplane -> increase crashing chances of very modern airplanes on smaller than AT_METROPOLITAN airports |
|
1243 |
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
|
1244 |
if (st->airport_type == AT_SMALL && (AircraftVehInfo(v->engine_type)->subtype & 2) && !_cheats.no_jetcrash.value) { |
0 | 1245 |
prob = 0x10000 / 20; |
1246 |
} |
|
1247 |
||
1248 |
if ((uint16)Random() > prob) |
|
1249 |
return; |
|
1250 |
||
1251 |
// Crash the airplane. Remove all goods stored at the station. |
|
1252 |
for(i=0; i!=NUM_CARGO; i++) { |
|
1253 |
st->goods[i].rating = 1; |
|
1254 |
st->goods[i].waiting_acceptance &= ~0xFFF; |
|
1255 |
} |
|
1256 |
||
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
|
1257 |
CrashAirplane(v); |
0 | 1258 |
} |
1259 |
||
1260 |
// we've landed and just arrived at a terminal |
|
1261 |
static void AircraftEntersTerminal(Vehicle *v) |
|
1262 |
{ |
|
1263 |
Station *st; |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1264 |
Order old_order; |
0 | 1265 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1266 |
if (v->current_order.type == OT_GOTO_DEPOT) |
0 | 1267 |
return; |
1268 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1269 |
st = GetStation(v->u.air.targetairport); |
0 | 1270 |
v->last_station_visited = v->u.air.targetairport; |
1271 |
||
1272 |
/* Check if station was ever visited before */ |
|
1273 |
if (!(st->had_vehicle_of_type & HVOT_AIRCRAFT)) { |
|
1274 |
uint32 flags; |
|
1275 |
||
1276 |
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
|
1277 |
SetDParam(0, st->index); |
0 | 1278 |
// show newsitem of celebrating citizens |
1279 |
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); |
|
1280 |
AddNewsItem( |
|
1281 |
STR_A033_CITIZENS_CELEBRATE_FIRST, |
|
1282 |
flags, |
|
1283 |
v->index, |
|
1284 |
0); |
|
1285 |
} |
|
1286 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1287 |
old_order = v->current_order; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1288 |
v->current_order.type = OT_LOADING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1289 |
v->current_order.flags = 0; |
0 | 1290 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1291 |
if (old_order.type == OT_GOTO_STATION && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1292 |
v->current_order.station == v->last_station_visited) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1293 |
v->current_order.flags = |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1294 |
(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD)) | OF_NON_STOP; |
0 | 1295 |
} |
1296 |
||
1297 |
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC); |
|
1298 |
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
|
1299 |
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
|
1300 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 1301 |
} |
1302 |
||
1064
1b6564cec6be
(svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents:
1055
diff
changeset
|
1303 |
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
|
1304 |
{ |
1b6564cec6be
(svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents:
1055
diff
changeset
|
1305 |
Vehicle *v = GetVehicle(data_a); |
1b6564cec6be
(svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents:
1055
diff
changeset
|
1306 |
|
1b6564cec6be
(svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents:
1055
diff
changeset
|
1307 |
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
|
1308 |
} |
1b6564cec6be
(svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents:
1055
diff
changeset
|
1309 |
|
0 | 1310 |
static void AircraftEnterHangar(Vehicle *v) |
1311 |
{ |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1312 |
Order old_order; |
0 | 1313 |
|
1314 |
ServiceAircraft(v); |
|
1055
3aae1d6f12aa
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
1315 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1316 |
|
842 | 1317 |
MaybeReplaceVehicle(v); |
0 | 1318 |
|
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
|
1319 |
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
|
1320 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1321 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
0 | 1322 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
1323 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1324 |
old_order = v->current_order; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1325 |
v->current_order.type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1326 |
v->current_order.flags = 0; |
0 | 1327 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1328 |
if (old_order.flags & OF_UNLOAD) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1329 |
v->cur_order_index++; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1330 |
} else if (old_order.flags & OF_FULL_LOAD) { // force depot visit |
0 | 1331 |
v->vehstatus |= VS_STOPPED; |
1055
3aae1d6f12aa
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
1332 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 1333 |
|
1334 |
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
|
1335 |
SetDParam(0, v->unitnumber); |
1064
1b6564cec6be
(svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents:
1055
diff
changeset
|
1336 |
AddValidatedNewsItem( |
0 | 1337 |
STR_A014_AIRCRAFT_IS_WAITING_IN, |
1338 |
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), |
|
1339 |
v->index, |
|
1064
1b6564cec6be
(svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents:
1055
diff
changeset
|
1340 |
0, |
1b6564cec6be
(svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents:
1055
diff
changeset
|
1341 |
ValidateAircraftInHangar); |
0 | 1342 |
} |
1343 |
} |
|
1344 |
} |
|
1345 |
} |
|
1346 |
||
1347 |
static void AircraftLand(Vehicle *v) |
|
1348 |
{ |
|
1349 |
v->sprite_width = v->sprite_height = 2; |
|
1350 |
} |
|
1351 |
||
1352 |
static void AircraftLandAirplane(Vehicle *v) |
|
1353 |
{ |
|
1354 |
AircraftLand(v); |
|
541 | 1355 |
SndPlayVehicleFx(SND_17_SKID_PLANE, v); |
0 | 1356 |
MaybeCrashAirplane(v); |
1357 |
} |
|
1358 |
||
1359 |
// set the right pos when heading to other airports after takeoff |
|
1360 |
static void AircraftNextAirportPos_and_Order(Vehicle *v) |
|
1361 |
{ |
|
1362 |
Station *st; |
|
1363 |
const AirportFTAClass *Airport; |
|
1364 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1365 |
if (v->current_order.type == OT_GOTO_STATION || |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1366 |
v->current_order.type == OT_GOTO_DEPOT) |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1367 |
v->u.air.targetairport = v->current_order.station; |
0 | 1368 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1369 |
st = GetStation(v->u.air.targetairport); |
0 | 1370 |
Airport = GetAirport(st->airport_type); |
1371 |
v->u.air.pos = v->u.air.previous_pos = Airport->entry_point; |
|
1372 |
} |
|
1373 |
||
1374 |
static void AircraftLeaveHangar(Vehicle *v) |
|
1375 |
{ |
|
1376 |
v->cur_speed = 0; |
|
1377 |
v->subspeed = 0; |
|
1378 |
v->progress = 0; |
|
1379 |
v->direction = 3; |
|
1380 |
v->vehstatus &= ~VS_HIDDEN; |
|
1381 |
{ |
|
1382 |
Vehicle *u = v->next; |
|
1383 |
u->vehstatus &= ~VS_HIDDEN; |
|
1384 |
||
1385 |
// Rotor blades |
|
1386 |
if ((u=u->next) != NULL) { |
|
1387 |
u->vehstatus &= ~VS_HIDDEN; |
|
1388 |
u->cur_speed = 80; |
|
1389 |
} |
|
1390 |
} |
|
1391 |
||
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
|
1392 |
VehicleServiceInDepot(v); |
0 | 1393 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos); |
1394 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
1055
3aae1d6f12aa
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
1395 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
0 | 1396 |
} |
1397 |
||
1398 |
||
1399 |
//////////////////////////////////////////////////////////////////////////////// |
|
1400 |
/////////////////// AIRCRAFT MOVEMENT SCHEME //////////////////////////////// |
|
1401 |
//////////////////////////////////////////////////////////////////////////////// |
|
1402 |
static void AircraftEventHandler_EnterTerminal(Vehicle *v, const AirportFTAClass *Airport) |
|
1403 |
{ |
|
1404 |
AircraftEntersTerminal(v); |
|
1405 |
v->u.air.state = Airport->layout[v->u.air.pos].heading; |
|
1406 |
} |
|
1407 |
||
1408 |
static void AircraftEventHandler_EnterHangar(Vehicle *v, const AirportFTAClass *Airport) |
|
1409 |
{ |
|
1410 |
AircraftEnterHangar(v); |
|
1411 |
v->u.air.state = Airport->layout[v->u.air.pos].heading; |
|
1412 |
} |
|
1413 |
||
1414 |
// In an Airport Hangar |
|
1415 |
static void AircraftEventHandler_InHangar(Vehicle *v, const AirportFTAClass *Airport) |
|
1416 |
{ |
|
1417 |
// if we just arrived, execute EnterHangar first |
|
1418 |
if (v->u.air.previous_pos != v->u.air.pos) { |
|
1419 |
AircraftEventHandler_EnterHangar(v, Airport); |
|
1420 |
return; |
|
1421 |
} |
|
1422 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1423 |
// if we were sent to the depot, stay there |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1424 |
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
|
1425 |
v->current_order.type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1426 |
v->current_order.flags = 0; |
0 | 1427 |
return; |
1428 |
} |
|
1429 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1430 |
if (v->current_order.type != OT_GOTO_STATION && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1431 |
v->current_order.type != OT_GOTO_DEPOT) |
0 | 1432 |
return; |
1433 |
||
1434 |
// if the block of the next position is busy, stay put |
|
1435 |
if (AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) {return;} |
|
1436 |
||
1437 |
// 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
|
1438 |
if (v->current_order.station == v->u.air.targetairport) { |
0 | 1439 |
// FindFreeTerminal: |
1440 |
// 1. Find a free terminal, 2. Occupy it, 3. Set the vehicle's state to that terminal |
|
1441 |
if (v->subtype != 0) {if(!AirportFindFreeTerminal(v, Airport)) {return;}} // airplane |
|
1442 |
else {if(!AirportFindFreeHelipad(v, Airport)) {return;}} // helicopter |
|
1443 |
} |
|
1444 |
else { // Else prepare for launch. |
|
1445 |
// airplane goto state takeoff, helicopter to helitakeoff |
|
1446 |
v->u.air.state = (v->subtype != 0) ? TAKEOFF : HELITAKEOFF; |
|
1447 |
} |
|
1448 |
AircraftLeaveHangar(v); |
|
1449 |
AirportMove(v, Airport); |
|
1450 |
} |
|
1451 |
||
1452 |
// At one of the Airport's Terminals |
|
1453 |
static void AircraftEventHandler_AtTerminal(Vehicle *v, const AirportFTAClass *Airport) |
|
1454 |
{ |
|
1455 |
// if we just arrived, execute EnterTerminal first |
|
1456 |
if (v->u.air.previous_pos != v->u.air.pos) { |
|
1457 |
AircraftEventHandler_EnterTerminal(v, Airport); |
|
1458 |
// on an airport with helipads, a helicopter will always land there |
|
1459 |
// and get serviced at the same time - patch setting |
|
1460 |
if (_patches.serviceathelipad) { |
|
950
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1461 |
if (v->subtype == 0 && Airport->helipads != NULL) { |
0 | 1462 |
// an exerpt of ServiceAircraft, without the invisibility stuff |
1463 |
v->date_of_last_service = _date; |
|
1464 |
v->breakdowns_since_last_service = 0; |
|
1465 |
v->reliability = _engines[v->engine_type].reliability; |
|
1466 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1467 |
} |
|
1468 |
} |
|
1469 |
return; |
|
1470 |
} |
|
1471 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1472 |
if (v->current_order.type == OT_NOTHING) return; |
0 | 1473 |
|
1474 |
// if the block of the next position is busy, stay put |
|
1475 |
if (AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) { |
|
1476 |
return; |
|
1477 |
} |
|
1478 |
||
1479 |
// airport-road is free. We either have to go to another airport, or to the hangar |
|
1480 |
// ---> start moving |
|
1481 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1482 |
switch (v->current_order.type) { |
0 | 1483 |
case OT_GOTO_STATION: // ready to fly to another airport |
1484 |
// airplane goto state takeoff, helicopter to helitakeoff |
|
1485 |
v->u.air.state = (v->subtype != 0) ? TAKEOFF : HELITAKEOFF; |
|
1486 |
break; |
|
1487 |
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
|
1488 |
if (v->current_order.station == v->u.air.targetairport) |
0 | 1489 |
v->u.air.state = HANGAR; |
1490 |
else |
|
1491 |
v->u.air.state = (v->subtype != 0) ? TAKEOFF : HELITAKEOFF; |
|
1492 |
break; |
|
1493 |
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
|
1494 |
v->current_order.type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1495 |
v->current_order.flags = 0; |
0 | 1496 |
v->u.air.state = HANGAR; |
1497 |
} |
|
1498 |
AirportMove(v, Airport); |
|
1499 |
} |
|
1500 |
||
1501 |
static void AircraftEventHandler_General(Vehicle *v, const AirportFTAClass *Airport) |
|
1502 |
{ |
|
70
60216d94f7c1
(svn r71) -Cheat: [976127] no extra frequent jet crash on small airports (truesatan)
darkvater
parents:
19
diff
changeset
|
1503 |
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
|
1504 |
assert(0); |
0 | 1505 |
} |
1506 |
||
1507 |
static void AircraftEventHandler_TakeOff(Vehicle *v, const AirportFTAClass *Airport) { |
|
1508 |
PlayAircraftSound(v); // play takeoffsound for airplanes |
|
1509 |
v->u.air.state = STARTTAKEOFF; |
|
1510 |
} |
|
1511 |
||
1512 |
static void AircraftEventHandler_StartTakeOff(Vehicle *v, const AirportFTAClass *Airport) |
|
1513 |
{ |
|
1514 |
v->sprite_width = v->sprite_height = 24; // ??? no idea what this is |
|
1515 |
v->u.air.state = ENDTAKEOFF; |
|
1516 |
} |
|
1517 |
||
1518 |
static void AircraftEventHandler_EndTakeOff(Vehicle *v, const AirportFTAClass *Airport) |
|
1519 |
{ |
|
1520 |
v->u.air.state = FLYING; |
|
1521 |
// get the next position to go to, differs per airport |
|
1522 |
AircraftNextAirportPos_and_Order(v); |
|
1523 |
} |
|
1524 |
||
1525 |
static void AircraftEventHandler_HeliTakeOff(Vehicle *v, const AirportFTAClass *Airport) |
|
1526 |
{ |
|
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 |
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
|
1533 |
if (v->current_order.type != OT_GOTO_DEPOT && v->owner == _local_player) { |
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
|
1534 |
// only the vehicle owner needs to calculate the rest (locally) |
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
|
1535 |
if ((_autoreplace_array[v->engine_type] != v->engine_type) || |
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
|
1536 |
(_patches.autorenew && v->age - v->max_age > (_patches.autorenew_months * 30))) { |
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
|
1537 |
|
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
|
1538 |
if (v->set_for_replacement) { |
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
|
1539 |
Station *st = GetStation(v->u.air.targetairport); |
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
|
1540 |
// 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
|
1541 |
// 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
|
1542 |
if (st->xy == 0 || st->airport_tile == 0 || 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
|
1543 |
return; |
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
|
1544 |
/* this is not the airport, where the helicopter will be replaced |
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
|
1545 |
No need to make everybody check this, since it would be a waste of bandwidth */ |
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
|
1546 |
} |
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
|
1547 |
|
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
|
1548 |
{ |
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
|
1549 |
bool has_hangar = HaveHangarInOrderList(v); // this info is needed twice, but we only want to loop the orders once ;) |
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
|
1550 |
uint32 next_airport = 0; |
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
|
1551 |
|
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
|
1552 |
if (!has_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
|
1553 |
// the helicopter needs help to find a hangar since there are none in the schedule |
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
|
1554 |
SETBIT(next_airport, 17); |
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
|
1555 |
next_airport |= FindNearestHangar(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
|
1556 |
if (HASBIT(next_airport, 16)) { |
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
|
1557 |
/* when shared airports are allowed, a check for a rentable hangar should be added here */ |
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
|
1558 |
/* TODO: tell the player that he needs 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
|
1559 |
v->set_for_replacement = false; //needed so it will check again later when the player might have build 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
|
1560 |
return; // player do not own 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
|
1561 |
} |
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
|
1562 |
} |
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
|
1563 |
SETBIT(next_airport, 16); |
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
|
1564 |
_current_player = _local_player; |
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
|
1565 |
DoCommandP(v->tile, v->index, next_airport, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR); |
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
|
1566 |
_current_player = OWNER_NONE; |
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
|
1567 |
} |
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
|
1568 |
} else { // no need to go to a depot |
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
|
1569 |
if (v->set_for_replacement) { |
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
|
1570 |
// it seems that the user clicked "Stop replacing" |
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
|
1571 |
_current_player = _local_player; |
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
|
1572 |
DoCommandP(v->tile, v->index, (1 | (1 << 2)) << 16, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR); |
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
|
1573 |
_current_player = OWNER_NONE; |
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
|
1574 |
} |
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
|
1575 |
} |
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
|
1576 |
} |
0 | 1577 |
} |
1578 |
||
1579 |
static void AircraftEventHandler_Flying(Vehicle *v, const AirportFTAClass *Airport) |
|
1580 |
{ |
|
1581 |
Station *st; |
|
1582 |
byte landingtype; |
|
1583 |
AirportFTA *current; |
|
1584 |
uint16 tcur_speed, tsubspeed; |
|
1585 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1586 |
st = GetStation(v->u.air.targetairport); |
0 | 1587 |
// flying device is accepted at this station |
1588 |
// small airport --> no helicopters (AIRCRAFT_ONLY) |
|
1589 |
// all other airports --> all types of flying devices (ALL) |
|
1590 |
// heliport/oilrig, etc --> no airplanes (HELICOPTERS_ONLY) |
|
1591 |
// runway busy or not allowed to use this airstation, circle |
|
1592 |
if (! (v->subtype == Airport->acc_planes || |
|
1593 |
st->airport_tile == 0 || (st->owner != OWNER_NONE && st->owner != v->owner) )) { |
|
1594 |
||
1595 |
// {32,FLYING,NOTHING_block,37}, {32,LANDING,N,33}, {32,HELILANDING,N,41}, |
|
1596 |
// if it is an airplane, look for LANDING, for helicopter HELILANDING |
|
1597 |
// it is possible to choose from multiple landing runways, so loop until a free one is found |
|
1598 |
landingtype = (v->subtype != 0) ? LANDING : HELILANDING; |
|
1599 |
current = Airport->layout[v->u.air.pos].next_in_chain; |
|
1600 |
while (current != NULL) { |
|
1601 |
if (current->heading == landingtype) { |
|
1602 |
// save speed before, since if AirportHasBlock is false, it resets them to 0 |
|
1603 |
// we don't want that for plane in air |
|
1604 |
// hack for speed thingie |
|
1605 |
tcur_speed = v->cur_speed; |
|
1606 |
tsubspeed = v->subspeed; |
|
1607 |
if (!AirportHasBlock(v, current, Airport)) { |
|
1608 |
v->u.air.state = landingtype; // LANDING / HELILANDING |
|
1609 |
// it's a bit dirty, but I need to set position to next position, otherwise |
|
1610 |
// if there are multiple runways, plane won't know which one it took (because |
|
1611 |
// they all have heading LANDING). And also occupy that block! |
|
1612 |
v->u.air.pos = current->next_position; |
|
1613 |
SETBITS(st->airport_flags, Airport->layout[v->u.air.pos].block); |
|
1614 |
return; |
|
1615 |
} |
|
1616 |
v->cur_speed = tcur_speed; |
|
1617 |
v->subspeed = tsubspeed; |
|
1618 |
} |
|
1619 |
current = current->next_in_chain; |
|
1620 |
} |
|
1621 |
} |
|
1622 |
v->u.air.state = FLYING; |
|
1623 |
v->u.air.pos = Airport->layout[v->u.air.pos].next_position; |
|
1624 |
} |
|
1625 |
||
1626 |
static void AircraftEventHandler_Landing(Vehicle *v, const AirportFTAClass *Airport) |
|
1627 |
{ |
|
1628 |
AircraftLandAirplane(v); // maybe crash airplane |
|
1629 |
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
|
1630 |
// 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
|
1631 |
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
|
1632 |
// only the vehicle owner needs to calculate the rest (locally) |
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
|
1633 |
if ((_autoreplace_array[v->engine_type] != v->engine_type) || |
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
|
1634 |
(_patches.autorenew && v->age - v->max_age > (_patches.autorenew_months * 30))) { |
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
|
1635 |
// send the aircraft to the hangar at next airport |
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
|
1636 |
_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
|
1637 |
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
|
1638 |
_current_player = OWNER_NONE; |
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
|
1639 |
} else { // no need to go to a depot |
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
|
1640 |
if (v->set_for_replacement) { |
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
|
1641 |
// it seems that the user clicked "Stop replacing" |
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
|
1642 |
_current_player = _local_player; |
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
|
1643 |
DoCommandP(v->tile, v->index, (1 | (1 << 2)) << 16, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR); |
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
|
1644 |
_current_player = OWNER_NONE; |
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
|
1645 |
} |
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
|
1646 |
} |
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
|
1647 |
} |
0 | 1648 |
} |
1649 |
||
1650 |
static void AircraftEventHandler_HeliLanding(Vehicle *v, const AirportFTAClass *Airport) |
|
1651 |
{ |
|
1652 |
AircraftLand(v); // helicopters don't crash |
|
1653 |
v->u.air.state = HELIENDLANDING; |
|
1654 |
} |
|
1655 |
||
1656 |
static void AircraftEventHandler_EndLanding(Vehicle *v, const AirportFTAClass *Airport) |
|
1657 |
{ |
|
1658 |
// next block busy, don't do a thing, just wait |
|
1659 |
if(AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) {return;} |
|
1660 |
||
1661 |
// if going to terminal (OT_GOTO_STATION) choose one |
|
1662 |
// 1. in case all terminals are busy AirportFindFreeTerminal() returns false or |
|
1663 |
// 2. not going for terminal (but depot, no order), |
|
1664 |
// --> get out of the way to the hangar. |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1665 |
if (v->current_order.type == OT_GOTO_STATION) { |
0 | 1666 |
if (AirportFindFreeTerminal(v, Airport)) {return;} |
1667 |
} |
|
1668 |
v->u.air.state = HANGAR; |
|
1669 |
||
1670 |
} |
|
1671 |
||
1672 |
static void AircraftEventHandler_HeliEndLanding(Vehicle *v, const AirportFTAClass *Airport) |
|
1673 |
{ |
|
1674 |
// next block busy, don't do a thing, just wait |
|
1675 |
if(AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) {return;} |
|
1676 |
||
1677 |
// if going to helipad (OT_GOTO_STATION) choose one. If airport doesn't have helipads, choose terminal |
|
1678 |
// 1. in case all terminals/helipads are busy (AirportFindFreeHelipad() returns false) or |
|
1679 |
// 2. not going for terminal (but depot, no order), |
|
1680 |
// --> get out of the way to the hangar IF there are terminals on the airport. |
|
1681 |
// --> else TAKEOFF |
|
1682 |
// the reason behind this is that if an airport has a terminal, it also has a hangar. Airplanes |
|
1683 |
// must go to a hangar. |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1684 |
if (v->current_order.type == OT_GOTO_STATION) { |
0 | 1685 |
if (AirportFindFreeHelipad(v, Airport)) {return;} |
1686 |
} |
|
950
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1687 |
v->u.air.state = (Airport->terminals != NULL) ? HANGAR : HELITAKEOFF; |
0 | 1688 |
} |
1689 |
||
1690 |
typedef void AircraftStateHandler(Vehicle *v, const AirportFTAClass *Airport); |
|
1691 |
static AircraftStateHandler * const _aircraft_state_handlers[] = { |
|
1692 |
AircraftEventHandler_General, // TO_ALL = 0 |
|
1693 |
AircraftEventHandler_InHangar, // HANGAR = 1 |
|
1694 |
AircraftEventHandler_AtTerminal, // TERM1 = 2 |
|
1695 |
AircraftEventHandler_AtTerminal, // TERM2 = 3 |
|
1696 |
AircraftEventHandler_AtTerminal, // TERM3 = 4 |
|
1697 |
AircraftEventHandler_AtTerminal, // TERM4 = 5 |
|
1698 |
AircraftEventHandler_AtTerminal, // TERM5 = 6 |
|
1699 |
AircraftEventHandler_AtTerminal, // TERM6 = 7 |
|
1700 |
AircraftEventHandler_AtTerminal, // HELIPAD1 = 8 |
|
1701 |
AircraftEventHandler_AtTerminal, // HELIPAD2 = 9 |
|
1702 |
AircraftEventHandler_TakeOff, // TAKEOFF = 10 |
|
1703 |
AircraftEventHandler_StartTakeOff, // STARTTAKEOFF = 11 |
|
1704 |
AircraftEventHandler_EndTakeOff, // ENDTAKEOFF = 12 |
|
1705 |
AircraftEventHandler_HeliTakeOff, // HELITAKEOFF = 13 |
|
1706 |
AircraftEventHandler_Flying, // FLYING = 14 |
|
1707 |
AircraftEventHandler_Landing, // LANDING = 15 |
|
1708 |
AircraftEventHandler_EndLanding, // ENDLANDING = 16 |
|
1709 |
AircraftEventHandler_HeliLanding, // HELILANDING = 17 |
|
1710 |
AircraftEventHandler_HeliEndLanding,// HELIENDLANDING = 18 |
|
1711 |
}; |
|
1712 |
||
1713 |
static void AirportClearBlock(Vehicle *v, const AirportFTAClass *Airport) |
|
1714 |
{ |
|
1715 |
Station *st; |
|
1716 |
// we have left the previous block, and entered the new one. Free the previous block |
|
1717 |
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
|
1718 |
st = GetStation(v->u.air.targetairport); |
0 | 1719 |
CLRBITS(st->airport_flags, Airport->layout[v->u.air.previous_pos].block); |
1720 |
} |
|
1721 |
} |
|
1722 |
||
1723 |
static void AirportGoToNextPosition(Vehicle *v, const AirportFTAClass *Airport) |
|
1724 |
{ |
|
1725 |
// 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
|
1726 |
if (!AircraftController(v)) {return;} |
0 | 1727 |
|
1728 |
AirportClearBlock(v, Airport); |
|
1729 |
AirportMove(v, Airport); // move aircraft to next position |
|
1730 |
} |
|
1731 |
||
1732 |
// gets pos from vehicle and next orders |
|
1733 |
static bool AirportMove(Vehicle *v, const AirportFTAClass *Airport) |
|
1734 |
{ |
|
1735 |
AirportFTA *current; |
|
1736 |
byte prev_pos; |
|
1737 |
bool retval = false; |
|
1738 |
||
1739 |
// error handling |
|
1740 |
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
|
1741 |
DEBUG(misc, 0) ("position %d is not valid for current airport. Max position is %d", v->u.air.pos, Airport->nofelements-1); |
0 | 1742 |
assert(v->u.air.pos < Airport->nofelements); |
1743 |
} |
|
1744 |
||
1745 |
current = &Airport->layout[v->u.air.pos]; |
|
1746 |
// we have arrived in an important state (eg terminal, hangar, etc.) |
|
1747 |
if (current->heading == v->u.air.state) { |
|
1748 |
prev_pos = v->u.air.pos; // location could be changed in state, so save it before-hand |
|
1749 |
_aircraft_state_handlers[v->u.air.state](v, Airport); |
|
1750 |
if (v->u.air.state != FLYING) {v->u.air.previous_pos = prev_pos;} |
|
1751 |
return true; |
|
1752 |
} |
|
1753 |
||
1754 |
v->u.air.previous_pos = v->u.air.pos; // save previous location |
|
1755 |
||
1756 |
// there is only one choice to move to |
|
1757 |
if (current->next_in_chain == NULL) { |
|
1758 |
if (AirportSetBlocks(v, current, Airport)) { |
|
1759 |
v->u.air.pos = current->next_position; |
|
1760 |
} // move to next position |
|
1761 |
return retval; |
|
1762 |
} |
|
1763 |
||
1764 |
// there are more choices to choose from, choose the one that |
|
1765 |
// matches our heading |
|
1766 |
do { |
|
1767 |
if (v->u.air.state == current->heading || current->heading == TO_ALL) { |
|
1768 |
if (AirportSetBlocks(v, current, Airport)) { |
|
1769 |
v->u.air.pos = current->next_position; |
|
1770 |
} // move to next position |
|
1771 |
return retval; |
|
1772 |
} |
|
1773 |
current = current->next_in_chain; |
|
1774 |
} while (current != NULL); |
|
1775 |
||
70
60216d94f7c1
(svn r71) -Cheat: [976127] no extra frequent jet crash on small airports (truesatan)
darkvater
parents:
19
diff
changeset
|
1776 |
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
|
1777 |
DEBUG(misc, 0) ("Airport entry point: %d, Vehicle: %d", Airport->entry_point, v->index); |
0 | 1778 |
assert(0); |
1779 |
return false; |
|
1780 |
} |
|
1781 |
||
1782 |
// returns true if the road ahead is busy, eg. you must wait before proceeding |
|
1783 |
static bool AirportHasBlock(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport) |
|
1784 |
{ |
|
1785 |
Station *st; |
|
1786 |
uint32 airport_flags; |
|
1787 |
AirportFTA *next, *reference; |
|
1788 |
reference = &Airport->layout[v->u.air.pos]; |
|
1789 |
next = &Airport->layout[current_pos->next_position]; |
|
1790 |
||
1791 |
// same block, then of course we can move |
|
1792 |
if (Airport->layout[current_pos->position].block != next->block) { |
|
1793 |
airport_flags = next->block; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1794 |
st = GetStation(v->u.air.targetairport); |
0 | 1795 |
// check additional possible extra blocks |
1796 |
if (current_pos != reference && current_pos->block != NOTHING_block) { |
|
1797 |
airport_flags |= current_pos->block; |
|
1798 |
} |
|
1799 |
||
1800 |
if (HASBITS(st->airport_flags, airport_flags)) { |
|
1801 |
v->cur_speed = 0; |
|
1802 |
v->subspeed = 0; |
|
1803 |
return true; |
|
1804 |
} |
|
1805 |
} |
|
1806 |
return false; |
|
1807 |
} |
|
1808 |
||
1809 |
// returns true on success. Eg, next block was free and we have occupied it |
|
1810 |
static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport) |
|
1811 |
{ |
|
1812 |
Station *st; |
|
1813 |
uint32 airport_flags; |
|
1814 |
AirportFTA *current, *reference, *next; |
|
1815 |
next = &Airport->layout[current_pos->next_position]; |
|
1816 |
reference = &Airport->layout[v->u.air.pos]; |
|
1817 |
||
1818 |
// if the next position is in another block, check it and wait until it is free |
|
1819 |
if (Airport->layout[current_pos->position].block != next->block) { |
|
1820 |
airport_flags = next->block; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1821 |
st = GetStation(v->u.air.targetairport); |
0 | 1822 |
//search for all all elements in the list with the same state, and blocks != N |
1823 |
// this means more blocks should be checked/set |
|
1824 |
current = current_pos; |
|
1825 |
if (current == reference) { current = current->next_in_chain;} |
|
1826 |
while (current != NULL) { |
|
1827 |
if (current->heading == current_pos->heading && current->block != 0) { |
|
1828 |
airport_flags |= current->block; |
|
1829 |
break; |
|
1830 |
} |
|
1831 |
current = current->next_in_chain; |
|
1832 |
}; |
|
1833 |
||
1834 |
// if the block to be checked is in the next position, then exclude that from |
|
1835 |
// checking, because it has been set by the airplane before |
|
1836 |
if (current_pos->block == next->block) {airport_flags ^= next->block;} |
|
1837 |
||
1838 |
if (HASBITS(st->airport_flags, airport_flags)) { |
|
1839 |
v->cur_speed = 0; |
|
1840 |
v->subspeed = 0; |
|
1841 |
return false; |
|
1842 |
} |
|
1843 |
||
1844 |
if (next->block != NOTHING_block) { |
|
1845 |
SETBITS(st->airport_flags, airport_flags); // occupy next block |
|
1846 |
} |
|
1847 |
} |
|
1848 |
return true; |
|
1849 |
} |
|
1850 |
||
1851 |
static bool FreeTerminal(Vehicle *v, byte i, byte last_terminal) |
|
1852 |
{ |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1853 |
Station *st = GetStation(v->u.air.targetairport); |
0 | 1854 |
for (; i < last_terminal; i++) { |
1855 |
if (!HASBIT(st->airport_flags, i)) { |
|
1856 |
// TERMINAL# HELIPAD# |
|
1857 |
v->u.air.state = i + TERM1; // start moving to that terminal/helipad |
|
1858 |
SETBIT(st->airport_flags, i); // occupy terminal/helipad |
|
1859 |
return true; |
|
1860 |
} |
|
1861 |
} |
|
1862 |
return false; |
|
1863 |
} |
|
1864 |
||
950
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1865 |
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
|
1866 |
{ |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1867 |
int i, num = 0; |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
1868 |
|
950
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1869 |
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
|
1870 |
num += Airport->terminals[i]; |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
1871 |
|
950
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1872 |
return num; |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1873 |
} |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1874 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1875 |
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport) |
0 | 1876 |
{ |
1877 |
AirportFTA *temp; |
|
1878 |
Station *st; |
|
1879 |
||
1880 |
/* example of more terminalgroups |
|
1881 |
{0,HANGAR,NOTHING_block,1}, {0,255,TERM_GROUP1_block,0}, {0,255,TERM_GROUP2_ENTER_block,1}, {0,0,N,1}, |
|
1882 |
Heading 255 denotes a group. We see 2 groups here: |
|
1883 |
1. group 0 -- TERM_GROUP1_block (check block) |
|
1884 |
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
|
1885 |
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
|
1886 |
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
|
1887 |
possible groups are checked (in this case group 1, since that is after group 0). If that |
0 | 1888 |
fails, then attempt fails and plane waits |
1889 |
*/ |
|
950
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1890 |
if (Airport->terminals[0] > 1) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1891 |
st = GetStation(v->u.air.targetairport); |
0 | 1892 |
temp = Airport->layout[v->u.air.pos].next_in_chain; |
1893 |
while (temp != NULL) { |
|
1894 |
if (temp->heading == 255) { |
|
1895 |
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
|
1896 |
int target_group; |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1897 |
int i; |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1898 |
int group_start = 0; |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1899 |
int group_end; |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1900 |
|
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1901 |
//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
|
1902 |
//(the first free group) |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1903 |
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
|
1904 |
|
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1905 |
//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
|
1906 |
//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
|
1907 |
//groups with lower number |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1908 |
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
|
1909 |
group_start += Airport->terminals[i]; |
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 |
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
|
1912 |
if (FreeTerminal(v, group_start, group_end)) {return true;} |
0 | 1913 |
} |
1914 |
} |
|
1915 |
else {return false;} // once the heading isn't 255, we've exhausted the possible blocks. So we cannot move |
|
1916 |
temp = temp->next_in_chain; |
|
1917 |
} |
|
1918 |
} |
|
1919 |
||
1920 |
// 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
|
1921 |
return FreeTerminal(v, 0, GetNumTerminals(Airport)); |
0 | 1922 |
} |
1923 |
||
950
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1924 |
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
|
1925 |
{ |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1926 |
int i, num = 0; |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
1927 |
|
950
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1928 |
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
|
1929 |
num += Airport->helipads[i]; |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
1930 |
|
950
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1931 |
return num; |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1932 |
} |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1933 |
|
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1934 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1935 |
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport) |
0 | 1936 |
{ |
1937 |
Station *st; |
|
1938 |
AirportFTA *temp; |
|
1939 |
||
1940 |
// 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
|
1941 |
if (Airport->helipads == NULL) {return AirportFindFreeTerminal(v, Airport);} |
0 | 1942 |
|
1943 |
// 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
|
1944 |
if (Airport->helipads[0] > 1) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1945 |
st = GetStation(v->u.air.targetairport); |
0 | 1946 |
temp = Airport->layout[v->u.air.pos].next_in_chain; |
1947 |
while (temp != NULL) { |
|
1948 |
if (temp->heading == 255) { |
|
1949 |
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
|
1950 |
int target_group; |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1951 |
int i; |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1952 |
int group_start = 0; |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1953 |
int group_end; |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1954 |
|
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1955 |
//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
|
1956 |
//(the first free group) |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1957 |
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
|
1958 |
|
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1959 |
//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
|
1960 |
//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
|
1961 |
//groups with lower number |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1962 |
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
|
1963 |
group_start += Airport->helipads[i]; |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1964 |
|
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1965 |
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
|
1966 |
if (FreeTerminal(v, group_start, group_end)) {return true;} |
0 | 1967 |
} |
1968 |
} |
|
1969 |
else {return false;} // once the heading isn't 255, we've exhausted the possible blocks. So we cannot move |
|
1970 |
temp = temp->next_in_chain; |
|
1971 |
} |
|
1972 |
} |
|
1973 |
// only 1 helicoptergroup, check all helipads |
|
1974 |
// 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
|
1975 |
else {return FreeTerminal(v, MAX_TERMINALS, GetNumHelipads(Airport) + MAX_TERMINALS);} |
0 | 1976 |
return false; // it shouldn't get here anytime, but just to be sure |
1977 |
} |
|
1978 |
||
1979 |
static void AircraftEventHandler(Vehicle *v, int loop) |
|
1980 |
{ |
|
1981 |
v->tick_counter++; |
|
1982 |
||
1983 |
if (v->vehstatus & VS_CRASHED) { |
|
1984 |
HandleCrashedAircraft(v); |
|
1985 |
return; |
|
1986 |
} |
|
1987 |
||
1988 |
/* exit if aircraft is stopped */ |
|
1989 |
if (v->vehstatus & VS_STOPPED) |
|
1990 |
return; |
|
1991 |
||
1992 |
/* aircraft is broken down? */ |
|
1993 |
if (v->breakdown_ctr != 0) { |
|
1994 |
if (v->breakdown_ctr <= 2) { |
|
1995 |
HandleBrokenAircraft(v); |
|
1996 |
} else { |
|
1997 |
v->breakdown_ctr--; |
|
1998 |
} |
|
1999 |
} |
|
2000 |
||
2001 |
HandleAircraftSmoke(v); |
|
2002 |
ProcessAircraftOrder(v); |
|
2003 |
HandleAircraftLoading(v, loop); |
|
2004 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2005 |
if (v->current_order.type >= OT_LOADING) |
0 | 2006 |
return; |
2007 |
||
2008 |
// pass the right airport structure to the functions |
|
2009 |
// DEREF_STATION gets target airport (Station *st), its type is passed to GetAirport |
|
2010 |
// 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
|
2011 |
AirportGoToNextPosition(v, GetAirport(GetStation(v->u.air.targetairport)->airport_type)); |
0 | 2012 |
} |
2013 |
||
2014 |
void Aircraft_Tick(Vehicle *v) |
|
2015 |
{ |
|
2016 |
int i; |
|
2017 |
||
2018 |
if (v->subtype > 2) |
|
2019 |
return; |
|
2020 |
||
2021 |
if (v->subtype == 0) |
|
2022 |
HelicopterTickHandler(v); |
|
2023 |
||
2024 |
AgeAircraftCargo(v); |
|
2025 |
||
2026 |
for(i=0; i!=6; i++) { |
|
2027 |
AircraftEventHandler(v, i); |
|
2028 |
if (v->type != VEH_Aircraft) // In case it was deleted |
|
2029 |
break; |
|
2030 |
} |
|
2031 |
} |
|
2032 |
||
950
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2033 |
void UpdateOilRig( void ) |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2034 |
{ |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2035 |
Station *st; |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
2036 |
|
950
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2037 |
FOR_ALL_STATIONS(st) { |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2038 |
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
|
2039 |
} |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2040 |
} |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
2041 |
|
0 | 2042 |
// 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
|
2043 |
void UpdateOldAircraft(void) |
0 | 2044 |
{ |
2045 |
Station *st; |
|
2046 |
Vehicle *v_oldstyle; |
|
2047 |
GetNewVehiclePosResult gp; |
|
2048 |
||
2049 |
// set airport_flags to 0 for all airports just to be sure |
|
2050 |
FOR_ALL_STATIONS(st) { |
|
2051 |
st->airport_flags = 0; // reset airport |
|
2052 |
// type of oilrig has been moved, update it (3-5) |
|
2053 |
if (st->airport_type == 3) {st->airport_type = AT_OILRIG;} |
|
2054 |
} |
|
2055 |
||
2056 |
FOR_ALL_VEHICLES(v_oldstyle) { |
|
2057 |
// airplane has another vehicle with subtype 4 (shadow), helicopter also has 3 (rotor) |
|
2058 |
// skip those |
|
2059 |
if (v_oldstyle->type == VEH_Aircraft && v_oldstyle->subtype <= 2) { |
|
2060 |
// airplane in terminal stopped doesn't hurt anyone, so goto next |
|
2061 |
if ((v_oldstyle->vehstatus & VS_STOPPED) && (v_oldstyle->u.air.state == 0)) { |
|
2062 |
v_oldstyle->u.air.state = HANGAR; |
|
2063 |
continue; |
|
2064 |
} |
|
2065 |
||
2066 |
AircraftLeaveHangar(v_oldstyle); // make airplane visible if it was in a depot for example |
|
2067 |
v_oldstyle->vehstatus &= ~VS_STOPPED; // make airplane moving |
|
2068 |
v_oldstyle->u.air.state = FLYING; |
|
2069 |
AircraftNextAirportPos_and_Order(v_oldstyle); // move it to the entry point of the airport |
|
2070 |
GetNewVehiclePos(v_oldstyle, &gp); // get the position of the plane (to be used for setting) |
|
2071 |
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
|
2072 |
|
0 | 2073 |
// correct speed of helicopter-rotors |
2074 |
if (v_oldstyle->subtype == 0) {v_oldstyle->next->next->cur_speed = 32;} |
|
2075 |
||
2076 |
// set new position x,y,z |
|
2077 |
SetAircraftPosition(v_oldstyle, gp.x, gp.y, GetAircraftFlyingAltitude(v_oldstyle)); |
|
2078 |
} |
|
2079 |
} |
|
2080 |
} |
|
2081 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2082 |
void UpdateAirplanesOnNewStation(Station *st) |
0 | 2083 |
{ |
2084 |
GetNewVehiclePosResult gp; |
|
2085 |
Vehicle *v; |
|
2086 |
byte takeofftype; |
|
2087 |
uint16 cnt; |
|
2088 |
// only 1 station is updated per function call, so it is enough to get entry_point once |
|
2089 |
const AirportFTAClass *ap = GetAirport(st->airport_type); |
|
2090 |
FOR_ALL_VEHICLES(v) { |
|
2091 |
if (v->type == VEH_Aircraft && v->subtype <= 2) { |
|
2092 |
if (v->u.air.targetairport == st->index) { // if heading to this airport |
|
2093 |
/* update position of airplane. If plane is not flying, landing, or taking off |
|
2094 |
you cannot delete airport, so it doesn't matter |
|
2095 |
*/ |
|
2096 |
if (v->u.air.state >= FLYING) { // circle around |
|
2097 |
v->u.air.pos = v->u.air.previous_pos = ap->entry_point; |
|
2098 |
v->u.air.state = FLYING; |
|
2099 |
// 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
|
2100 |
// in normal mode, plane is reset in AircraftController. It doesn't hurt for FLYING |
0 | 2101 |
GetNewVehiclePos(v, &gp); |
2102 |
// set new position x,y,z |
|
2103 |
SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v)); |
|
2104 |
} |
|
2105 |
else { |
|
2106 |
assert(v->u.air.state == ENDTAKEOFF || v->u.air.state == HELITAKEOFF); |
|
2107 |
takeofftype = (v->subtype == 0) ? HELITAKEOFF : ENDTAKEOFF; |
|
2108 |
// search in airportdata for that heading |
|
2109 |
// easiest to do, since this doesn't happen a lot |
|
2110 |
for (cnt = 0; cnt < ap->nofelements; cnt++) { |
|
2111 |
if (ap->layout[cnt].heading == takeofftype) { |
|
2112 |
v->u.air.pos = ap->layout[cnt].position; |
|
2113 |
break; |
|
2114 |
} |
|
2115 |
} |
|
2116 |
} |
|
2117 |
} |
|
2118 |
} |
|
2119 |
} |
|
2120 |
} |