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