author | celestar |
Sat, 15 Jan 2005 09:28:08 +0000 | |
changeset 1020 | 59ee8ceac74c |
parent 1019 | 6bae6c11e865 |
child 1024 | 5e446b5b3ec5 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
458
diff
changeset
|
3 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
593
diff
changeset
|
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
cbe0c766c947
(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
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
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
24fdb517fbe5
(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
527e47c8feec
(svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents:
337
diff
changeset
|
53 |
if (is_custom_sprite(spritenum)) { |
527e47c8feec
(svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents:
337
diff
changeset
|
54 |
int sprite = GetCustomVehicleIcon(engine, 6); |
527e47c8feec
(svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents:
337
diff
changeset
|
55 |
|
527e47c8feec
(svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents:
337
diff
changeset
|
56 |
if (sprite) { |
527e47c8feec
(svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents:
337
diff
changeset
|
57 |
DrawSprite(sprite | image_ormod, x, y); |
527e47c8feec
(svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents:
337
diff
changeset
|
58 |
return; |
527e47c8feec
(svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents:
337
diff
changeset
|
59 |
} |
527e47c8feec
(svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents:
337
diff
changeset
|
60 |
spritenum = _engine_original_sprites[engine]; |
527e47c8feec
(svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents:
337
diff
changeset
|
61 |
} |
527e47c8feec
(svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents:
337
diff
changeset
|
62 |
|
527e47c8feec
(svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents:
337
diff
changeset
|
63 |
DrawSprite((6 + _aircraft_sprite[spritenum]) | image_ormod, x, y); |
527e47c8feec
(svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents:
337
diff
changeset
|
64 |
|
538
24fdb517fbe5
(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
24fdb517fbe5
(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); |
24fdb517fbe5
(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); |
24fdb517fbe5
(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
10035216cbaf
(svn r1410) Replaced all occurences of 'passanger' by 'passenger' in the code
celestar
parents:
919
diff
changeset
|
74 |
SetDParam(2, avi->passenger_capacity); |
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
75 |
SetDParam(3, avi->mail_capacity); |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
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
65ecc321b3db
(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
24fdb517fbe5
(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
24fdb517fbe5
(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
24fdb517fbe5
(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 |
||
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
149 |
x = TileX(tile) * 16 + 5; |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
150 |
y = TileY(tile) * 16 + 3; |
0 | 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
24fdb517fbe5
(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
10035216cbaf
(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
24fdb517fbe5
(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
238bbdaa228b
(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
24fdb517fbe5
(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; |
24fdb517fbe5
(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
24fdb517fbe5
(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
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
203 |
_ptr_to_next_order->type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
204 |
_ptr_to_next_order->flags = 0; |
02df8a1b7f33
(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
65cdb609b7a6
(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
544f374ee392
(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
604af534c65d
(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
65cdb609b7a6
(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
544f374ee392
(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
544f374ee392
(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
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
699
diff
changeset
|
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
544f374ee392
(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
02df8a1b7f33
(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
02df8a1b7f33
(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++; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
368 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
369 |
v->current_order.flags = 0; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
699
diff
changeset
|
370 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 371 |
} |
372 |
} else { |
|
919
544f374ee392
(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 |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
376 |
if (st->xy == 0 || st->airport_tile == 0 || GetAirport(st->airport_type)->terminals == NULL) |
0 | 377 |
return CMD_ERROR; |
378 |
||
379 |
if (flags & DC_EXEC) { |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
380 |
v->current_order.type = OT_GOTO_DEPOT; |
02df8a1b7f33
(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; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
382 |
v->current_order.station = v->u.air.targetairport; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
699
diff
changeset
|
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
544f374ee392
(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 |
|
924
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
419 |
AircraftVehicleInfo *avi; |
0 | 420 |
|
421 |
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN); |
|
422 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
423 |
v = GetVehicle(p1); |
924
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
424 |
avi = AircraftVehInfo(v->engine_type); |
842 | 425 |
if (!CheckOwnership(v->owner) || (!CheckStoppedInHangar(v) && !(SkipStoppedInHangerCheck))) |
0 | 426 |
return CMD_ERROR; |
427 |
||
924
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
428 |
switch (new_cargo_type) { |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
429 |
case CT_PASSENGERS: |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
430 |
pass = avi->passenger_capacity; |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
431 |
break; |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
432 |
case CT_MAIL: |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
433 |
pass = avi->passenger_capacity + avi->mail_capacity; |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
434 |
break; |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
435 |
case CT_GOODS: |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
436 |
pass = avi->passenger_capacity + avi->mail_capacity; |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
437 |
pass /= 2; |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
438 |
break; |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
439 |
default: |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
440 |
pass = avi->passenger_capacity + avi->mail_capacity; |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
441 |
pass /= 4; |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
442 |
break; |
0 | 443 |
} |
444 |
_aircraft_refit_capacity = pass; |
|
445 |
||
446 |
cost = 0; |
|
842 | 447 |
if (IS_HUMAN_PLAYER(v->owner) && new_cargo_type != v->cargo_type) { |
0 | 448 |
cost = _price.aircraft_base >> 7; |
449 |
} |
|
450 |
||
451 |
if (flags & DC_EXEC) { |
|
452 |
v->cargo_cap = pass; |
|
453 |
||
454 |
u = v->next; |
|
924
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
455 |
mail = avi->mail_capacity; |
842 | 456 |
if (new_cargo_type != CT_PASSENGERS) { |
0 | 457 |
mail = 0; |
458 |
} |
|
459 |
u->cargo_cap = mail; |
|
842 | 460 |
//autorefitted planes wants to keep the cargo |
461 |
//it will be checked if the cargo is valid in CmdReplaceVehicle |
|
462 |
if (!(SkipStoppedInHangerCheck)) |
|
463 |
v->cargo_count = u->cargo_count = 0; |
|
464 |
v->cargo_type = new_cargo_type; |
|
0 | 465 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
466 |
} |
|
467 |
||
468 |
return cost; |
|
469 |
} |
|
470 |
||
471 |
void HandleClickOnAircraft(Vehicle *v) |
|
472 |
{ |
|
473 |
ShowAircraftViewWindow(v); |
|
474 |
} |
|
475 |
||
476 |
static void CheckIfAircraftNeedsService(Vehicle *v) |
|
477 |
{ |
|
478 |
Station *st; |
|
479 |
||
76
30511cbc5188
(svn r77) -Fix: [1010788] AI service interval bug (tnx truesatan)
truelight
parents:
70
diff
changeset
|
480 |
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
|
481 |
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
|
482 |
|
593 | 483 |
if (!VehicleNeedsService(v)) |
0 | 484 |
return; |
485 |
||
486 |
if (v->vehstatus & VS_STOPPED) |
|
487 |
return; |
|
488 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
489 |
if (v->current_order.type == OT_GOTO_DEPOT && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
490 |
v->current_order.flags & OF_FULL_LOAD) |
0 | 491 |
return; |
492 |
||
76
30511cbc5188
(svn r77) -Fix: [1010788] AI service interval bug (tnx truesatan)
truelight
parents:
70
diff
changeset
|
493 |
if (_patches.gotodepot && ScheduleHasDepotOrders(v->schedule_ptr)) |
0 | 494 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
495 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
496 |
st = GetStation(v->current_order.station); |
0 | 497 |
// only goto depot if the target airport has terminals (eg. it is airport) |
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
498 |
if (st->xy != 0 && st->airport_tile != 0 && GetAirport(st->airport_type)->terminals != NULL) { |
0 | 499 |
// printf("targetairport = %d, st->index = %d\n", v->u.air.targetairport, st->index); |
500 |
// v->u.air.targetairport = st->index; |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
501 |
v->current_order.type = OT_GOTO_DEPOT; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
502 |
v->current_order.flags = OF_NON_STOP; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
699
diff
changeset
|
503 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
504 |
} else if (v->current_order.type == OT_GOTO_DEPOT) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
505 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
506 |
v->current_order.flags = 0; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
699
diff
changeset
|
507 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 508 |
} |
509 |
} |
|
510 |
||
1020
59ee8ceac74c
(svn r1521) -Fix: Ship Vehicle Lists are now redrawn correctly
celestar
parents:
1019
diff
changeset
|
511 |
void InvalidateAircraftWindows(const Vehicle *v) |
1018
3212d4365653
(svn r1519) -Fix: [1102776], [1099535] Aircraft vehicle lists are now redrawn when an aircraft arrives in the depot. Station-specific vehicle lists are now redrawn daily as well (not only the master list)
celestar
parents:
950
diff
changeset
|
512 |
{ |
1020
59ee8ceac74c
(svn r1521) -Fix: Ship Vehicle Lists are now redrawn correctly
celestar
parents:
1019
diff
changeset
|
513 |
const Order *o; |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
514 |
|
1018
3212d4365653
(svn r1519) -Fix: [1102776], [1099535] Aircraft vehicle lists are now redrawn when an aircraft arrives in the depot. Station-specific vehicle lists are now redrawn daily as well (not only the master list)
celestar
parents:
950
diff
changeset
|
515 |
InvalidateWindow(WC_AIRCRAFT_LIST, v->owner); |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
516 |
|
1020
59ee8ceac74c
(svn r1521) -Fix: Ship Vehicle Lists are now redrawn correctly
celestar
parents:
1019
diff
changeset
|
517 |
for ( o = v->schedule_ptr; o->type != OT_NOTHING; o++) { |
1018
3212d4365653
(svn r1519) -Fix: [1102776], [1099535] Aircraft vehicle lists are now redrawn when an aircraft arrives in the depot. Station-specific vehicle lists are now redrawn daily as well (not only the master list)
celestar
parents:
950
diff
changeset
|
518 |
if (o->type == OT_GOTO_STATION ) { |
3212d4365653
(svn r1519) -Fix: [1102776], [1099535] Aircraft vehicle lists are now redrawn when an aircraft arrives in the depot. Station-specific vehicle lists are now redrawn daily as well (not only the master list)
celestar
parents:
950
diff
changeset
|
519 |
InvalidateWindow(WC_AIRCRAFT_LIST, o->station << 16 | v->owner); |
3212d4365653
(svn r1519) -Fix: [1102776], [1099535] Aircraft vehicle lists are now redrawn when an aircraft arrives in the depot. Station-specific vehicle lists are now redrawn daily as well (not only the master list)
celestar
parents:
950
diff
changeset
|
520 |
} |
3212d4365653
(svn r1519) -Fix: [1102776], [1099535] Aircraft vehicle lists are now redrawn when an aircraft arrives in the depot. Station-specific vehicle lists are now redrawn daily as well (not only the master list)
celestar
parents:
950
diff
changeset
|
521 |
} |
3212d4365653
(svn r1519) -Fix: [1102776], [1099535] Aircraft vehicle lists are now redrawn when an aircraft arrives in the depot. Station-specific vehicle lists are now redrawn daily as well (not only the master list)
celestar
parents:
950
diff
changeset
|
522 |
} |
3212d4365653
(svn r1519) -Fix: [1102776], [1099535] Aircraft vehicle lists are now redrawn when an aircraft arrives in the depot. Station-specific vehicle lists are now redrawn daily as well (not only the master list)
celestar
parents:
950
diff
changeset
|
523 |
|
0 | 524 |
void OnNewDay_Aircraft(Vehicle *v) |
525 |
{ |
|
526 |
int32 cost; |
|
527 |
||
528 |
if (v->subtype > 2) |
|
529 |
return; |
|
530 |
||
531 |
if ((++v->day_counter & 7) == 0) |
|
532 |
DecreaseVehicleValue(v); |
|
533 |
||
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
11
diff
changeset
|
534 |
CheckOrders(v); |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
11
diff
changeset
|
535 |
|
0 | 536 |
CheckVehicleBreakdown(v); |
537 |
AgeVehicle(v); |
|
538 |
CheckIfAircraftNeedsService(v); |
|
539 |
||
540 |
if (v->vehstatus & VS_STOPPED) |
|
541 |
return; |
|
542 |
||
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
543 |
cost = AircraftVehInfo(v->engine_type)->running_cost * _price.aircraft_running / 364; |
0 | 544 |
|
545 |
v->profit_this_year -= cost >> 8; |
|
546 |
||
547 |
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN); |
|
548 |
SubtractMoneyFromPlayerFract(v->owner, cost); |
|
549 |
||
550 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
551 |
} |
|
552 |
||
553 |
void AircraftYearlyLoop() |
|
554 |
{ |
|
555 |
Vehicle *v; |
|
556 |
||
557 |
FOR_ALL_VEHICLES(v) { |
|
558 |
if (v->type == VEH_Aircraft && v->subtype <= 2) { |
|
559 |
v->profit_last_year = v->profit_this_year; |
|
560 |
v->profit_this_year = 0; |
|
561 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
562 |
} |
|
563 |
} |
|
564 |
} |
|
565 |
||
566 |
static void AgeAircraftCargo(Vehicle *v) |
|
567 |
{ |
|
568 |
if (_age_cargo_skip_counter != 0) |
|
569 |
return; |
|
570 |
||
571 |
do { |
|
572 |
if (v->cargo_days != 0xFF) |
|
573 |
v->cargo_days++; |
|
574 |
} while ( (v=v->next) != NULL ); |
|
575 |
} |
|
576 |
||
577 |
static void HelicopterTickHandler(Vehicle *v) |
|
578 |
{ |
|
579 |
Vehicle *u; |
|
580 |
int tick,spd; |
|
581 |
uint16 img; |
|
582 |
||
583 |
u = v->next->next; |
|
584 |
||
585 |
if (u->vehstatus & VS_HIDDEN) |
|
586 |
return; |
|
587 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
588 |
// if true, helicopter rotors do not rotate. This should only be the case if a helicopter is |
0 | 589 |
// loading/unloading at a terminal or stopped |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
590 |
if (v->current_order.type == OT_LOADING || (v->vehstatus & VS_STOPPED)) { |
0 | 591 |
if (u->cur_speed != 0) { |
592 |
u->cur_speed++; |
|
593 |
if (u->cur_speed >= 0x80 && u->cur_image == 0xF40) { |
|
594 |
u->cur_speed = 0; |
|
595 |
} |
|
596 |
} |
|
597 |
} else { |
|
598 |
if (u->cur_speed == 0) |
|
599 |
u->cur_speed = 0x70; |
|
600 |
||
601 |
if (u->cur_speed >= 0x50) |
|
602 |
u->cur_speed--; |
|
603 |
} |
|
604 |
||
605 |
tick = ++u->tick_counter; |
|
606 |
spd = u->cur_speed >> 4; |
|
607 |
||
608 |
if (spd == 0) { |
|
609 |
img = 0xF3D; |
|
610 |
if (u->cur_image == img) |
|
611 |
return; |
|
612 |
} else if (tick >= spd) { |
|
613 |
u->tick_counter = 0; |
|
614 |
img = u->cur_image + 1; |
|
615 |
if (img > 0xF40) |
|
616 |
img = 0xF3E; |
|
617 |
} else |
|
618 |
return; |
|
619 |
||
620 |
u->cur_image=img; |
|
621 |
||
622 |
BeginVehicleMove(u); |
|
623 |
VehiclePositionChanged(u); |
|
624 |
EndVehicleMove(u); |
|
625 |
} |
|
626 |
||
627 |
static void SetAircraftPosition(Vehicle *v, int x, int y, int z) |
|
628 |
{ |
|
629 |
Vehicle *u; |
|
630 |
int yt; |
|
631 |
||
632 |
v->x_pos = x; |
|
633 |
v->y_pos = y; |
|
634 |
v->z_pos = z; |
|
635 |
||
636 |
v->cur_image = GetAircraftImage(v, v->direction); |
|
637 |
||
638 |
BeginVehicleMove(v); |
|
639 |
VehiclePositionChanged(v); |
|
640 |
EndVehicleMove(v); |
|
641 |
||
642 |
u = v->next; |
|
643 |
||
644 |
yt = y - ((v->z_pos-GetSlopeZ(x, y-1)) >> 3); |
|
645 |
u->x_pos = x; |
|
646 |
u->y_pos = yt; |
|
647 |
u->z_pos = GetSlopeZ(x,yt); |
|
648 |
u->cur_image = v->cur_image; |
|
649 |
||
650 |
BeginVehicleMove(u); |
|
651 |
VehiclePositionChanged(u); |
|
652 |
EndVehicleMove(u); |
|
653 |
||
654 |
if ((u=u->next) != NULL) { |
|
655 |
u->x_pos = x; |
|
656 |
u->y_pos = y; |
|
657 |
u->z_pos = z + 5; |
|
658 |
||
659 |
BeginVehicleMove(u); |
|
660 |
VehiclePositionChanged(u); |
|
661 |
EndVehicleMove(u); |
|
662 |
} |
|
663 |
} |
|
664 |
||
665 |
static void ServiceAircraft(Vehicle *v) |
|
666 |
{ |
|
667 |
Vehicle *u; |
|
668 |
||
669 |
v->cur_speed = 0; |
|
670 |
v->subspeed = 0; |
|
671 |
v->progress = 0; |
|
672 |
v->vehstatus |= VS_HIDDEN; |
|
673 |
||
674 |
u = v->next; |
|
675 |
u->vehstatus |= VS_HIDDEN; |
|
676 |
if ((u=u->next) != NULL) { |
|
677 |
u->vehstatus |= VS_HIDDEN; |
|
678 |
u->cur_speed = 0; |
|
679 |
} |
|
680 |
||
681 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos); |
|
682 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
683 |
||
578
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
684 |
VehicleServiceInDepot(v); |
0 | 685 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
686 |
} |
|
687 |
||
688 |
static void PlayAircraftSound(Vehicle *v) |
|
689 |
{ |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
690 |
SndPlayVehicleFx(AircraftVehInfo(v->engine_type)->sfx, v); |
0 | 691 |
} |
692 |
||
693 |
static bool UpdateAircraftSpeed(Vehicle *v) |
|
694 |
{ |
|
695 |
uint spd = v->acceleration * 2; |
|
696 |
byte t; |
|
697 |
||
698 |
v->subspeed = (t=v->subspeed) + (byte)spd; |
|
699 |
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
|
700 |
|
0 | 701 |
// adjust speed for broken vehicles |
702 |
if(v->vehstatus&VS_AIRCRAFT_BROKEN) spd = min(spd, 27); |
|
703 |
||
704 |
//updates statusbar only if speed have changed to save CPU time |
|
705 |
if (spd != v->cur_speed) { |
|
706 |
v->cur_speed = spd; |
|
707 |
if (_patches.vehicle_speed) |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
699
diff
changeset
|
708 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 709 |
} |
710 |
||
711 |
if (!(v->direction & 1)) { |
|
712 |
spd = spd * 3 >> 2; |
|
713 |
} |
|
714 |
||
715 |
if (spd == 0) |
|
716 |
return false; |
|
717 |
||
718 |
if ((byte)++spd == 0) |
|
719 |
return true; |
|
720 |
||
721 |
v->progress = (t = v->progress) - (byte)spd; |
|
722 |
||
723 |
return (t < v->progress); |
|
724 |
} |
|
725 |
||
726 |
// get Aircraft running altitude |
|
727 |
static byte GetAircraftFlyingAltitude(const Vehicle *v) |
|
728 |
{ |
|
729 |
byte maxz = 162; |
|
730 |
if (v->max_speed != 37) { |
|
731 |
maxz = 171; |
|
732 |
if (v->max_speed != 74) {maxz = 180;} |
|
733 |
} |
|
734 |
return maxz; |
|
735 |
} |
|
736 |
||
737 |
static bool Aircraft_5(Vehicle *v) |
|
738 |
{ |
|
739 |
Station *st; |
|
740 |
const AirportMovingData *amd; |
|
741 |
Vehicle *u; |
|
742 |
byte z,dirdiff,newdir,maxz,curz; |
|
743 |
GetNewVehiclePosResult gp; |
|
744 |
uint dist; |
|
745 |
int x,y; |
|
746 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
747 |
st = GetStation(v->u.air.targetairport); |
0 | 748 |
|
749 |
// prevent going to 0,0 if airport is deleted. |
|
750 |
{ |
|
751 |
uint tile = st->airport_tile; |
|
752 |
if (tile == 0) tile = st->xy; |
|
753 |
// xy of destination |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
754 |
x = TileX(tile) * 16; |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
755 |
y = TileY(tile) * 16; |
0 | 756 |
} |
757 |
||
758 |
// get airport moving data |
|
759 |
assert(v->u.air.pos < GetAirport(st->airport_type)->nofelements); |
|
760 |
amd = &_airport_moving_datas[st->airport_type][v->u.air.pos]; |
|
761 |
||
762 |
// Helicopter raise |
|
763 |
if (amd->flag & AMED_HELI_RAISE) { |
|
764 |
u = v->next->next; |
|
765 |
||
766 |
// Make sure the rotors don't rotate too fast |
|
767 |
if (u->cur_speed > 32) { |
|
768 |
v->cur_speed = 0; |
|
769 |
if (--u->cur_speed == 32) { |
|
541 | 770 |
SndPlayVehicleFx(SND_18_HELICOPTER, v); |
0 | 771 |
} |
772 |
} else { |
|
773 |
u->cur_speed = 32; |
|
774 |
if (UpdateAircraftSpeed(v)) { |
|
775 |
v->tile = 0; |
|
776 |
||
777 |
// Reached altitude? |
|
778 |
if (v->z_pos >= 184) { |
|
779 |
v->cur_speed = 0; |
|
780 |
return true; |
|
781 |
} |
|
782 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos+1); |
|
783 |
} |
|
784 |
} |
|
785 |
return false; |
|
786 |
} |
|
787 |
||
788 |
// Helicopter landing. |
|
789 |
if (amd->flag & AMED_HELI_LOWER) { |
|
790 |
if (UpdateAircraftSpeed(v)) { |
|
791 |
if (st->airport_tile == 0) { |
|
792 |
// FIXME - Aircraft_5 -> if station no longer exists, do not land |
|
793 |
// helicopter will circle until sign disappears, then go to next order |
|
794 |
// * what to do when it is the only order left, right now it just stays in 1 place |
|
795 |
v->u.air.state = FLYING; |
|
796 |
AircraftNextAirportPos_and_Order(v); |
|
797 |
return false; |
|
798 |
} |
|
799 |
||
800 |
// Vehicle is now at the airport. |
|
801 |
v->tile = st->airport_tile; |
|
802 |
||
803 |
// Find altitude of landing position. |
|
804 |
z = GetSlopeZ(x, y) + 1; |
|
805 |
if (st->airport_type == AT_OILRIG) z += 54; |
|
806 |
if (st->airport_type == AT_HELIPORT) z += 60; |
|
807 |
||
808 |
if (z == v->z_pos) { |
|
809 |
u = v->next->next; |
|
810 |
||
811 |
// Increase speed of rotors. When speed is 80, we've landed. |
|
812 |
if (u->cur_speed >= 80) |
|
813 |
return true; |
|
814 |
u->cur_speed+=4; |
|
815 |
} else if (v->z_pos > z) { |
|
816 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos-1); |
|
817 |
} else { |
|
818 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos+1); |
|
819 |
} |
|
820 |
} |
|
821 |
return false; |
|
822 |
} |
|
823 |
||
824 |
// Get distance from destination pos to current pos. |
|
825 |
dist = myabs(x + amd->x - v->x_pos) + myabs(y + amd->y - v->y_pos); |
|
826 |
||
827 |
// Need exact position? |
|
828 |
if (!(amd->flag & AMED_EXACTPOS) && dist <= (uint)((amd->flag&AMED_SLOWTURN)?8:4)) |
|
829 |
return true; |
|
830 |
||
831 |
// At final pos? |
|
832 |
if (dist == 0) { |
|
833 |
||
834 |
// Clamp speed to 12. |
|
835 |
if (v->cur_speed > 12) |
|
836 |
v->cur_speed = 12; |
|
837 |
||
838 |
// Change direction smoothly to final direction. |
|
839 |
dirdiff = amd->direction - v->direction; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
840 |
// if distance is 0, and plane points in right direction, no point in calling |
0 | 841 |
// UpdateAircraftSpeed(). So do it only afterwards |
842 |
if (dirdiff == 0) { |
|
843 |
v->cur_speed = 0; |
|
844 |
return true; |
|
845 |
} |
|
846 |
||
847 |
if (!UpdateAircraftSpeed(v)) |
|
848 |
return false; |
|
849 |
||
850 |
v->direction = (v->direction+((dirdiff&7)<5?1:-1)) & 7; |
|
851 |
v->cur_speed >>= 1; |
|
852 |
||
853 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos); |
|
854 |
return false; |
|
855 |
} |
|
856 |
||
857 |
// Clamp speed? |
|
858 |
if (!(amd->flag & AMED_NOSPDCLAMP) && v->cur_speed > 12) |
|
859 |
v->cur_speed = 12; |
|
860 |
||
861 |
if (!UpdateAircraftSpeed(v)) |
|
862 |
return false; |
|
863 |
||
864 |
// Decrease animation counter. |
|
865 |
if (v->load_unload_time_rem != 0) |
|
866 |
v->load_unload_time_rem--; |
|
867 |
||
868 |
// Turn. Do it slowly if in the air. |
|
869 |
newdir = GetDirectionTowards(v, x + amd->x, y + amd->y); |
|
870 |
if (newdir != v->direction) { |
|
871 |
if (amd->flag & AMED_SLOWTURN) { |
|
872 |
if (v->load_unload_time_rem == 0) { |
|
873 |
v->load_unload_time_rem = 8; |
|
874 |
} |
|
99 | 875 |
v->direction = newdir; |
0 | 876 |
} else { |
877 |
v->cur_speed >>= 1; |
|
878 |
v->direction = newdir; |
|
879 |
} |
|
880 |
} |
|
881 |
||
882 |
// Move vehicle. |
|
883 |
GetNewVehiclePos(v, &gp); |
|
884 |
v->tile = gp.new_tile; |
|
885 |
||
886 |
// If vehicle is in the air, use tile coordinate 0. |
|
887 |
if (amd->flag & (AMED_TAKEOFF | AMED_SLOWTURN | AMED_LAND)) { |
|
888 |
v->tile = 0; |
|
889 |
} |
|
890 |
||
891 |
// Adjust Z for land or takeoff? |
|
892 |
z = v->z_pos; |
|
893 |
||
894 |
if (amd->flag & AMED_TAKEOFF) { |
|
895 |
z+=2; |
|
896 |
// Determine running altitude |
|
897 |
maxz = GetAircraftFlyingAltitude(v); |
|
898 |
if (z > maxz) |
|
899 |
z = maxz; |
|
900 |
} |
|
901 |
||
902 |
if (amd->flag & AMED_LAND) { |
|
903 |
if (st->airport_tile == 0) { |
|
904 |
//FIXME -- FIXED - Aircraft_5 -> if station no longer exists, do not land |
|
905 |
// * what to do when it is the only order left, right now it just stays in 1 place? |
|
906 |
v->u.air.state = FLYING; |
|
907 |
AircraftNextAirportPos_and_Order(v); |
|
908 |
// get aircraft back on running altitude |
|
909 |
SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v)); |
|
910 |
return false; |
|
911 |
} |
|
912 |
||
913 |
curz = GetSlopeZ(x, y) + 1; |
|
914 |
||
915 |
if (curz > z) { |
|
916 |
z++; |
|
917 |
} else { |
|
918 |
int t = max(1, dist-4); |
|
919 |
||
920 |
z -= ((z - curz) + t - 1) / t; |
|
921 |
if (z < curz) z = curz; |
|
922 |
} |
|
923 |
} |
|
924 |
||
925 |
// We've landed. Decrase speed when we're reaching end of runway. |
|
926 |
if (amd->flag & AMED_BRAKE) { |
|
927 |
curz = GetSlopeZ(x, y) + 1; |
|
928 |
||
929 |
if (z > curz) z--; |
|
930 |
else if (z < curz) z++; |
|
931 |
||
932 |
if (dist < 64 && v->cur_speed > 12) |
|
933 |
v->cur_speed -= 4; |
|
934 |
} |
|
935 |
||
936 |
SetAircraftPosition(v, gp.x, gp.y, z); |
|
937 |
return false; |
|
938 |
} |
|
939 |
||
940 |
static const int8 _crashed_aircraft_moddir[4] = { |
|
941 |
-1,0,0,1 |
|
942 |
}; |
|
943 |
||
944 |
static void HandleCrashedAircraft(Vehicle *v) |
|
945 |
{ |
|
946 |
uint32 r; |
|
947 |
Station *st; |
|
899
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
948 |
int z; |
0 | 949 |
|
950 |
v->u.air.crashed_counter++; |
|
951 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
952 |
st = GetStation(v->u.air.targetairport); |
899
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
953 |
|
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
954 |
// make aircraft crash down to the ground |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
955 |
if ( st->airport_tile==0 && ((v->u.air.crashed_counter % 3) == 0) ) { |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
956 |
z = GetSlopeZ(v->x_pos, v->y_pos) + 1; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
957 |
v->z_pos -= 1; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
958 |
if (v->z_pos < z) |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
959 |
DoDeleteAircraft(v); |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
960 |
} |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
961 |
|
0 | 962 |
if (v->u.air.crashed_counter < 650) { |
963 |
if (CHANCE16R(1,32,r)) { |
|
964 |
v->direction = (v->direction+_crashed_aircraft_moddir[(r >> 16)&3]) & 7; |
|
965 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos); |
|
966 |
r = Random(); |
|
967 |
CreateEffectVehicleRel(v, |
|
968 |
4 + (r&0xF), |
|
969 |
4 + ((r>>4)&0xF), |
|
970 |
((r>>8)&0xF), |
|
971 |
EV_DEMOLISH); |
|
972 |
} |
|
973 |
} else if (v->u.air.crashed_counter >= 10000) { |
|
974 |
// remove rubble of crashed airplane |
|
975 |
||
976 |
// clear runway-in on all airports, set by crashing plane |
|
977 |
// small airports use AIRPORT_BUSY, city airports use RUNWAY_IN_OUT_block, etc. |
|
978 |
// but they all share the same number |
|
979 |
CLRBITS(st->airport_flags, RUNWAY_IN_block); |
|
980 |
||
981 |
BeginVehicleMove(v); |
|
982 |
EndVehicleMove(v); |
|
983 |
||
984 |
DoDeleteAircraft(v); |
|
985 |
} |
|
986 |
} |
|
987 |
||
988 |
static void HandleBrokenAircraft(Vehicle *v) |
|
989 |
{ |
|
990 |
if (v->breakdown_ctr != 1) { |
|
991 |
v->breakdown_ctr = 1; |
|
992 |
v->vehstatus |= VS_AIRCRAFT_BROKEN; |
|
993 |
||
994 |
if (v->breakdowns_since_last_service != 255) |
|
995 |
v->breakdowns_since_last_service++; |
|
996 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
|
997 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
998 |
} |
|
999 |
} |
|
1000 |
||
1001 |
static const int8 _aircraft_smoke_xy[16] = { |
|
1002 |
5,6,5,0,-5,-6,-5,0, /* x coordinates */ |
|
1003 |
5,0,-5,-6,-5,0,5,6, /* y coordinate */ |
|
1004 |
}; |
|
1005 |
||
1006 |
static void HandleAircraftSmoke(Vehicle *v) |
|
1007 |
{ |
|
1008 |
if (!(v->vehstatus&VS_AIRCRAFT_BROKEN)) |
|
1009 |
return; |
|
1010 |
||
1011 |
if (v->cur_speed < 10) { |
|
1012 |
v->vehstatus &= ~VS_AIRCRAFT_BROKEN; |
|
1013 |
v->breakdown_ctr = 0; |
|
1014 |
return; |
|
1015 |
} |
|
1016 |
||
1017 |
if ((v->tick_counter & 0x1F) == 0) { |
|
1018 |
CreateEffectVehicleRel(v, |
|
1019 |
_aircraft_smoke_xy[v->direction], |
|
1020 |
_aircraft_smoke_xy[v->direction + 8], |
|
1021 |
2, |
|
1022 |
EV_SMOKE_3 |
|
1023 |
); |
|
1024 |
} |
|
1025 |
} |
|
1026 |
||
899
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1027 |
// returns true if the vehicle does have valid orders |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1028 |
// false if none are valid |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1029 |
static bool CheckForValidOrders(Vehicle *v) |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1030 |
{ |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1031 |
int i; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1032 |
for (i = 0; i < v->num_orders; i++) { |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1033 |
if( v->schedule_ptr[i].type != OT_DUMMY ) |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1034 |
return true; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1035 |
} |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1036 |
return false; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1037 |
} |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1038 |
|
0 | 1039 |
static void ProcessAircraftOrder(Vehicle *v) |
1040 |
{ |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1041 |
Order order; |
0 | 1042 |
|
1043 |
// OT_GOTO_DEPOT, OT_LOADING |
|
899
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1044 |
if (v->current_order.type == OT_GOTO_DEPOT || |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1045 |
v->current_order.type == OT_LOADING) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1046 |
if (v->current_order.type != OT_GOTO_DEPOT || |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1047 |
!(v->current_order.flags & OF_UNLOAD)) |
0 | 1048 |
return; |
1049 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1050 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1051 |
if (v->current_order.type == OT_GOTO_DEPOT && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1052 |
(v->current_order.flags & (OF_UNLOAD | OF_FULL_LOAD)) == (OF_UNLOAD | OF_FULL_LOAD) && |
593 | 1053 |
!VehicleNeedsService(v)) { |
0 | 1054 |
v->cur_order_index++; |
1055 |
} |
|
1056 |
||
1057 |
if (v->cur_order_index >= v->num_orders) |
|
1058 |
v->cur_order_index = 0; |
|
1059 |
||
1060 |
order = v->schedule_ptr[v->cur_order_index]; |
|
1061 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1062 |
if (order.type == OT_NOTHING) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1063 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1064 |
v->current_order.flags = 0; |
0 | 1065 |
return; |
1066 |
} |
|
1067 |
||
901
0e42c4b151e3
(svn r1387) Fix: Airplanes now also crash when only one invalid order is in the schedule
dominik
parents:
899
diff
changeset
|
1068 |
if ( order.type == OT_DUMMY && !CheckForValidOrders(v)) |
0e42c4b151e3
(svn r1387) Fix: Airplanes now also crash when only one invalid order is in the schedule
dominik
parents:
899
diff
changeset
|
1069 |
CrashAirplane(v); |
0e42c4b151e3
(svn r1387) Fix: Airplanes now also crash when only one invalid order is in the schedule
dominik
parents:
899
diff
changeset
|
1070 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1071 |
if (order.type == v->current_order.type && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1072 |
order.flags == v->current_order.flags && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1073 |
order.station == v->current_order.station) |
0 | 1074 |
return; |
1075 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1076 |
v->current_order = order; |
0 | 1077 |
|
1078 |
// orders are changed in flight, ensure going to the right station |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1079 |
if (order.type == OT_GOTO_STATION && v->u.air.state == FLYING) { |
0 | 1080 |
AircraftNextAirportPos_and_Order(v); |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1081 |
v->u.air.targetairport = order.station; |
0 | 1082 |
} |
1083 |
||
1084 |
InvalidateVehicleOrderWidget(v); |
|
1020
59ee8ceac74c
(svn r1521) -Fix: Ship Vehicle Lists are now redrawn correctly
celestar
parents:
1019
diff
changeset
|
1085 |
|
59ee8ceac74c
(svn r1521) -Fix: Ship Vehicle Lists are now redrawn correctly
celestar
parents:
1019
diff
changeset
|
1086 |
InvalidateAircraftWindows(v); |
0 | 1087 |
} |
1088 |
||
1089 |
static void HandleAircraftLoading(Vehicle *v, int mode) |
|
1090 |
{ |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1091 |
if (v->current_order.type == OT_NOTHING) |
0 | 1092 |
return; |
1093 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1094 |
if (v->current_order.type != OT_DUMMY) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1095 |
if (v->current_order.type != OT_LOADING) |
0 | 1096 |
return; |
1097 |
||
1098 |
if (mode != 0) |
|
1099 |
return; |
|
1100 |
||
1101 |
if (--v->load_unload_time_rem) |
|
1102 |
return; |
|
1103 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1104 |
if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) { |
0 | 1105 |
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC); |
1106 |
LoadUnloadVehicle(v); |
|
1107 |
return; |
|
1108 |
} |
|
1109 |
||
1110 |
{ |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1111 |
Order b = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1112 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1113 |
v->current_order.flags = 0; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1114 |
if (!(b.flags & OF_NON_STOP)) |
0 | 1115 |
return; |
1116 |
} |
|
1117 |
} |
|
1118 |
v->cur_order_index++; |
|
1119 |
InvalidateVehicleOrderWidget(v); |
|
1120 |
} |
|
1121 |
||
899
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1122 |
static void CrashAirplane(Vehicle *v) |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1123 |
{ |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1124 |
uint16 amt; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1125 |
Station *st; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1126 |
StringID newsitem; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1127 |
|
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1128 |
v->vehstatus |= VS_CRASHED; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1129 |
v->u.air.crashed_counter = 0; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1130 |
|
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1131 |
CreateEffectVehicleRel(v, 4, 4, 8, EV_CRASHED_SMOKE); |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1132 |
|
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1133 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1134 |
|
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1135 |
amt = 2; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1136 |
if (v->cargo_type == CT_PASSENGERS) amt += v->cargo_count; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1137 |
SetDParam(0, amt); |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1138 |
|
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1139 |
v->cargo_count = 0; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1140 |
v->next->cargo_count = 0, |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1141 |
st = GetStation(v->u.air.targetairport); |
899
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1142 |
if(st->airport_tile==0) { |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1143 |
newsitem = STR_PLANE_CRASH_OUT_OF_FUEL; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1144 |
} else { |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1145 |
SetDParam(1, st->index); |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1146 |
newsitem = STR_A034_PLANE_CRASH_DIE_IN_FIREBALL; |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1147 |
} |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1148 |
|
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1149 |
SetDParam(1, st->index); |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1150 |
AddNewsItem(newsitem, |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1151 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1152 |
v->index, |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1153 |
0); |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1154 |
|
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1155 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1156 |
} |
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1157 |
|
0 | 1158 |
static void MaybeCrashAirplane(Vehicle *v) |
1159 |
{ |
|
1160 |
Station *st; |
|
1161 |
uint16 prob; |
|
1162 |
int i; |
|
1163 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1164 |
st = GetStation(v->u.air.targetairport); |
0 | 1165 |
|
1166 |
//FIXME -- MaybeCrashAirplane -> increase crashing chances of very modern airplanes on smaller than AT_METROPOLITAN airports |
|
1167 |
prob = 0x10000 / 1500; |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
1168 |
if (st->airport_type == AT_SMALL && (AircraftVehInfo(v->engine_type)->subtype & 2) && !_cheats.no_jetcrash.value) { |
0 | 1169 |
prob = 0x10000 / 20; |
1170 |
} |
|
1171 |
||
1172 |
if ((uint16)Random() > prob) |
|
1173 |
return; |
|
1174 |
||
1175 |
// Crash the airplane. Remove all goods stored at the station. |
|
1176 |
for(i=0; i!=NUM_CARGO; i++) { |
|
1177 |
st->goods[i].rating = 1; |
|
1178 |
st->goods[i].waiting_acceptance &= ~0xFFF; |
|
1179 |
} |
|
1180 |
||
899
69db9cb6bc9d
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
dominik
parents:
842
diff
changeset
|
1181 |
CrashAirplane(v); |
0 | 1182 |
} |
1183 |
||
1184 |
// we've landed and just arrived at a terminal |
|
1185 |
static void AircraftEntersTerminal(Vehicle *v) |
|
1186 |
{ |
|
1187 |
Station *st; |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1188 |
Order old_order; |
0 | 1189 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1190 |
if (v->current_order.type == OT_GOTO_DEPOT) |
0 | 1191 |
return; |
1192 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1193 |
st = GetStation(v->u.air.targetairport); |
0 | 1194 |
v->last_station_visited = v->u.air.targetairport; |
1195 |
||
1196 |
/* Check if station was ever visited before */ |
|
1197 |
if (!(st->had_vehicle_of_type & HVOT_AIRCRAFT)) { |
|
1198 |
uint32 flags; |
|
1199 |
||
1200 |
st->had_vehicle_of_type |= HVOT_AIRCRAFT; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1201 |
SetDParam(0, st->index); |
0 | 1202 |
// show newsitem of celebrating citizens |
1203 |
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); |
|
1204 |
AddNewsItem( |
|
1205 |
STR_A033_CITIZENS_CELEBRATE_FIRST, |
|
1206 |
flags, |
|
1207 |
v->index, |
|
1208 |
0); |
|
1209 |
} |
|
1210 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1211 |
old_order = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1212 |
v->current_order.type = OT_LOADING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1213 |
v->current_order.flags = 0; |
0 | 1214 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1215 |
if (old_order.type == OT_GOTO_STATION && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1216 |
v->current_order.station == v->last_station_visited) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1217 |
v->current_order.flags = |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1218 |
(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD)) | OF_NON_STOP; |
0 | 1219 |
} |
1220 |
||
1221 |
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC); |
|
1222 |
LoadUnloadVehicle(v); |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
699
diff
changeset
|
1223 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1224 |
} |
1225 |
||
1226 |
static void AircraftEnterHangar(Vehicle *v) |
|
1227 |
{ |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1228 |
Order old_order; |
0 | 1229 |
|
1230 |
ServiceAircraft(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1231 |
|
842 | 1232 |
MaybeReplaceVehicle(v); |
0 | 1233 |
|
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
410
diff
changeset
|
1234 |
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
410
diff
changeset
|
1235 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1236 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
0 | 1237 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
1238 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1239 |
old_order = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1240 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1241 |
v->current_order.flags = 0; |
0 | 1242 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1243 |
if (old_order.flags & OF_UNLOAD) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1244 |
v->cur_order_index++; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1245 |
} else if (old_order.flags & OF_FULL_LOAD) { // force depot visit |
0 | 1246 |
v->vehstatus |= VS_STOPPED; |
1018
3212d4365653
(svn r1519) -Fix: [1102776], [1099535] Aircraft vehicle lists are now redrawn when an aircraft arrives in the depot. Station-specific vehicle lists are now redrawn daily as well (not only the master list)
celestar
parents:
950
diff
changeset
|
1247 |
InvalidateAircraftWindows(v); |
0 | 1248 |
|
1249 |
if (v->owner == _local_player) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1250 |
SetDParam(0, v->unitnumber); |
0 | 1251 |
AddNewsItem( |
1252 |
STR_A014_AIRCRAFT_IS_WAITING_IN, |
|
1253 |
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), |
|
1254 |
v->index, |
|
1255 |
0); |
|
1256 |
} |
|
1257 |
} |
|
1258 |
} |
|
1259 |
} |
|
1260 |
||
1261 |
static void AircraftLand(Vehicle *v) |
|
1262 |
{ |
|
1263 |
v->sprite_width = v->sprite_height = 2; |
|
1264 |
} |
|
1265 |
||
1266 |
static void AircraftLandAirplane(Vehicle *v) |
|
1267 |
{ |
|
1268 |
AircraftLand(v); |
|
541 | 1269 |
SndPlayVehicleFx(SND_17_SKID_PLANE, v); |
0 | 1270 |
MaybeCrashAirplane(v); |
1271 |
} |
|
1272 |
||
1273 |
// set the right pos when heading to other airports after takeoff |
|
1274 |
static void AircraftNextAirportPos_and_Order(Vehicle *v) |
|
1275 |
{ |
|
1276 |
Station *st; |
|
1277 |
const AirportFTAClass *Airport; |
|
1278 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1279 |
if (v->current_order.type == OT_GOTO_STATION || |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1280 |
v->current_order.type == OT_GOTO_DEPOT) |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1281 |
v->u.air.targetairport = v->current_order.station; |
0 | 1282 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1283 |
st = GetStation(v->u.air.targetairport); |
0 | 1284 |
Airport = GetAirport(st->airport_type); |
1285 |
v->u.air.pos = v->u.air.previous_pos = Airport->entry_point; |
|
1286 |
} |
|
1287 |
||
1288 |
static void AircraftLeaveHangar(Vehicle *v) |
|
1289 |
{ |
|
1290 |
v->cur_speed = 0; |
|
1291 |
v->subspeed = 0; |
|
1292 |
v->progress = 0; |
|
1293 |
v->direction = 3; |
|
1294 |
v->vehstatus &= ~VS_HIDDEN; |
|
1295 |
{ |
|
1296 |
Vehicle *u = v->next; |
|
1297 |
u->vehstatus &= ~VS_HIDDEN; |
|
1298 |
||
1299 |
// Rotor blades |
|
1300 |
if ((u=u->next) != NULL) { |
|
1301 |
u->vehstatus &= ~VS_HIDDEN; |
|
1302 |
u->cur_speed = 80; |
|
1303 |
} |
|
1304 |
} |
|
1305 |
||
578
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
1306 |
VehicleServiceInDepot(v); |
0 | 1307 |
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos); |
1308 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
1309 |
} |
|
1310 |
||
1311 |
||
1312 |
//////////////////////////////////////////////////////////////////////////////// |
|
1313 |
/////////////////// AIRCRAFT MOVEMENT SCHEME //////////////////////////////// |
|
1314 |
//////////////////////////////////////////////////////////////////////////////// |
|
1315 |
static void AircraftEventHandler_EnterTerminal(Vehicle *v, const AirportFTAClass *Airport) |
|
1316 |
{ |
|
1317 |
AircraftEntersTerminal(v); |
|
1318 |
v->u.air.state = Airport->layout[v->u.air.pos].heading; |
|
1319 |
} |
|
1320 |
||
1321 |
static void AircraftEventHandler_EnterHangar(Vehicle *v, const AirportFTAClass *Airport) |
|
1322 |
{ |
|
1323 |
AircraftEnterHangar(v); |
|
1324 |
v->u.air.state = Airport->layout[v->u.air.pos].heading; |
|
1325 |
} |
|
1326 |
||
1327 |
// In an Airport Hangar |
|
1328 |
static void AircraftEventHandler_InHangar(Vehicle *v, const AirportFTAClass *Airport) |
|
1329 |
{ |
|
1330 |
// if we just arrived, execute EnterHangar first |
|
1331 |
if (v->u.air.previous_pos != v->u.air.pos) { |
|
1332 |
AircraftEventHandler_EnterHangar(v, Airport); |
|
1333 |
return; |
|
1334 |
} |
|
1335 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1336 |
// if we were sent to the depot, stay there |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1337 |
if (v->current_order.type == OT_GOTO_DEPOT && (v->vehstatus & VS_STOPPED)) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1338 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1339 |
v->current_order.flags = 0; |
0 | 1340 |
return; |
1341 |
} |
|
1342 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1343 |
if (v->current_order.type != OT_GOTO_STATION && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1344 |
v->current_order.type != OT_GOTO_DEPOT) |
0 | 1345 |
return; |
1346 |
||
1347 |
// if the block of the next position is busy, stay put |
|
1348 |
if (AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) {return;} |
|
1349 |
||
1350 |
// We are already at the target airport, we need to find a terminal |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1351 |
if (v->current_order.station == v->u.air.targetairport) { |
0 | 1352 |
// FindFreeTerminal: |
1353 |
// 1. Find a free terminal, 2. Occupy it, 3. Set the vehicle's state to that terminal |
|
1354 |
if (v->subtype != 0) {if(!AirportFindFreeTerminal(v, Airport)) {return;}} // airplane |
|
1355 |
else {if(!AirportFindFreeHelipad(v, Airport)) {return;}} // helicopter |
|
1356 |
} |
|
1357 |
else { // Else prepare for launch. |
|
1358 |
// airplane goto state takeoff, helicopter to helitakeoff |
|
1359 |
v->u.air.state = (v->subtype != 0) ? TAKEOFF : HELITAKEOFF; |
|
1360 |
} |
|
1361 |
AircraftLeaveHangar(v); |
|
1362 |
AirportMove(v, Airport); |
|
1363 |
} |
|
1364 |
||
1365 |
// At one of the Airport's Terminals |
|
1366 |
static void AircraftEventHandler_AtTerminal(Vehicle *v, const AirportFTAClass *Airport) |
|
1367 |
{ |
|
1368 |
// if we just arrived, execute EnterTerminal first |
|
1369 |
if (v->u.air.previous_pos != v->u.air.pos) { |
|
1370 |
AircraftEventHandler_EnterTerminal(v, Airport); |
|
1371 |
// on an airport with helipads, a helicopter will always land there |
|
1372 |
// and get serviced at the same time - patch setting |
|
1373 |
if (_patches.serviceathelipad) { |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1374 |
if (v->subtype == 0 && Airport->helipads != NULL) { |
0 | 1375 |
// an exerpt of ServiceAircraft, without the invisibility stuff |
1376 |
v->date_of_last_service = _date; |
|
1377 |
v->breakdowns_since_last_service = 0; |
|
1378 |
v->reliability = _engines[v->engine_type].reliability; |
|
1379 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1380 |
} |
|
1381 |
} |
|
1382 |
return; |
|
1383 |
} |
|
1384 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1385 |
if (v->current_order.type == OT_NOTHING) return; |
0 | 1386 |
|
1387 |
// if the block of the next position is busy, stay put |
|
1388 |
if (AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) { |
|
1389 |
return; |
|
1390 |
} |
|
1391 |
||
1392 |
// airport-road is free. We either have to go to another airport, or to the hangar |
|
1393 |
// ---> start moving |
|
1394 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1395 |
switch (v->current_order.type) { |
0 | 1396 |
case OT_GOTO_STATION: // ready to fly to another airport |
1397 |
// airplane goto state takeoff, helicopter to helitakeoff |
|
1398 |
v->u.air.state = (v->subtype != 0) ? TAKEOFF : HELITAKEOFF; |
|
1399 |
break; |
|
1400 |
case OT_GOTO_DEPOT: // visit hangar for serivicing, sale, etc. |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1401 |
if (v->current_order.station == v->u.air.targetairport) |
0 | 1402 |
v->u.air.state = HANGAR; |
1403 |
else |
|
1404 |
v->u.air.state = (v->subtype != 0) ? TAKEOFF : HELITAKEOFF; |
|
1405 |
break; |
|
1406 |
default: // orders have been deleted (no orders), goto depot and don't bother us |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1407 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1408 |
v->current_order.flags = 0; |
0 | 1409 |
v->u.air.state = HANGAR; |
1410 |
} |
|
1411 |
AirportMove(v, Airport); |
|
1412 |
} |
|
1413 |
||
1414 |
static void AircraftEventHandler_General(Vehicle *v, const AirportFTAClass *Airport) |
|
1415 |
{ |
|
70
60216d94f7c1
(svn r71) -Cheat: [976127] no extra frequent jet crash on small airports (truesatan)
darkvater
parents:
19
diff
changeset
|
1416 |
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
|
1417 |
assert(0); |
0 | 1418 |
} |
1419 |
||
1420 |
static void AircraftEventHandler_TakeOff(Vehicle *v, const AirportFTAClass *Airport) { |
|
1421 |
PlayAircraftSound(v); // play takeoffsound for airplanes |
|
1422 |
v->u.air.state = STARTTAKEOFF; |
|
1423 |
} |
|
1424 |
||
1425 |
static void AircraftEventHandler_StartTakeOff(Vehicle *v, const AirportFTAClass *Airport) |
|
1426 |
{ |
|
1427 |
v->sprite_width = v->sprite_height = 24; // ??? no idea what this is |
|
1428 |
v->u.air.state = ENDTAKEOFF; |
|
1429 |
} |
|
1430 |
||
1431 |
static void AircraftEventHandler_EndTakeOff(Vehicle *v, const AirportFTAClass *Airport) |
|
1432 |
{ |
|
1433 |
v->u.air.state = FLYING; |
|
1434 |
// get the next position to go to, differs per airport |
|
1435 |
AircraftNextAirportPos_and_Order(v); |
|
1436 |
} |
|
1437 |
||
1438 |
static void AircraftEventHandler_HeliTakeOff(Vehicle *v, const AirportFTAClass *Airport) |
|
1439 |
{ |
|
1440 |
v->sprite_width = v->sprite_height = 24; // ??? no idea what this is |
|
1441 |
v->u.air.state = FLYING; |
|
1442 |
// get the next position to go to, differs per airport |
|
1443 |
AircraftNextAirportPos_and_Order(v); |
|
1444 |
} |
|
1445 |
||
1446 |
static void AircraftEventHandler_Flying(Vehicle *v, const AirportFTAClass *Airport) |
|
1447 |
{ |
|
1448 |
Station *st; |
|
1449 |
byte landingtype; |
|
1450 |
AirportFTA *current; |
|
1451 |
uint16 tcur_speed, tsubspeed; |
|
1452 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1453 |
st = GetStation(v->u.air.targetairport); |
0 | 1454 |
// flying device is accepted at this station |
1455 |
// small airport --> no helicopters (AIRCRAFT_ONLY) |
|
1456 |
// all other airports --> all types of flying devices (ALL) |
|
1457 |
// heliport/oilrig, etc --> no airplanes (HELICOPTERS_ONLY) |
|
1458 |
// runway busy or not allowed to use this airstation, circle |
|
1459 |
if (! (v->subtype == Airport->acc_planes || |
|
1460 |
st->airport_tile == 0 || (st->owner != OWNER_NONE && st->owner != v->owner) )) { |
|
1461 |
||
1462 |
// {32,FLYING,NOTHING_block,37}, {32,LANDING,N,33}, {32,HELILANDING,N,41}, |
|
1463 |
// if it is an airplane, look for LANDING, for helicopter HELILANDING |
|
1464 |
// it is possible to choose from multiple landing runways, so loop until a free one is found |
|
1465 |
landingtype = (v->subtype != 0) ? LANDING : HELILANDING; |
|
1466 |
current = Airport->layout[v->u.air.pos].next_in_chain; |
|
1467 |
while (current != NULL) { |
|
1468 |
if (current->heading == landingtype) { |
|
1469 |
// save speed before, since if AirportHasBlock is false, it resets them to 0 |
|
1470 |
// we don't want that for plane in air |
|
1471 |
// hack for speed thingie |
|
1472 |
tcur_speed = v->cur_speed; |
|
1473 |
tsubspeed = v->subspeed; |
|
1474 |
if (!AirportHasBlock(v, current, Airport)) { |
|
1475 |
v->u.air.state = landingtype; // LANDING / HELILANDING |
|
1476 |
// it's a bit dirty, but I need to set position to next position, otherwise |
|
1477 |
// if there are multiple runways, plane won't know which one it took (because |
|
1478 |
// they all have heading LANDING). And also occupy that block! |
|
1479 |
v->u.air.pos = current->next_position; |
|
1480 |
SETBITS(st->airport_flags, Airport->layout[v->u.air.pos].block); |
|
1481 |
return; |
|
1482 |
} |
|
1483 |
v->cur_speed = tcur_speed; |
|
1484 |
v->subspeed = tsubspeed; |
|
1485 |
} |
|
1486 |
current = current->next_in_chain; |
|
1487 |
} |
|
1488 |
} |
|
1489 |
v->u.air.state = FLYING; |
|
1490 |
v->u.air.pos = Airport->layout[v->u.air.pos].next_position; |
|
1491 |
} |
|
1492 |
||
1493 |
static void AircraftEventHandler_Landing(Vehicle *v, const AirportFTAClass *Airport) |
|
1494 |
{ |
|
1495 |
AircraftLandAirplane(v); // maybe crash airplane |
|
1496 |
v->u.air.state = ENDLANDING; |
|
1497 |
} |
|
1498 |
||
1499 |
static void AircraftEventHandler_HeliLanding(Vehicle *v, const AirportFTAClass *Airport) |
|
1500 |
{ |
|
1501 |
AircraftLand(v); // helicopters don't crash |
|
1502 |
v->u.air.state = HELIENDLANDING; |
|
1503 |
} |
|
1504 |
||
1505 |
static void AircraftEventHandler_EndLanding(Vehicle *v, const AirportFTAClass *Airport) |
|
1506 |
{ |
|
1507 |
// next block busy, don't do a thing, just wait |
|
1508 |
if(AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) {return;} |
|
1509 |
||
1510 |
// if going to terminal (OT_GOTO_STATION) choose one |
|
1511 |
// 1. in case all terminals are busy AirportFindFreeTerminal() returns false or |
|
1512 |
// 2. not going for terminal (but depot, no order), |
|
1513 |
// --> get out of the way to the hangar. |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1514 |
if (v->current_order.type == OT_GOTO_STATION) { |
0 | 1515 |
if (AirportFindFreeTerminal(v, Airport)) {return;} |
1516 |
} |
|
1517 |
v->u.air.state = HANGAR; |
|
1518 |
||
1519 |
} |
|
1520 |
||
1521 |
static void AircraftEventHandler_HeliEndLanding(Vehicle *v, const AirportFTAClass *Airport) |
|
1522 |
{ |
|
1523 |
// next block busy, don't do a thing, just wait |
|
1524 |
if(AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) {return;} |
|
1525 |
||
1526 |
// if going to helipad (OT_GOTO_STATION) choose one. If airport doesn't have helipads, choose terminal |
|
1527 |
// 1. in case all terminals/helipads are busy (AirportFindFreeHelipad() returns false) or |
|
1528 |
// 2. not going for terminal (but depot, no order), |
|
1529 |
// --> get out of the way to the hangar IF there are terminals on the airport. |
|
1530 |
// --> else TAKEOFF |
|
1531 |
// the reason behind this is that if an airport has a terminal, it also has a hangar. Airplanes |
|
1532 |
// must go to a hangar. |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1533 |
if (v->current_order.type == OT_GOTO_STATION) { |
0 | 1534 |
if (AirportFindFreeHelipad(v, Airport)) {return;} |
1535 |
} |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1536 |
v->u.air.state = (Airport->terminals != NULL) ? HANGAR : HELITAKEOFF; |
0 | 1537 |
} |
1538 |
||
1539 |
typedef void AircraftStateHandler(Vehicle *v, const AirportFTAClass *Airport); |
|
1540 |
static AircraftStateHandler * const _aircraft_state_handlers[] = { |
|
1541 |
AircraftEventHandler_General, // TO_ALL = 0 |
|
1542 |
AircraftEventHandler_InHangar, // HANGAR = 1 |
|
1543 |
AircraftEventHandler_AtTerminal, // TERM1 = 2 |
|
1544 |
AircraftEventHandler_AtTerminal, // TERM2 = 3 |
|
1545 |
AircraftEventHandler_AtTerminal, // TERM3 = 4 |
|
1546 |
AircraftEventHandler_AtTerminal, // TERM4 = 5 |
|
1547 |
AircraftEventHandler_AtTerminal, // TERM5 = 6 |
|
1548 |
AircraftEventHandler_AtTerminal, // TERM6 = 7 |
|
1549 |
AircraftEventHandler_AtTerminal, // HELIPAD1 = 8 |
|
1550 |
AircraftEventHandler_AtTerminal, // HELIPAD2 = 9 |
|
1551 |
AircraftEventHandler_TakeOff, // TAKEOFF = 10 |
|
1552 |
AircraftEventHandler_StartTakeOff, // STARTTAKEOFF = 11 |
|
1553 |
AircraftEventHandler_EndTakeOff, // ENDTAKEOFF = 12 |
|
1554 |
AircraftEventHandler_HeliTakeOff, // HELITAKEOFF = 13 |
|
1555 |
AircraftEventHandler_Flying, // FLYING = 14 |
|
1556 |
AircraftEventHandler_Landing, // LANDING = 15 |
|
1557 |
AircraftEventHandler_EndLanding, // ENDLANDING = 16 |
|
1558 |
AircraftEventHandler_HeliLanding, // HELILANDING = 17 |
|
1559 |
AircraftEventHandler_HeliEndLanding,// HELIENDLANDING = 18 |
|
1560 |
}; |
|
1561 |
||
1562 |
static void AirportClearBlock(Vehicle *v, const AirportFTAClass *Airport) |
|
1563 |
{ |
|
1564 |
Station *st; |
|
1565 |
// we have left the previous block, and entered the new one. Free the previous block |
|
1566 |
if (Airport->layout[v->u.air.previous_pos].block != Airport->layout[v->u.air.pos].block) { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1567 |
st = GetStation(v->u.air.targetairport); |
0 | 1568 |
CLRBITS(st->airport_flags, Airport->layout[v->u.air.previous_pos].block); |
1569 |
} |
|
1570 |
} |
|
1571 |
||
1572 |
static void AirportGoToNextPosition(Vehicle *v, const AirportFTAClass *Airport) |
|
1573 |
{ |
|
1574 |
// if aircraft is not in position, wait until it is |
|
1575 |
if (!Aircraft_5(v)) {return;} |
|
1576 |
||
1577 |
AirportClearBlock(v, Airport); |
|
1578 |
AirportMove(v, Airport); // move aircraft to next position |
|
1579 |
} |
|
1580 |
||
1581 |
// gets pos from vehicle and next orders |
|
1582 |
static bool AirportMove(Vehicle *v, const AirportFTAClass *Airport) |
|
1583 |
{ |
|
1584 |
AirportFTA *current; |
|
1585 |
byte prev_pos; |
|
1586 |
bool retval = false; |
|
1587 |
||
1588 |
// error handling |
|
1589 |
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
|
1590 |
DEBUG(misc, 0) ("position %d is not valid for current airport. Max position is %d", v->u.air.pos, Airport->nofelements-1); |
0 | 1591 |
assert(v->u.air.pos < Airport->nofelements); |
1592 |
} |
|
1593 |
||
1594 |
current = &Airport->layout[v->u.air.pos]; |
|
1595 |
// we have arrived in an important state (eg terminal, hangar, etc.) |
|
1596 |
if (current->heading == v->u.air.state) { |
|
1597 |
prev_pos = v->u.air.pos; // location could be changed in state, so save it before-hand |
|
1598 |
_aircraft_state_handlers[v->u.air.state](v, Airport); |
|
1599 |
if (v->u.air.state != FLYING) {v->u.air.previous_pos = prev_pos;} |
|
1600 |
return true; |
|
1601 |
} |
|
1602 |
||
1603 |
v->u.air.previous_pos = v->u.air.pos; // save previous location |
|
1604 |
||
1605 |
// there is only one choice to move to |
|
1606 |
if (current->next_in_chain == NULL) { |
|
1607 |
if (AirportSetBlocks(v, current, Airport)) { |
|
1608 |
v->u.air.pos = current->next_position; |
|
1609 |
} // move to next position |
|
1610 |
return retval; |
|
1611 |
} |
|
1612 |
||
1613 |
// there are more choices to choose from, choose the one that |
|
1614 |
// matches our heading |
|
1615 |
do { |
|
1616 |
if (v->u.air.state == current->heading || current->heading == TO_ALL) { |
|
1617 |
if (AirportSetBlocks(v, current, Airport)) { |
|
1618 |
v->u.air.pos = current->next_position; |
|
1619 |
} // move to next position |
|
1620 |
return retval; |
|
1621 |
} |
|
1622 |
current = current->next_in_chain; |
|
1623 |
} while (current != NULL); |
|
1624 |
||
70
60216d94f7c1
(svn r71) -Cheat: [976127] no extra frequent jet crash on small airports (truesatan)
darkvater
parents:
19
diff
changeset
|
1625 |
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
|
1626 |
DEBUG(misc, 0) ("Airport entry point: %d, Vehicle: %d", Airport->entry_point, v->index); |
0 | 1627 |
assert(0); |
1628 |
return false; |
|
1629 |
} |
|
1630 |
||
1631 |
// returns true if the road ahead is busy, eg. you must wait before proceeding |
|
1632 |
static bool AirportHasBlock(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport) |
|
1633 |
{ |
|
1634 |
Station *st; |
|
1635 |
uint32 airport_flags; |
|
1636 |
AirportFTA *next, *reference; |
|
1637 |
reference = &Airport->layout[v->u.air.pos]; |
|
1638 |
next = &Airport->layout[current_pos->next_position]; |
|
1639 |
||
1640 |
// same block, then of course we can move |
|
1641 |
if (Airport->layout[current_pos->position].block != next->block) { |
|
1642 |
airport_flags = next->block; |
|
919
544f374ee392
(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 |
// check additional possible extra blocks |
1645 |
if (current_pos != reference && current_pos->block != NOTHING_block) { |
|
1646 |
airport_flags |= current_pos->block; |
|
1647 |
} |
|
1648 |
||
1649 |
if (HASBITS(st->airport_flags, airport_flags)) { |
|
1650 |
v->cur_speed = 0; |
|
1651 |
v->subspeed = 0; |
|
1652 |
return true; |
|
1653 |
} |
|
1654 |
} |
|
1655 |
return false; |
|
1656 |
} |
|
1657 |
||
1658 |
// returns true on success. Eg, next block was free and we have occupied it |
|
1659 |
static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport) |
|
1660 |
{ |
|
1661 |
Station *st; |
|
1662 |
uint32 airport_flags; |
|
1663 |
AirportFTA *current, *reference, *next; |
|
1664 |
next = &Airport->layout[current_pos->next_position]; |
|
1665 |
reference = &Airport->layout[v->u.air.pos]; |
|
1666 |
||
1667 |
// if the next position is in another block, check it and wait until it is free |
|
1668 |
if (Airport->layout[current_pos->position].block != next->block) { |
|
1669 |
airport_flags = next->block; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1670 |
st = GetStation(v->u.air.targetairport); |
0 | 1671 |
//search for all all elements in the list with the same state, and blocks != N |
1672 |
// this means more blocks should be checked/set |
|
1673 |
current = current_pos; |
|
1674 |
if (current == reference) { current = current->next_in_chain;} |
|
1675 |
while (current != NULL) { |
|
1676 |
if (current->heading == current_pos->heading && current->block != 0) { |
|
1677 |
airport_flags |= current->block; |
|
1678 |
break; |
|
1679 |
} |
|
1680 |
current = current->next_in_chain; |
|
1681 |
}; |
|
1682 |
||
1683 |
// if the block to be checked is in the next position, then exclude that from |
|
1684 |
// checking, because it has been set by the airplane before |
|
1685 |
if (current_pos->block == next->block) {airport_flags ^= next->block;} |
|
1686 |
||
1687 |
if (HASBITS(st->airport_flags, airport_flags)) { |
|
1688 |
v->cur_speed = 0; |
|
1689 |
v->subspeed = 0; |
|
1690 |
return false; |
|
1691 |
} |
|
1692 |
||
1693 |
if (next->block != NOTHING_block) { |
|
1694 |
SETBITS(st->airport_flags, airport_flags); // occupy next block |
|
1695 |
} |
|
1696 |
} |
|
1697 |
return true; |
|
1698 |
} |
|
1699 |
||
1700 |
static bool FreeTerminal(Vehicle *v, byte i, byte last_terminal) |
|
1701 |
{ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1702 |
Station *st = GetStation(v->u.air.targetairport); |
0 | 1703 |
for (; i < last_terminal; i++) { |
1704 |
if (!HASBIT(st->airport_flags, i)) { |
|
1705 |
// TERMINAL# HELIPAD# |
|
1706 |
v->u.air.state = i + TERM1; // start moving to that terminal/helipad |
|
1707 |
SETBIT(st->airport_flags, i); // occupy terminal/helipad |
|
1708 |
return true; |
|
1709 |
} |
|
1710 |
} |
|
1711 |
return false; |
|
1712 |
} |
|
1713 |
||
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1714 |
static int GetNumTerminals(const AirportFTAClass *Airport) |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1715 |
{ |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1716 |
int i, num = 0; |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
1717 |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1718 |
for (i = Airport->terminals[0]; i > 0; i--) |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1719 |
num += Airport->terminals[i]; |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
1720 |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1721 |
return num; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1722 |
} |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1723 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1724 |
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport) |
0 | 1725 |
{ |
1726 |
AirportFTA *temp; |
|
1727 |
Station *st; |
|
1728 |
||
1729 |
/* example of more terminalgroups |
|
1730 |
{0,HANGAR,NOTHING_block,1}, {0,255,TERM_GROUP1_block,0}, {0,255,TERM_GROUP2_ENTER_block,1}, {0,0,N,1}, |
|
1731 |
Heading 255 denotes a group. We see 2 groups here: |
|
1732 |
1. group 0 -- TERM_GROUP1_block (check block) |
|
1733 |
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
|
1734 |
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
|
1735 |
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
|
1736 |
possible groups are checked (in this case group 1, since that is after group 0). If that |
0 | 1737 |
fails, then attempt fails and plane waits |
1738 |
*/ |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1739 |
if (Airport->terminals[0] > 1) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1740 |
st = GetStation(v->u.air.targetairport); |
0 | 1741 |
temp = Airport->layout[v->u.air.pos].next_in_chain; |
1742 |
while (temp != NULL) { |
|
1743 |
if (temp->heading == 255) { |
|
1744 |
if (!HASBITS(st->airport_flags, temp->block)) { |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1745 |
int target_group; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1746 |
int i; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1747 |
int group_start = 0; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1748 |
int group_end; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1749 |
|
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1750 |
//read which group do we want to go to? |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1751 |
//(the first free group) |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1752 |
target_group = temp->next_position + 1; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1753 |
|
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1754 |
//at what terminal does the group start? |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1755 |
//that means, sum up all terminals of |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1756 |
//groups with lower number |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1757 |
for(i = 1; i < target_group; i++) |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1758 |
group_start += Airport->terminals[i]; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1759 |
|
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1760 |
group_end = group_start + Airport->terminals[target_group]; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1761 |
if (FreeTerminal(v, group_start, group_end)) {return true;} |
0 | 1762 |
} |
1763 |
} |
|
1764 |
else {return false;} // once the heading isn't 255, we've exhausted the possible blocks. So we cannot move |
|
1765 |
temp = temp->next_in_chain; |
|
1766 |
} |
|
1767 |
} |
|
1768 |
||
1769 |
// if there is only 1 terminalgroup, all terminals are checked (starting from 0 to max) |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1770 |
return FreeTerminal(v, 0, GetNumTerminals(Airport)); |
0 | 1771 |
} |
1772 |
||
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1773 |
static int GetNumHelipads(const AirportFTAClass *Airport) |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1774 |
{ |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1775 |
int i, num = 0; |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
1776 |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1777 |
for (i = Airport->helipads[0]; i > 0; i--) |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1778 |
num += Airport->helipads[i]; |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
1779 |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1780 |
return num; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1781 |
} |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1782 |
|
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1783 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1784 |
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport) |
0 | 1785 |
{ |
1786 |
Station *st; |
|
1787 |
AirportFTA *temp; |
|
1788 |
||
1789 |
// if an airport doesn't have helipads, use terminals |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1790 |
if (Airport->helipads == NULL) {return AirportFindFreeTerminal(v, Airport);} |
0 | 1791 |
|
1792 |
// if there are more helicoptergroups, pick one, just as in AirportFindFreeTerminal() |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1793 |
if (Airport->helipads[0] > 1) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1794 |
st = GetStation(v->u.air.targetairport); |
0 | 1795 |
temp = Airport->layout[v->u.air.pos].next_in_chain; |
1796 |
while (temp != NULL) { |
|
1797 |
if (temp->heading == 255) { |
|
1798 |
if (!HASBITS(st->airport_flags, temp->block)) { |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1799 |
int target_group; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1800 |
int i; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1801 |
int group_start = 0; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1802 |
int group_end; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1803 |
|
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1804 |
//read which group do we want to go to? |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1805 |
//(the first free group) |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1806 |
target_group = temp->next_position + 1; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1807 |
|
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1808 |
//at what terminal does the group start? |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1809 |
//that means, sum up all terminals of |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1810 |
//groups with lower number |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1811 |
for(i = 1; i < target_group; i++) |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1812 |
group_start += Airport->helipads[i]; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1813 |
|
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1814 |
group_end = group_start + Airport->helipads[target_group]; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1815 |
if (FreeTerminal(v, group_start, group_end)) {return true;} |
0 | 1816 |
} |
1817 |
} |
|
1818 |
else {return false;} // once the heading isn't 255, we've exhausted the possible blocks. So we cannot move |
|
1819 |
temp = temp->next_in_chain; |
|
1820 |
} |
|
1821 |
} |
|
1822 |
// only 1 helicoptergroup, check all helipads |
|
1823 |
// The blocks for helipads start after the last terminal (MAX_TERMINALS) |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1824 |
else {return FreeTerminal(v, MAX_TERMINALS, GetNumHelipads(Airport) + MAX_TERMINALS);} |
0 | 1825 |
return false; // it shouldn't get here anytime, but just to be sure |
1826 |
} |
|
1827 |
||
1828 |
static void AircraftEventHandler(Vehicle *v, int loop) |
|
1829 |
{ |
|
1830 |
v->tick_counter++; |
|
1831 |
||
1832 |
if (v->vehstatus & VS_CRASHED) { |
|
1833 |
HandleCrashedAircraft(v); |
|
1834 |
return; |
|
1835 |
} |
|
1836 |
||
1837 |
/* exit if aircraft is stopped */ |
|
1838 |
if (v->vehstatus & VS_STOPPED) |
|
1839 |
return; |
|
1840 |
||
1841 |
/* aircraft is broken down? */ |
|
1842 |
if (v->breakdown_ctr != 0) { |
|
1843 |
if (v->breakdown_ctr <= 2) { |
|
1844 |
HandleBrokenAircraft(v); |
|
1845 |
} else { |
|
1846 |
v->breakdown_ctr--; |
|
1847 |
} |
|
1848 |
} |
|
1849 |
||
1850 |
HandleAircraftSmoke(v); |
|
1851 |
ProcessAircraftOrder(v); |
|
1852 |
HandleAircraftLoading(v, loop); |
|
1853 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1854 |
if (v->current_order.type >= OT_LOADING) |
0 | 1855 |
return; |
1856 |
||
1857 |
// pass the right airport structure to the functions |
|
1858 |
// DEREF_STATION gets target airport (Station *st), its type is passed to GetAirport |
|
1859 |
// that returns the correct layout depending on type |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1860 |
AirportGoToNextPosition(v, GetAirport(GetStation(v->u.air.targetairport)->airport_type)); |
0 | 1861 |
} |
1862 |
||
1863 |
void Aircraft_Tick(Vehicle *v) |
|
1864 |
{ |
|
1865 |
int i; |
|
1866 |
||
1867 |
if (v->subtype > 2) |
|
1868 |
return; |
|
1869 |
||
1870 |
if (v->subtype == 0) |
|
1871 |
HelicopterTickHandler(v); |
|
1872 |
||
1873 |
AgeAircraftCargo(v); |
|
1874 |
||
1875 |
for(i=0; i!=6; i++) { |
|
1876 |
AircraftEventHandler(v, i); |
|
1877 |
if (v->type != VEH_Aircraft) // In case it was deleted |
|
1878 |
break; |
|
1879 |
} |
|
1880 |
} |
|
1881 |
||
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1882 |
void UpdateOilRig( void ) |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1883 |
{ |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1884 |
Station *st; |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1018
diff
changeset
|
1885 |
|
950
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1886 |
FOR_ALL_STATIONS(st) { |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1887 |
if (st->airport_type == 5) st->airport_type = AT_OILRIG; |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1888 |
} |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1889 |
} |
165341d74973
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
926
diff
changeset
|
1890 |
|
0 | 1891 |
// need to be called to load aircraft from old version |
1892 |
void UpdateOldAircraft() |
|
1893 |
{ |
|
1894 |
Station *st; |
|
1895 |
Vehicle *v_oldstyle; |
|
1896 |
GetNewVehiclePosResult gp; |
|
1897 |
||
1898 |
// set airport_flags to 0 for all airports just to be sure |
|
1899 |
FOR_ALL_STATIONS(st) { |
|
1900 |
st->airport_flags = 0; // reset airport |
|
1901 |
// type of oilrig has been moved, update it (3-5) |
|
1902 |
if (st->airport_type == 3) {st->airport_type = AT_OILRIG;} |
|
1903 |
} |
|
1904 |
||
1905 |
FOR_ALL_VEHICLES(v_oldstyle) { |
|
1906 |
// airplane has another vehicle with subtype 4 (shadow), helicopter also has 3 (rotor) |
|
1907 |
// skip those |
|
1908 |
if (v_oldstyle->type == VEH_Aircraft && v_oldstyle->subtype <= 2) { |
|
1909 |
// airplane in terminal stopped doesn't hurt anyone, so goto next |
|
1910 |
if ((v_oldstyle->vehstatus & VS_STOPPED) && (v_oldstyle->u.air.state == 0)) { |
|
1911 |
v_oldstyle->u.air.state = HANGAR; |
|
1912 |
continue; |
|
1913 |
} |
|
1914 |
||
1915 |
AircraftLeaveHangar(v_oldstyle); // make airplane visible if it was in a depot for example |
|
1916 |
v_oldstyle->vehstatus &= ~VS_STOPPED; // make airplane moving |
|
1917 |
v_oldstyle->u.air.state = FLYING; |
|
1918 |
AircraftNextAirportPos_and_Order(v_oldstyle); // move it to the entry point of the airport |
|
1919 |
GetNewVehiclePos(v_oldstyle, &gp); // get the position of the plane (to be used for setting) |
|
1920 |
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
|
1921 |
|
0 | 1922 |
// correct speed of helicopter-rotors |
1923 |
if (v_oldstyle->subtype == 0) {v_oldstyle->next->next->cur_speed = 32;} |
|
1924 |
||
1925 |
// set new position x,y,z |
|
1926 |
SetAircraftPosition(v_oldstyle, gp.x, gp.y, GetAircraftFlyingAltitude(v_oldstyle)); |
|
1927 |
} |
|
1928 |
} |
|
1929 |
} |
|
1930 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1931 |
void UpdateAirplanesOnNewStation(Station *st) |
0 | 1932 |
{ |
1933 |
GetNewVehiclePosResult gp; |
|
1934 |
Vehicle *v; |
|
1935 |
byte takeofftype; |
|
1936 |
uint16 cnt; |
|
1937 |
// only 1 station is updated per function call, so it is enough to get entry_point once |
|
1938 |
const AirportFTAClass *ap = GetAirport(st->airport_type); |
|
1939 |
FOR_ALL_VEHICLES(v) { |
|
1940 |
if (v->type == VEH_Aircraft && v->subtype <= 2) { |
|
1941 |
if (v->u.air.targetairport == st->index) { // if heading to this airport |
|
1942 |
/* update position of airplane. If plane is not flying, landing, or taking off |
|
1943 |
you cannot delete airport, so it doesn't matter |
|
1944 |
*/ |
|
1945 |
if (v->u.air.state >= FLYING) { // circle around |
|
1946 |
v->u.air.pos = v->u.air.previous_pos = ap->entry_point; |
|
1947 |
v->u.air.state = FLYING; |
|
1948 |
// landing plane needs to be reset to flying height (only if in pause mode upgrade, |
|
1949 |
// in normal mode, plane is reset in Aircraft_5. It doesn't hurt for FLYING |
|
1950 |
GetNewVehiclePos(v, &gp); |
|
1951 |
// set new position x,y,z |
|
1952 |
SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v)); |
|
1953 |
} |
|
1954 |
else { |
|
1955 |
assert(v->u.air.state == ENDTAKEOFF || v->u.air.state == HELITAKEOFF); |
|
1956 |
takeofftype = (v->subtype == 0) ? HELITAKEOFF : ENDTAKEOFF; |
|
1957 |
// search in airportdata for that heading |
|
1958 |
// easiest to do, since this doesn't happen a lot |
|
1959 |
for (cnt = 0; cnt < ap->nofelements; cnt++) { |
|
1960 |
if (ap->layout[cnt].heading == takeofftype) { |
|
1961 |
v->u.air.pos = ap->layout[cnt].position; |
|
1962 |
break; |
|
1963 |
} |
|
1964 |
} |
|
1965 |
} |
|
1966 |
} |
|
1967 |
} |
|
1968 |
} |
|
1969 |
} |