(svn r16388) -Codechange: move u.air to Aircraft

This commit is contained in:
rubidium 2009-05-22 20:07:26 +00:00
parent ada3067960
commit c882248348
13 changed files with 170 additions and 162 deletions

View File

@ -92,6 +92,13 @@ byte GetAircraftFlyingAltitude(const Aircraft *v);
* As side-effect the vehicle type is set correctly. * As side-effect the vehicle type is set correctly.
*/ */
struct Aircraft : public Vehicle { struct Aircraft : public Vehicle {
uint16 crashed_counter;
uint16 cached_max_speed;
byte pos;
byte previous_pos;
StationID targetairport;
byte state;
/** Initializes the Vehicle to an aircraft */ /** Initializes the Vehicle to an aircraft */
Aircraft() { this->type = VEH_AIRCRAFT; } Aircraft() { this->type = VEH_AIRCRAFT; }

View File

@ -40,7 +40,7 @@ void Aircraft::UpdateDeltaXY(Direction direction)
default: NOT_REACHED(); default: NOT_REACHED();
case AIR_AIRCRAFT: case AIR_AIRCRAFT:
case AIR_HELICOPTER: case AIR_HELICOPTER:
switch (this->u.air.state) { switch (this->state) {
case ENDTAKEOFF: case ENDTAKEOFF:
case LANDING: case LANDING:
case HELILANDING: case HELILANDING:
@ -173,7 +173,7 @@ SpriteID GetRotorImage(const Aircraft *v)
} }
/* Return standard rotor sprites if there are no custom sprites for this helicopter */ /* Return standard rotor sprites if there are no custom sprites for this helicopter */
return SPR_ROTOR_STOPPED + w->u.air.state; return SPR_ROTOR_STOPPED + w->state;
} }
static SpriteID GetAircraftIcon(EngineID engine) static SpriteID GetAircraftIcon(EngineID engine)
@ -368,14 +368,14 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
assert(i != apc->nof_depots); assert(i != apc->nof_depots);
if (st->airport_tile + ToTileIndexDiff(apc->airport_depots[i]) == tile) { if (st->airport_tile + ToTileIndexDiff(apc->airport_depots[i]) == tile) {
assert(apc->layout[i].heading == HANGAR); assert(apc->layout[i].heading == HANGAR);
v->u.air.pos = apc->layout[i].position; v->pos = apc->layout[i].position;
break; break;
} }
} }
v->u.air.state = HANGAR; v->state = HANGAR;
v->u.air.previous_pos = v->u.air.pos; v->previous_pos = v->pos;
v->u.air.targetairport = GetStationIndex(tile); v->targetairport = GetStationIndex(tile);
v->SetNext(u); v->SetNext(u);
v->service_interval = _settings_game.vehicle.servint_aircraft; v->service_interval = _settings_game.vehicle.servint_aircraft;
@ -411,7 +411,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
w->cur_image = SPR_ROTOR_STOPPED; w->cur_image = SPR_ROTOR_STOPPED;
w->random_bits = VehicleRandomBits(); w->random_bits = VehicleRandomBits();
/* Use rotor's air.state to store the rotor animation frame */ /* Use rotor's air.state to store the rotor animation frame */
w->u.air.state = HRS_ROTOR_STOPPED; w->state = HRS_ROTOR_STOPPED;
w->UpdateDeltaXY(INVALID_DIR); w->UpdateDeltaXY(INVALID_DIR);
u->SetNext(w); u->SetNext(w);
@ -594,8 +594,8 @@ static void CheckIfAircraftNeedsService(Aircraft *v)
/* only goto depot if the target airport has terminals (eg. it is airport) */ /* only goto depot if the target airport has terminals (eg. it is airport) */
if (st->airport_tile != INVALID_TILE && st->Airport()->terminals != NULL) { if (st->airport_tile != INVALID_TILE && st->Airport()->terminals != NULL) {
// printf("targetairport = %d, st->index = %d\n", v->u.air.targetairport, st->index); // printf("targetairport = %d, st->index = %d\n", v->targetairport, st->index);
// v->u.air.targetairport = st->index; // v->targetairport = st->index;
v->current_order.MakeGoToDepot(st->index, ODTFB_SERVICE); v->current_order.MakeGoToDepot(st->index, ODTFB_SERVICE);
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
} else if (v->current_order.IsType(OT_GOTO_DEPOT)) { } else if (v->current_order.IsType(OT_GOTO_DEPOT)) {
@ -655,7 +655,7 @@ static void HelicopterTickHandler(Aircraft *v)
if (v->current_order.IsType(OT_LOADING) || (v->vehstatus & VS_STOPPED)) { if (v->current_order.IsType(OT_LOADING) || (v->vehstatus & VS_STOPPED)) {
if (u->cur_speed != 0) { if (u->cur_speed != 0) {
u->cur_speed++; u->cur_speed++;
if (u->cur_speed >= 0x80 && u->u.air.state == HRS_ROTOR_MOVING_3) { if (u->cur_speed >= 0x80 && u->state == HRS_ROTOR_MOVING_3) {
u->cur_speed = 0; u->cur_speed = 0;
} }
} }
@ -672,13 +672,13 @@ static void HelicopterTickHandler(Aircraft *v)
SpriteID img; SpriteID img;
if (spd == 0) { if (spd == 0) {
u->u.air.state = HRS_ROTOR_STOPPED; u->state = HRS_ROTOR_STOPPED;
img = GetRotorImage(v); img = GetRotorImage(v);
if (u->cur_image == img) return; if (u->cur_image == img) return;
} else if (tick >= spd) { } else if (tick >= spd) {
u->tick_counter = 0; u->tick_counter = 0;
u->u.air.state++; u->state++;
if (u->u.air.state > HRS_ROTOR_MOVING_3) u->u.air.state = HRS_ROTOR_MOVING_1; if (u->state > HRS_ROTOR_MOVING_3) u->state = HRS_ROTOR_MOVING_1;
img = GetRotorImage(v); img = GetRotorImage(v);
} else { } else {
return; return;
@ -757,9 +757,9 @@ void UpdateAircraftCache(Aircraft *v)
/* Convert from original units to (approx) km/h */ /* Convert from original units to (approx) km/h */
max_speed = (max_speed * 129) / 10; max_speed = (max_speed * 129) / 10;
v->u.air.cached_max_speed = max_speed; v->cached_max_speed = max_speed;
} else { } else {
v->u.air.cached_max_speed = 0xFFFF; v->cached_max_speed = 0xFFFF;
} }
} }
@ -791,9 +791,9 @@ static int UpdateAircraftSpeed(Aircraft *v, uint speed_limit = SPEED_LIMIT_NONE,
* and take-off speeds being too low. */ * and take-off speeds being too low. */
speed_limit *= _settings_game.vehicle.plane_speed; speed_limit *= _settings_game.vehicle.plane_speed;
if (v->u.air.cached_max_speed < speed_limit) { if (v->cached_max_speed < speed_limit) {
if (v->cur_speed < speed_limit) hard_limit = false; if (v->cur_speed < speed_limit) hard_limit = false;
speed_limit = v->u.air.cached_max_speed; speed_limit = v->cached_max_speed;
} }
speed_limit = min(speed_limit, v->max_speed); speed_limit = min(speed_limit, v->max_speed);
@ -889,7 +889,7 @@ static byte AircraftGetEntryPoint(const Aircraft *v, const AirportFTAClass *apc)
* or it will simply crash in next tick */ * or it will simply crash in next tick */
TileIndex tile = 0; TileIndex tile = 0;
const Station *st = Station::GetIfValid(v->u.air.targetairport); const Station *st = Station::GetIfValid(v->targetairport);
if (st != NULL) { if (st != NULL) {
/* Make sure we don't go to INVALID_TILE if the airport has been removed. */ /* Make sure we don't go to INVALID_TILE if the airport has been removed. */
tile = (st->airport_tile != INVALID_TILE) ? st->airport_tile : st->xy; tile = (st->airport_tile != INVALID_TILE) ? st->airport_tile : st->xy;
@ -921,7 +921,7 @@ static bool AircraftController(Aircraft *v)
int count; int count;
/* NULL if station is invalid */ /* NULL if station is invalid */
const Station *st = Station::GetIfValid(v->u.air.targetairport); const Station *st = Station::GetIfValid(v->targetairport);
/* INVALID_TILE if there is no station */ /* INVALID_TILE if there is no station */
TileIndex tile = INVALID_TILE; TileIndex tile = INVALID_TILE;
if (st != NULL) { if (st != NULL) {
@ -933,11 +933,11 @@ static bool AircraftController(Aircraft *v)
/* prevent going to INVALID_TILE if airport is deleted. */ /* prevent going to INVALID_TILE if airport is deleted. */
if (st == NULL || st->airport_tile == INVALID_TILE) { if (st == NULL || st->airport_tile == INVALID_TILE) {
/* Jump into our "holding pattern" state machine if possible */ /* Jump into our "holding pattern" state machine if possible */
if (v->u.air.pos >= afc->nofelements) { if (v->pos >= afc->nofelements) {
v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, afc); v->pos = v->previous_pos = AircraftGetEntryPoint(v, afc);
} else if (v->u.air.targetairport != v->current_order.GetDestination()) { } else if (v->targetairport != v->current_order.GetDestination()) {
/* If not possible, just get out of here fast */ /* If not possible, just get out of here fast */
v->u.air.state = FLYING; v->state = FLYING;
UpdateAircraftCache(v); UpdateAircraftCache(v);
AircraftNextAirportPos_and_Order(v); AircraftNextAirportPos_and_Order(v);
/* get aircraft back on running altitude */ /* get aircraft back on running altitude */
@ -947,7 +947,7 @@ static bool AircraftController(Aircraft *v)
} }
/* get airport moving data */ /* get airport moving data */
const AirportMovingData *amd = afc->MovingData(v->u.air.pos); const AirportMovingData *amd = afc->MovingData(v->pos);
int x = TileX(tile) * TILE_SIZE; int x = TileX(tile) * TILE_SIZE;
int y = TileY(tile) * TILE_SIZE; int y = TileY(tile) * TILE_SIZE;
@ -983,7 +983,7 @@ static bool AircraftController(Aircraft *v)
/* FIXME - AircraftController -> if station no longer exists, do not land /* FIXME - AircraftController -> if station no longer exists, do not land
* helicopter will circle until sign disappears, then go to next order * helicopter will circle until sign disappears, then go to next order
* what to do when it is the only order left, right now it just stays in 1 place */ * what to do when it is the only order left, right now it just stays in 1 place */
v->u.air.state = FLYING; v->state = FLYING;
UpdateAircraftCache(v); UpdateAircraftCache(v);
AircraftNextAirportPos_and_Order(v); AircraftNextAirportPos_and_Order(v);
return false; return false;
@ -1102,7 +1102,7 @@ static bool AircraftController(Aircraft *v)
if (amd->flag & AMED_LAND) { if (amd->flag & AMED_LAND) {
if (st->airport_tile == INVALID_TILE) { if (st->airport_tile == INVALID_TILE) {
/* Airport has been removed, abort the landing procedure */ /* Airport has been removed, abort the landing procedure */
v->u.air.state = FLYING; v->state = FLYING;
UpdateAircraftCache(v); UpdateAircraftCache(v);
AircraftNextAirportPos_and_Order(v); AircraftNextAirportPos_and_Order(v);
/* get aircraft back on running altitude */ /* get aircraft back on running altitude */
@ -1142,21 +1142,21 @@ static bool AircraftController(Aircraft *v)
static bool HandleCrashedAircraft(Aircraft *v) static bool HandleCrashedAircraft(Aircraft *v)
{ {
v->u.air.crashed_counter += 3; v->crashed_counter += 3;
Station *st = GetTargetAirportIfValid(v); Station *st = GetTargetAirportIfValid(v);
/* make aircraft crash down to the ground */ /* make aircraft crash down to the ground */
if (v->u.air.crashed_counter < 500 && st == NULL && ((v->u.air.crashed_counter % 3) == 0) ) { if (v->crashed_counter < 500 && st == NULL && ((v->crashed_counter % 3) == 0) ) {
uint z = GetSlopeZ(v->x_pos, v->y_pos); uint z = GetSlopeZ(v->x_pos, v->y_pos);
v->z_pos -= 1; v->z_pos -= 1;
if (v->z_pos == z) { if (v->z_pos == z) {
v->u.air.crashed_counter = 500; v->crashed_counter = 500;
v->z_pos++; v->z_pos++;
} }
} }
if (v->u.air.crashed_counter < 650) { if (v->crashed_counter < 650) {
uint32 r; uint32 r;
if (Chance16R(1,32,r)) { if (Chance16R(1,32,r)) {
static const DirDiff delta[] = { static const DirDiff delta[] = {
@ -1172,7 +1172,7 @@ static bool HandleCrashedAircraft(Aircraft *v)
GB(r, 8, 4), GB(r, 8, 4),
EV_EXPLOSION_SMALL); EV_EXPLOSION_SMALL);
} }
} else if (v->u.air.crashed_counter >= 10000) { } else if (v->crashed_counter >= 10000) {
/* remove rubble of crashed airplane */ /* remove rubble of crashed airplane */
/* clear runway-in on all airports, set by crashing plane /* clear runway-in on all airports, set by crashing plane
@ -1276,7 +1276,7 @@ void HandleMissingAircraftOrders(Aircraft *v)
TileIndex Aircraft::GetOrderStationLocation(StationID station) TileIndex Aircraft::GetOrderStationLocation(StationID station)
{ {
/* Orders are changed in flight, ensure going to the right station. */ /* Orders are changed in flight, ensure going to the right station. */
if (this->u.air.state == FLYING) { if (this->state == FLYING) {
AircraftNextAirportPos_and_Order(this); AircraftNextAirportPos_and_Order(this);
} }
@ -1294,7 +1294,7 @@ void Aircraft::MarkDirty()
static void CrashAirplane(Aircraft *v) static void CrashAirplane(Aircraft *v)
{ {
v->vehstatus |= VS_CRASHED; v->vehstatus |= VS_CRASHED;
v->u.air.crashed_counter = 0; v->crashed_counter = 0;
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
@ -1330,7 +1330,7 @@ static void CrashAirplane(Aircraft *v)
static void MaybeCrashAirplane(Aircraft *v) static void MaybeCrashAirplane(Aircraft *v)
{ {
Station *st = Station::Get(v->u.air.targetairport); Station *st = Station::Get(v->targetairport);
/* FIXME -- MaybeCrashAirplane -> increase crashing chances of very modern airplanes on smaller than AT_METROPOLITAN airports */ /* FIXME -- MaybeCrashAirplane -> increase crashing chances of very modern airplanes on smaller than AT_METROPOLITAN airports */
uint16 prob = 0x10000 / 1500; uint16 prob = 0x10000 / 1500;
@ -1356,8 +1356,8 @@ static void AircraftEntersTerminal(Aircraft *v)
{ {
if (v->current_order.IsType(OT_GOTO_DEPOT)) return; if (v->current_order.IsType(OT_GOTO_DEPOT)) return;
Station *st = Station::Get(v->u.air.targetairport); Station *st = Station::Get(v->targetairport);
v->last_station_visited = v->u.air.targetairport; v->last_station_visited = v->targetairport;
/* Check if station was ever visited before */ /* Check if station was ever visited before */
if (!(st->had_vehicle_of_type & HVOT_AIRCRAFT)) { if (!(st->had_vehicle_of_type & HVOT_AIRCRAFT)) {
@ -1391,12 +1391,12 @@ static void AircraftLandAirplane(Aircraft *v)
void AircraftNextAirportPos_and_Order(Aircraft *v) void AircraftNextAirportPos_and_Order(Aircraft *v)
{ {
if (v->current_order.IsType(OT_GOTO_STATION) || v->current_order.IsType(OT_GOTO_DEPOT)) { if (v->current_order.IsType(OT_GOTO_STATION) || v->current_order.IsType(OT_GOTO_DEPOT)) {
v->u.air.targetairport = v->current_order.GetDestination(); v->targetairport = v->current_order.GetDestination();
} }
const Station *st = GetTargetAirportIfValid(v); const Station *st = GetTargetAirportIfValid(v);
const AirportFTAClass *apc = st == NULL ? GetAirport(AT_DUMMY) : st->Airport(); const AirportFTAClass *apc = st == NULL ? GetAirport(AT_DUMMY) : st->Airport();
v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, apc); v->pos = v->previous_pos = AircraftGetEntryPoint(v, apc);
} }
void AircraftLeaveHangar(Aircraft *v) void AircraftLeaveHangar(Aircraft *v)
@ -1470,20 +1470,20 @@ static inline bool CheckSendAircraftToHangarForReplacement(const Vehicle *v)
static void AircraftEventHandler_EnterTerminal(Aircraft *v, const AirportFTAClass *apc) static void AircraftEventHandler_EnterTerminal(Aircraft *v, const AirportFTAClass *apc)
{ {
AircraftEntersTerminal(v); AircraftEntersTerminal(v);
v->u.air.state = apc->layout[v->u.air.pos].heading; v->state = apc->layout[v->pos].heading;
} }
static void AircraftEventHandler_EnterHangar(Aircraft *v, const AirportFTAClass *apc) static void AircraftEventHandler_EnterHangar(Aircraft *v, const AirportFTAClass *apc)
{ {
VehicleEnterDepot(v); VehicleEnterDepot(v);
v->u.air.state = apc->layout[v->u.air.pos].heading; v->state = apc->layout[v->pos].heading;
} }
/** In an Airport Hangar */ /** In an Airport Hangar */
static void AircraftEventHandler_InHangar(Aircraft *v, const AirportFTAClass *apc) static void AircraftEventHandler_InHangar(Aircraft *v, const AirportFTAClass *apc)
{ {
/* if we just arrived, execute EnterHangar first */ /* if we just arrived, execute EnterHangar first */
if (v->u.air.previous_pos != v->u.air.pos) { if (v->previous_pos != v->pos) {
AircraftEventHandler_EnterHangar(v, apc); AircraftEventHandler_EnterHangar(v, apc);
return; return;
} }
@ -1499,10 +1499,10 @@ static void AircraftEventHandler_InHangar(Aircraft *v, const AirportFTAClass *ap
return; return;
/* if the block of the next position is busy, stay put */ /* if the block of the next position is busy, stay put */
if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return; if (AirportHasBlock(v, &apc->layout[v->pos], apc)) return;
/* We are already at the target airport, we need to find a terminal */ /* We are already at the target airport, we need to find a terminal */
if (v->current_order.GetDestination() == v->u.air.targetairport) { if (v->current_order.GetDestination() == v->targetairport) {
/* FindFreeTerminal: /* FindFreeTerminal:
* 1. Find a free terminal, 2. Occupy it, 3. Set the vehicle's state to that terminal */ * 1. Find a free terminal, 2. Occupy it, 3. Set the vehicle's state to that terminal */
if (v->subtype == AIR_HELICOPTER) { if (v->subtype == AIR_HELICOPTER) {
@ -1512,7 +1512,7 @@ static void AircraftEventHandler_InHangar(Aircraft *v, const AirportFTAClass *ap
} }
} else { // Else prepare for launch. } else { // Else prepare for launch.
/* airplane goto state takeoff, helicopter to helitakeoff */ /* airplane goto state takeoff, helicopter to helitakeoff */
v->u.air.state = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : TAKEOFF; v->state = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : TAKEOFF;
} }
AircraftLeaveHangar(v); AircraftLeaveHangar(v);
AirportMove(v, apc); AirportMove(v, apc);
@ -1522,7 +1522,7 @@ static void AircraftEventHandler_InHangar(Aircraft *v, const AirportFTAClass *ap
static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *apc) static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *apc)
{ {
/* if we just arrived, execute EnterTerminal first */ /* if we just arrived, execute EnterTerminal first */
if (v->u.air.previous_pos != v->u.air.pos) { if (v->previous_pos != v->pos) {
AircraftEventHandler_EnterTerminal(v, apc); AircraftEventHandler_EnterTerminal(v, apc);
/* on an airport with helipads, a helicopter will always land there /* on an airport with helipads, a helicopter will always land there
* and get serviced at the same time - setting */ * and get serviced at the same time - setting */
@ -1541,7 +1541,7 @@ static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *
if (v->current_order.IsType(OT_NOTHING)) return; if (v->current_order.IsType(OT_NOTHING)) return;
/* if the block of the next position is busy, stay put */ /* if the block of the next position is busy, stay put */
if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return; if (AirportHasBlock(v, &apc->layout[v->pos], apc)) return;
/* airport-road is free. We either have to go to another airport, or to the hangar /* airport-road is free. We either have to go to another airport, or to the hangar
* ---> start moving */ * ---> start moving */
@ -1551,7 +1551,7 @@ static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *
case OT_GOTO_STATION: // ready to fly to another airport case OT_GOTO_STATION: // ready to fly to another airport
break; break;
case OT_GOTO_DEPOT: // visit hangar for serivicing, sale, etc. case OT_GOTO_DEPOT: // visit hangar for serivicing, sale, etc.
go_to_hangar = v->current_order.GetDestination() == v->u.air.targetairport; go_to_hangar = v->current_order.GetDestination() == v->targetairport;
break; break;
case OT_CONDITIONAL: case OT_CONDITIONAL:
/* In case of a conditional order we just have to wait a tick /* In case of a conditional order we just have to wait a tick
@ -1560,14 +1560,14 @@ static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *
return; return;
default: // orders have been deleted (no orders), goto depot and don't bother us default: // orders have been deleted (no orders), goto depot and don't bother us
v->current_order.Free(); v->current_order.Free();
go_to_hangar = Station::Get(v->u.air.targetairport)->Airport()->nof_depots != 0; go_to_hangar = Station::Get(v->targetairport)->Airport()->nof_depots != 0;
} }
if (go_to_hangar) { if (go_to_hangar) {
v->u.air.state = HANGAR; v->state = HANGAR;
} else { } else {
/* airplane goto state takeoff, helicopter to helitakeoff */ /* airplane goto state takeoff, helicopter to helitakeoff */
v->u.air.state = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : TAKEOFF; v->state = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : TAKEOFF;
} }
AirportMove(v, apc); AirportMove(v, apc);
} }
@ -1580,25 +1580,25 @@ static void AircraftEventHandler_General(Aircraft *v, const AirportFTAClass *apc
static void AircraftEventHandler_TakeOff(Aircraft *v, const AirportFTAClass *apc) static void AircraftEventHandler_TakeOff(Aircraft *v, const AirportFTAClass *apc)
{ {
PlayAircraftSound(v); // play takeoffsound for airplanes PlayAircraftSound(v); // play takeoffsound for airplanes
v->u.air.state = STARTTAKEOFF; v->state = STARTTAKEOFF;
} }
static void AircraftEventHandler_StartTakeOff(Aircraft *v, const AirportFTAClass *apc) static void AircraftEventHandler_StartTakeOff(Aircraft *v, const AirportFTAClass *apc)
{ {
v->u.air.state = ENDTAKEOFF; v->state = ENDTAKEOFF;
v->UpdateDeltaXY(INVALID_DIR); v->UpdateDeltaXY(INVALID_DIR);
} }
static void AircraftEventHandler_EndTakeOff(Aircraft *v, const AirportFTAClass *apc) static void AircraftEventHandler_EndTakeOff(Aircraft *v, const AirportFTAClass *apc)
{ {
v->u.air.state = FLYING; v->state = FLYING;
/* get the next position to go to, differs per airport */ /* get the next position to go to, differs per airport */
AircraftNextAirportPos_and_Order(v); AircraftNextAirportPos_and_Order(v);
} }
static void AircraftEventHandler_HeliTakeOff(Aircraft *v, const AirportFTAClass *apc) static void AircraftEventHandler_HeliTakeOff(Aircraft *v, const AirportFTAClass *apc)
{ {
v->u.air.state = FLYING; v->state = FLYING;
v->UpdateDeltaXY(INVALID_DIR); v->UpdateDeltaXY(INVALID_DIR);
/* get the next position to go to, differs per airport */ /* get the next position to go to, differs per airport */
@ -1614,7 +1614,7 @@ static void AircraftEventHandler_HeliTakeOff(Aircraft *v, const AirportFTAClass
static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc) static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc)
{ {
Station *st = Station::Get(v->u.air.targetairport); Station *st = Station::Get(v->targetairport);
/* runway busy or not allowed to use this airstation, circle */ /* runway busy or not allowed to use this airstation, circle */
if (apc->flags & (v->subtype == AIR_HELICOPTER ? AirportFTAClass::HELICOPTERS : AirportFTAClass::AIRPLANES) && if (apc->flags & (v->subtype == AIR_HELICOPTER ? AirportFTAClass::HELICOPTERS : AirportFTAClass::AIRPLANES) &&
@ -1624,7 +1624,7 @@ static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc)
* if it is an airplane, look for LANDING, for helicopter HELILANDING * if it is an airplane, look for LANDING, for helicopter HELILANDING
* it is possible to choose from multiple landing runways, so loop until a free one is found */ * it is possible to choose from multiple landing runways, so loop until a free one is found */
byte landingtype = (v->subtype == AIR_HELICOPTER) ? HELILANDING : LANDING; byte landingtype = (v->subtype == AIR_HELICOPTER) ? HELILANDING : LANDING;
const AirportFTA *current = apc->layout[v->u.air.pos].next; const AirportFTA *current = apc->layout[v->pos].next;
while (current != NULL) { while (current != NULL) {
if (current->heading == landingtype) { if (current->heading == landingtype) {
/* save speed before, since if AirportHasBlock is false, it resets them to 0 /* save speed before, since if AirportHasBlock is false, it resets them to 0
@ -1633,12 +1633,12 @@ static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc)
uint16 tcur_speed = v->cur_speed; uint16 tcur_speed = v->cur_speed;
uint16 tsubspeed = v->subspeed; uint16 tsubspeed = v->subspeed;
if (!AirportHasBlock(v, current, apc)) { if (!AirportHasBlock(v, current, apc)) {
v->u.air.state = landingtype; // LANDING / HELILANDING v->state = landingtype; // LANDING / HELILANDING
/* it's a bit dirty, but I need to set position to next position, otherwise /* it's a bit dirty, but I need to set position to next position, otherwise
* if there are multiple runways, plane won't know which one it took (because * if there are multiple runways, plane won't know which one it took (because
* they all have heading LANDING). And also occupy that block! */ * they all have heading LANDING). And also occupy that block! */
v->u.air.pos = current->next_position; v->pos = current->next_position;
SETBITS(st->airport_flags, apc->layout[v->u.air.pos].block); SETBITS(st->airport_flags, apc->layout[v->pos].block);
return; return;
} }
v->cur_speed = tcur_speed; v->cur_speed = tcur_speed;
@ -1647,13 +1647,13 @@ static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc)
current = current->next; current = current->next;
} }
} }
v->u.air.state = FLYING; v->state = FLYING;
v->u.air.pos = apc->layout[v->u.air.pos].next_position; v->pos = apc->layout[v->pos].next_position;
} }
static void AircraftEventHandler_Landing(Aircraft *v, const AirportFTAClass *apc) static void AircraftEventHandler_Landing(Aircraft *v, const AirportFTAClass *apc)
{ {
v->u.air.state = ENDLANDING; v->state = ENDLANDING;
AircraftLandAirplane(v); // maybe crash airplane AircraftLandAirplane(v); // maybe crash airplane
/* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */ /* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */
@ -1666,14 +1666,14 @@ static void AircraftEventHandler_Landing(Aircraft *v, const AirportFTAClass *apc
static void AircraftEventHandler_HeliLanding(Aircraft *v, const AirportFTAClass *apc) static void AircraftEventHandler_HeliLanding(Aircraft *v, const AirportFTAClass *apc)
{ {
v->u.air.state = HELIENDLANDING; v->state = HELIENDLANDING;
v->UpdateDeltaXY(INVALID_DIR); v->UpdateDeltaXY(INVALID_DIR);
} }
static void AircraftEventHandler_EndLanding(Aircraft *v, const AirportFTAClass *apc) static void AircraftEventHandler_EndLanding(Aircraft *v, const AirportFTAClass *apc)
{ {
/* next block busy, don't do a thing, just wait */ /* next block busy, don't do a thing, just wait */
if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return; if (AirportHasBlock(v, &apc->layout[v->pos], apc)) return;
/* if going to terminal (OT_GOTO_STATION) choose one /* if going to terminal (OT_GOTO_STATION) choose one
* 1. in case all terminals are busy AirportFindFreeTerminal() returns false or * 1. in case all terminals are busy AirportFindFreeTerminal() returns false or
@ -1682,14 +1682,14 @@ static void AircraftEventHandler_EndLanding(Aircraft *v, const AirportFTAClass *
if (v->current_order.IsType(OT_GOTO_STATION)) { if (v->current_order.IsType(OT_GOTO_STATION)) {
if (AirportFindFreeTerminal(v, apc)) return; if (AirportFindFreeTerminal(v, apc)) return;
} }
v->u.air.state = HANGAR; v->state = HANGAR;
} }
static void AircraftEventHandler_HeliEndLanding(Aircraft *v, const AirportFTAClass *apc) static void AircraftEventHandler_HeliEndLanding(Aircraft *v, const AirportFTAClass *apc)
{ {
/* next block busy, don't do a thing, just wait */ /* next block busy, don't do a thing, just wait */
if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return; if (AirportHasBlock(v, &apc->layout[v->pos], apc)) return;
/* if going to helipad (OT_GOTO_STATION) choose one. If airport doesn't have helipads, choose terminal /* if going to helipad (OT_GOTO_STATION) choose one. If airport doesn't have helipads, choose terminal
* 1. in case all terminals/helipads are busy (AirportFindFreeHelipad() returns false) or * 1. in case all terminals/helipads are busy (AirportFindFreeHelipad() returns false) or
@ -1701,7 +1701,7 @@ static void AircraftEventHandler_HeliEndLanding(Aircraft *v, const AirportFTACla
if (v->current_order.IsType(OT_GOTO_STATION)) { if (v->current_order.IsType(OT_GOTO_STATION)) {
if (AirportFindFreeHelipad(v, apc)) return; if (AirportFindFreeHelipad(v, apc)) return;
} }
v->u.air.state = (apc->nof_depots != 0) ? HANGAR : HELITAKEOFF; v->state = (apc->nof_depots != 0) ? HANGAR : HELITAKEOFF;
} }
typedef void AircraftStateHandler(Aircraft *v, const AirportFTAClass *apc); typedef void AircraftStateHandler(Aircraft *v, const AirportFTAClass *apc);
@ -1734,10 +1734,10 @@ static AircraftStateHandler * const _aircraft_state_handlers[] = {
static void AirportClearBlock(const Aircraft *v, const AirportFTAClass *apc) static void AirportClearBlock(const Aircraft *v, const AirportFTAClass *apc)
{ {
/* we have left the previous block, and entered the new one. Free the previous block */ /* we have left the previous block, and entered the new one. Free the previous block */
if (apc->layout[v->u.air.previous_pos].block != apc->layout[v->u.air.pos].block) { if (apc->layout[v->previous_pos].block != apc->layout[v->pos].block) {
Station *st = Station::Get(v->u.air.targetairport); Station *st = Station::Get(v->targetairport);
CLRBITS(st->airport_flags, apc->layout[v->u.air.previous_pos].block); CLRBITS(st->airport_flags, apc->layout[v->previous_pos].block);
} }
} }
@ -1746,7 +1746,7 @@ static void AirportGoToNextPosition(Aircraft *v)
/* if aircraft is not in position, wait until it is */ /* if aircraft is not in position, wait until it is */
if (!AircraftController(v)) return; if (!AircraftController(v)) return;
const AirportFTAClass *apc = Station::Get(v->u.air.targetairport)->Airport(); const AirportFTAClass *apc = Station::Get(v->targetairport)->Airport();
AirportClearBlock(v, apc); AirportClearBlock(v, apc);
AirportMove(v, apc); // move aircraft to next position AirportMove(v, apc); // move aircraft to next position
@ -1756,28 +1756,28 @@ static void AirportGoToNextPosition(Aircraft *v)
static bool AirportMove(Aircraft *v, const AirportFTAClass *apc) static bool AirportMove(Aircraft *v, const AirportFTAClass *apc)
{ {
/* error handling */ /* error handling */
if (v->u.air.pos >= apc->nofelements) { if (v->pos >= apc->nofelements) {
DEBUG(misc, 0, "[Ap] position %d is not valid for current airport. Max position is %d", v->u.air.pos, apc->nofelements-1); DEBUG(misc, 0, "[Ap] position %d is not valid for current airport. Max position is %d", v->pos, apc->nofelements-1);
assert(v->u.air.pos < apc->nofelements); assert(v->pos < apc->nofelements);
} }
const AirportFTA *current = &apc->layout[v->u.air.pos]; const AirportFTA *current = &apc->layout[v->pos];
/* we have arrived in an important state (eg terminal, hangar, etc.) */ /* we have arrived in an important state (eg terminal, hangar, etc.) */
if (current->heading == v->u.air.state) { if (current->heading == v->state) {
byte prev_pos = v->u.air.pos; // location could be changed in state, so save it before-hand byte prev_pos = v->pos; // location could be changed in state, so save it before-hand
byte prev_state = v->u.air.state; byte prev_state = v->state;
_aircraft_state_handlers[v->u.air.state](v, apc); _aircraft_state_handlers[v->state](v, apc);
if (v->u.air.state != FLYING) v->u.air.previous_pos = prev_pos; if (v->state != FLYING) v->previous_pos = prev_pos;
if (v->u.air.state != prev_state || v->u.air.pos != prev_pos) UpdateAircraftCache(v); if (v->state != prev_state || v->pos != prev_pos) UpdateAircraftCache(v);
return true; return true;
} }
v->u.air.previous_pos = v->u.air.pos; // save previous location v->previous_pos = v->pos; // save previous location
/* there is only one choice to move to */ /* there is only one choice to move to */
if (current->next == NULL) { if (current->next == NULL) {
if (AirportSetBlocks(v, current, apc)) { if (AirportSetBlocks(v, current, apc)) {
v->u.air.pos = current->next_position; v->pos = current->next_position;
UpdateAircraftCache(v); UpdateAircraftCache(v);
} // move to next position } // move to next position
return false; return false;
@ -1786,9 +1786,9 @@ static bool AirportMove(Aircraft *v, const AirportFTAClass *apc)
/* there are more choices to choose from, choose the one that /* there are more choices to choose from, choose the one that
* matches our heading */ * matches our heading */
do { do {
if (v->u.air.state == current->heading || current->heading == TO_ALL) { if (v->state == current->heading || current->heading == TO_ALL) {
if (AirportSetBlocks(v, current, apc)) { if (AirportSetBlocks(v, current, apc)) {
v->u.air.pos = current->next_position; v->pos = current->next_position;
UpdateAircraftCache(v); UpdateAircraftCache(v);
} // move to next position } // move to next position
return false; return false;
@ -1796,7 +1796,7 @@ static bool AirportMove(Aircraft *v, const AirportFTAClass *apc)
current = current->next; current = current->next;
} while (current != NULL); } while (current != NULL);
DEBUG(misc, 0, "[Ap] cannot move further on Airport! (pos %d state %d) for vehicle %d", v->u.air.pos, v->u.air.state, v->index); DEBUG(misc, 0, "[Ap] cannot move further on Airport! (pos %d state %d) for vehicle %d", v->pos, v->state, v->index);
assert(0); assert(0);
return false; return false;
} }
@ -1804,12 +1804,12 @@ static bool AirportMove(Aircraft *v, const AirportFTAClass *apc)
/* returns true if the road ahead is busy, eg. you must wait before proceeding */ /* returns true if the road ahead is busy, eg. you must wait before proceeding */
static bool AirportHasBlock(Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc) static bool AirportHasBlock(Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc)
{ {
const AirportFTA *reference = &apc->layout[v->u.air.pos]; const AirportFTA *reference = &apc->layout[v->pos];
const AirportFTA *next = &apc->layout[current_pos->next_position]; const AirportFTA *next = &apc->layout[current_pos->next_position];
/* same block, then of course we can move */ /* same block, then of course we can move */
if (apc->layout[current_pos->position].block != next->block) { if (apc->layout[current_pos->position].block != next->block) {
const Station *st = Station::Get(v->u.air.targetairport); const Station *st = Station::Get(v->targetairport);
uint64 airport_flags = next->block; uint64 airport_flags = next->block;
/* check additional possible extra blocks */ /* check additional possible extra blocks */
@ -1836,7 +1836,7 @@ static bool AirportHasBlock(Aircraft *v, const AirportFTA *current_pos, const Ai
static bool AirportSetBlocks(Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc) static bool AirportSetBlocks(Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc)
{ {
const AirportFTA *next = &apc->layout[current_pos->next_position]; const AirportFTA *next = &apc->layout[current_pos->next_position];
const AirportFTA *reference = &apc->layout[v->u.air.pos]; const AirportFTA *reference = &apc->layout[v->pos];
/* if the next position is in another block, check it and wait until it is free */ /* if the next position is in another block, check it and wait until it is free */
if ((apc->layout[current_pos->position].block & next->block) != next->block) { if ((apc->layout[current_pos->position].block & next->block) != next->block) {
@ -1857,7 +1857,7 @@ static bool AirportSetBlocks(Aircraft *v, const AirportFTA *current_pos, const A
* checking, because it has been set by the airplane before */ * checking, because it has been set by the airplane before */
if (current_pos->block == next->block) airport_flags ^= next->block; if (current_pos->block == next->block) airport_flags ^= next->block;
Station *st = Station::Get(v->u.air.targetairport); Station *st = Station::Get(v->targetairport);
if (HASBITS(st->airport_flags, airport_flags)) { if (HASBITS(st->airport_flags, airport_flags)) {
v->cur_speed = 0; v->cur_speed = 0;
v->subspeed = 0; v->subspeed = 0;
@ -1873,11 +1873,11 @@ static bool AirportSetBlocks(Aircraft *v, const AirportFTA *current_pos, const A
static bool FreeTerminal(Aircraft *v, byte i, byte last_terminal) static bool FreeTerminal(Aircraft *v, byte i, byte last_terminal)
{ {
Station *st = Station::Get(v->u.air.targetairport); Station *st = Station::Get(v->targetairport);
for (; i < last_terminal; i++) { for (; i < last_terminal; i++) {
if (!HasBit(st->airport_flags, _airport_terminal_flag[i])) { if (!HasBit(st->airport_flags, _airport_terminal_flag[i])) {
/* TERMINAL# HELIPAD# */ /* TERMINAL# HELIPAD# */
v->u.air.state = _airport_terminal_state[i]; // start moving to that terminal/helipad v->state = _airport_terminal_state[i]; // start moving to that terminal/helipad
SetBit(st->airport_flags, _airport_terminal_flag[i]); // occupy terminal/helipad SetBit(st->airport_flags, _airport_terminal_flag[i]); // occupy terminal/helipad
return true; return true;
} }
@ -1907,8 +1907,8 @@ static bool AirportFindFreeTerminal(Aircraft *v, const AirportFTAClass *apc)
* fails, then attempt fails and plane waits * fails, then attempt fails and plane waits
*/ */
if (apc->terminals[0] > 1) { if (apc->terminals[0] > 1) {
const Station *st = Station::Get(v->u.air.targetairport); const Station *st = Station::Get(v->targetairport);
const AirportFTA *temp = apc->layout[v->u.air.pos].next; const AirportFTA *temp = apc->layout[v->pos].next;
while (temp != NULL) { while (temp != NULL) {
if (temp->heading == 255) { if (temp->heading == 255) {
@ -1958,8 +1958,8 @@ static bool AirportFindFreeHelipad(Aircraft *v, const AirportFTAClass *apc)
/* if there are more helicoptergroups, pick one, just as in AirportFindFreeTerminal() */ /* if there are more helicoptergroups, pick one, just as in AirportFindFreeTerminal() */
if (apc->helipads[0] > 1) { if (apc->helipads[0] > 1) {
const Station *st = Station::Get(v->u.air.targetairport); const Station *st = Station::Get(v->targetairport);
const AirportFTA *temp = apc->layout[v->u.air.pos].next; const AirportFTA *temp = apc->layout[v->pos].next;
while (temp != NULL) { while (temp != NULL) {
if (temp->heading == 255) { if (temp->heading == 255) {
@ -2049,7 +2049,7 @@ bool Aircraft::Tick()
} }
/** Returns aircraft's target station if v->u.air.target_airport /** Returns aircraft's target station if v->target_airport
* is a valid station with airport. * is a valid station with airport.
* @param v vehicle to get target airport for * @param v vehicle to get target airport for
* @return pointer to target station, NULL if invalid * @return pointer to target station, NULL if invalid
@ -2058,7 +2058,7 @@ Station *GetTargetAirportIfValid(const Aircraft *v)
{ {
assert(v->type == VEH_AIRCRAFT); assert(v->type == VEH_AIRCRAFT);
Station *st = Station::GetIfValid(v->u.air.targetairport); Station *st = Station::GetIfValid(v->targetairport);
if (st == NULL) return NULL; if (st == NULL) return NULL;
return st->airport_tile == INVALID_TILE ? NULL : st; return st->airport_tile == INVALID_TILE ? NULL : st;
@ -2077,12 +2077,12 @@ void UpdateAirplanesOnNewStation(const Station *st)
FOR_ALL_VEHICLES(u) { FOR_ALL_VEHICLES(u) {
if (u->type == VEH_AIRCRAFT && IsNormalAircraft(u)) { if (u->type == VEH_AIRCRAFT && IsNormalAircraft(u)) {
Aircraft *v = (Aircraft *)u; Aircraft *v = (Aircraft *)u;
if (v->u.air.targetairport == st->index) { // if heading to this airport if (v->targetairport == st->index) { // if heading to this airport
/* update position of airplane. If plane is not flying, landing, or taking off /* update position of airplane. If plane is not flying, landing, or taking off
* you cannot delete airport, so it doesn't matter */ * you cannot delete airport, so it doesn't matter */
if (v->u.air.state >= FLYING) { // circle around if (v->state >= FLYING) { // circle around
v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, ap); v->pos = v->previous_pos = AircraftGetEntryPoint(v, ap);
v->u.air.state = FLYING; v->state = FLYING;
UpdateAircraftCache(v); UpdateAircraftCache(v);
/* landing plane needs to be reset to flying height (only if in pause mode upgrade, /* landing plane needs to be reset to flying height (only if in pause mode upgrade,
* in normal mode, plane is reset in AircraftController. It doesn't hurt for FLYING */ * in normal mode, plane is reset in AircraftController. It doesn't hurt for FLYING */
@ -2090,13 +2090,13 @@ void UpdateAirplanesOnNewStation(const Station *st)
/* set new position x,y,z */ /* set new position x,y,z */
SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v)); SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v));
} else { } else {
assert(v->u.air.state == ENDTAKEOFF || v->u.air.state == HELITAKEOFF); assert(v->state == ENDTAKEOFF || v->state == HELITAKEOFF);
byte takeofftype = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : ENDTAKEOFF; byte takeofftype = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : ENDTAKEOFF;
/* search in airportdata for that heading /* search in airportdata for that heading
* easiest to do, since this doesn't happen a lot */ * easiest to do, since this doesn't happen a lot */
for (uint cnt = 0; cnt < ap->nofelements; cnt++) { for (uint cnt = 0; cnt < ap->nofelements; cnt++) {
if (ap->layout[cnt].heading == takeofftype) { if (ap->layout[cnt].heading == takeofftype) {
v->u.air.pos = ap->layout[cnt].position; v->pos = ap->layout[cnt].position;
UpdateAircraftCache(v); UpdateAircraftCache(v);
break; break;
} }

View File

@ -180,9 +180,9 @@ static byte MapAircraftMovementState(const Aircraft *v)
if (st == NULL) return AMS_TTDP_FLIGHT_TO_TOWER; if (st == NULL) return AMS_TTDP_FLIGHT_TO_TOWER;
const AirportFTAClass *afc = st->Airport(); const AirportFTAClass *afc = st->Airport();
uint16 amdflag = afc->MovingData(v->u.air.pos)->flag; uint16 amdflag = afc->MovingData(v->pos)->flag;
switch (v->u.air.state) { switch (v->state) {
case HANGAR: case HANGAR:
/* The international airport is a special case as helicopters can land in /* The international airport is a special case as helicopters can land in
* front of the hanger. Helicopters also change their air.state to * front of the hanger. Helicopters also change their air.state to
@ -303,7 +303,7 @@ enum {
*/ */
static byte MapAircraftMovementAction(const Aircraft *v) static byte MapAircraftMovementAction(const Aircraft *v)
{ {
switch (v->u.air.state) { switch (v->state) {
case HANGAR: case HANGAR:
return (v->cur_speed > 0) ? AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_IN_HANGAR; return (v->cur_speed > 0) ? AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_IN_HANGAR;
@ -796,7 +796,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
Aircraft *a = (Aircraft *)v; Aircraft *a = (Aircraft *)v;
switch (variable - 0x80) { switch (variable - 0x80) {
case 0x62: return MapAircraftMovementState(a); // Current movement state case 0x62: return MapAircraftMovementState(a); // Current movement state
case 0x63: return v->u.air.targetairport; // Airport to which the action refers case 0x63: return a->targetairport; // Airport to which the action refers
case 0x66: return MapAircraftMovementAction(a); // Current movement action case 0x66: return MapAircraftMovementAction(a); // Current movement action
} }
} break; } break;
@ -936,7 +936,7 @@ SpriteID GetRotorOverrideSprite(EngineID engine, const Aircraft *v, bool info_vi
if (v == NULL) return group->g.result.sprite; if (v == NULL) return group->g.result.sprite;
return group->g.result.sprite + (info_view ? 0 : (v->Next()->Next()->u.air.state % group->g.result.num_sprites)); return group->g.result.sprite + (info_view ? 0 : (v->Next()->Next()->state % group->g.result.num_sprites));
} }

View File

@ -1146,9 +1146,9 @@ void StateGameLoop()
case VEH_AIRCRAFT: { case VEH_AIRCRAFT: {
Aircraft *a = (Aircraft *)v; Aircraft *a = (Aircraft *)v;
uint speed = a->u.air.cached_max_speed; uint speed = a->cached_max_speed;
UpdateAircraftCache(a); UpdateAircraftCache(a);
if (speed != a->u.air.cached_max_speed) { if (speed != a->cached_max_speed) {
DEBUG(desync, 2, "cache mismatch: vehicle %i, company %i, unit number %i\n", v->index, (int)v->owner, v->unitnumber); DEBUG(desync, 2, "cache mismatch: vehicle %i, company %i, unit number %i\n", v->index, (int)v->owner, v->unitnumber);
} }
} break; } break;

View File

@ -1620,10 +1620,13 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
/* If there is no depot in front, reverse automatically (trains only) */ /* If there is no depot in front, reverse automatically (trains only) */
if (v->type == VEH_TRAIN && reverse) DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION); if (v->type == VEH_TRAIN && reverse) DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
if (v->type == VEH_AIRCRAFT && v->u.air.state == FLYING && v->u.air.targetairport != destination) { if (v->type == VEH_AIRCRAFT) {
/* The aircraft is now heading for a different hangar than the next in the orders */ Aircraft *a = (Aircraft *)v;
extern void AircraftNextAirportPos_and_Order(Aircraft *a); if (a->state == FLYING && a->targetairport != destination) {
AircraftNextAirportPos_and_Order((Aircraft *)v); /* The aircraft is now heading for a different hangar than the next in the orders */
extern void AircraftNextAirportPos_and_Order(Aircraft *a);
AircraftNextAirportPos_and_Order(a);
}
} }
} else { } else {
UpdateVehicleTimetable(v, true); UpdateVehicleTimetable(v, true);

View File

@ -1111,10 +1111,10 @@ static const OldChunks vehicle_ship_chunk[] = {
}; };
static const OldChunks vehicle_air_chunk[] = { static const OldChunks vehicle_air_chunk[] = {
OCL_SVAR( OC_UINT8, VehicleAir, pos ), OCL_SVAR( OC_UINT8, Aircraft, pos ),
OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, VehicleAir, targetairport ), OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Aircraft, targetairport ),
OCL_SVAR( OC_UINT16, VehicleAir, crashed_counter ), OCL_SVAR( OC_UINT16, Aircraft, crashed_counter ),
OCL_SVAR( OC_UINT8, VehicleAir, state ), OCL_SVAR( OC_UINT8, Aircraft, state ),
OCL_NULL( 5 ), ///< Junk OCL_NULL( 5 ), ///< Junk
@ -1159,7 +1159,7 @@ static bool LoadOldVehicleUnion(LoadgameState *ls, int num)
case VEH_TRAIN : res = LoadChunk(ls, &v->u.rail, vehicle_train_chunk); break; case VEH_TRAIN : res = LoadChunk(ls, &v->u.rail, vehicle_train_chunk); break;
case VEH_ROAD : res = LoadChunk(ls, &v->u.road, vehicle_road_chunk); break; case VEH_ROAD : res = LoadChunk(ls, &v->u.road, vehicle_road_chunk); break;
case VEH_SHIP : res = LoadChunk(ls, v, vehicle_ship_chunk); break; case VEH_SHIP : res = LoadChunk(ls, v, vehicle_ship_chunk); break;
case VEH_AIRCRAFT: res = LoadChunk(ls, &v->u.air, vehicle_air_chunk); break; case VEH_AIRCRAFT: res = LoadChunk(ls, v, vehicle_air_chunk); break;
case VEH_EFFECT : res = LoadChunk(ls, v, vehicle_effect_chunk); break; case VEH_EFFECT : res = LoadChunk(ls, v, vehicle_effect_chunk); break;
case VEH_DISASTER: res = LoadChunk(ls, v, vehicle_disaster_chunk); break; case VEH_DISASTER: res = LoadChunk(ls, v, vehicle_disaster_chunk); break;
} }

View File

@ -173,29 +173,30 @@ void UpdateOldAircraft()
* skip those */ * skip those */
if (v->type == VEH_AIRCRAFT && IsNormalAircraft(v)) { if (v->type == VEH_AIRCRAFT && IsNormalAircraft(v)) {
Aircraft *v_oldstyle = (Aircraft *)v; Aircraft *v_oldstyle = (Aircraft *)v;
Aircraft *a = (Aircraft *)v_oldstyle;
/* airplane in terminal stopped doesn't hurt anyone, so goto next */ /* airplane in terminal stopped doesn't hurt anyone, so goto next */
if (v_oldstyle->vehstatus & VS_STOPPED && v_oldstyle->u.air.state == 0) { if (a->vehstatus & VS_STOPPED && a->state == 0) {
v_oldstyle->u.air.state = HANGAR; a->state = HANGAR;
continue; continue;
} }
AircraftLeaveHangar(v_oldstyle); // make airplane visible if it was in a depot for example AircraftLeaveHangar(a); // make airplane visible if it was in a depot for example
v_oldstyle->vehstatus &= ~VS_STOPPED; // make airplane moving a->vehstatus &= ~VS_STOPPED; // make airplane moving
v_oldstyle->cur_speed = v_oldstyle->max_speed; // so aircraft don't have zero speed while in air a->cur_speed = v_oldstyle->max_speed; // so aircraft don't have zero speed while in air
if (!v_oldstyle->current_order.IsType(OT_GOTO_STATION) && !v_oldstyle->current_order.IsType(OT_GOTO_DEPOT)) { if (!a->current_order.IsType(OT_GOTO_STATION) && !a->current_order.IsType(OT_GOTO_DEPOT)) {
/* reset current order so aircraft doesn't have invalid "station-only" order */ /* reset current order so aircraft doesn't have invalid "station-only" order */
v_oldstyle->current_order.MakeDummy(); a->current_order.MakeDummy();
} }
v_oldstyle->u.air.state = FLYING; a->state = FLYING;
AircraftNextAirportPos_and_Order(v_oldstyle); // move it to the entry point of the airport AircraftNextAirportPos_and_Order(a); // move it to the entry point of the airport
GetNewVehiclePosResult gp = GetNewVehiclePos(v_oldstyle); GetNewVehiclePosResult gp = GetNewVehiclePos(a);
v_oldstyle->tile = 0; // aircraft in air is tile=0 a->tile = 0; // aircraft in air is tile=0
/* correct speed of helicopter-rotors */ /* correct speed of helicopter-rotors */
if (v_oldstyle->subtype == AIR_HELICOPTER) v_oldstyle->Next()->Next()->cur_speed = 32; if (a->subtype == AIR_HELICOPTER) a->Next()->Next()->cur_speed = 32;
/* set new position x,y,z */ /* set new position x,y,z */
SetAircraftPosition(v_oldstyle, gp.x, gp.y, GetAircraftFlyingAltitude(v_oldstyle)); SetAircraftPosition(a, gp.x, gp.y, GetAircraftFlyingAltitude(a));
} }
} }
} }
@ -572,15 +573,15 @@ const SaveLoad *GetVehicleDescription(VehicleType vt)
static const SaveLoad _aircraft_desc[] = { static const SaveLoad _aircraft_desc[] = {
SLE_WRITEBYTE(Vehicle, type, VEH_AIRCRAFT), SLE_WRITEBYTE(Vehicle, type, VEH_AIRCRAFT),
SLE_VEH_INCLUDEX(), SLE_VEH_INCLUDEX(),
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, crashed_counter), SLE_UINT16), SLE_VAR(Aircraft, crashed_counter, SLE_UINT16),
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, pos), SLE_UINT8), SLE_VAR(Aircraft, pos, SLE_UINT8),
SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, targetairport), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), SLE_CONDVAR(Aircraft, targetairport, SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, targetairport), SLE_UINT16, 5, SL_MAX_VERSION), SLE_CONDVAR(Aircraft, targetairport, SLE_UINT16, 5, SL_MAX_VERSION),
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, state), SLE_UINT8), SLE_VAR(Aircraft, state, SLE_UINT8),
SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, previous_pos), SLE_UINT8, 2, SL_MAX_VERSION), SLE_CONDVAR(Aircraft, previous_pos, SLE_UINT8, 2, SL_MAX_VERSION),
/* reserve extra space in savegame here. (currently 15 bytes) */ /* reserve extra space in savegame here. (currently 15 bytes) */
SLE_CONDNULL(15, 2, SL_MAX_VERSION), SLE_CONDNULL(15, 2, SL_MAX_VERSION),

View File

@ -70,9 +70,10 @@ Station::~Station()
Vehicle *v; Vehicle *v;
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
if (v->type == VEH_AIRCRAFT && IsNormalAircraft(v) && v->u.air.targetairport == this->index) { if (v->type != VEH_AIRCRAFT || !IsNormalAircraft(v)) continue;
v->u.air.targetairport = INVALID_STATION;
} Aircraft *a = (Aircraft *)v;
if (a->targetairport == this->index) a->targetairport = INVALID_STATION;
} }
MarkDirty(); MarkDirty();

View File

@ -1968,7 +1968,8 @@ static CommandCost RemoveAirport(Station *st, DoCommandFlag flags)
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
if (!(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) continue; if (!(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) continue;
if (v->u.air.targetairport == st->index && v->u.air.state != FLYING) return CMD_ERROR; Aircraft *a = (Aircraft *)v;
if (a->targetairport == st->index && a->state != FLYING) return CMD_ERROR;
} }
BEGIN_TILE_LOOP(tile_cur, w, h, tile) { BEGIN_TILE_LOOP(tile_cur, w, h, tile) {

View File

@ -530,7 +530,7 @@ void Vehicle::PreDestructor()
Station *st = GetTargetAirportIfValid(a); Station *st = GetTargetAirportIfValid(a);
if (st != NULL) { if (st != NULL) {
const AirportFTA *layout = st->Airport()->layout; const AirportFTA *layout = st->Airport()->layout;
CLRBITS(st->airport_flags, layout[this->u.air.previous_pos].block | layout[this->u.air.pos].block); CLRBITS(st->airport_flags, layout[a->previous_pos].block | layout[a->pos].block);
} }
} }
@ -1571,10 +1571,13 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
/* If there is no depot in front, reverse automatically (trains only) */ /* If there is no depot in front, reverse automatically (trains only) */
if (this->type == VEH_TRAIN && reverse) DoCommand(this->tile, this->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION); if (this->type == VEH_TRAIN && reverse) DoCommand(this->tile, this->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
if (this->type == VEH_AIRCRAFT && this->u.air.state == FLYING && this->u.air.targetairport != destination) { if (this->type == VEH_AIRCRAFT) {
/* The aircraft is now heading for a different hangar than the next in the orders */ Aircraft *a = (Aircraft *)this;
extern void AircraftNextAirportPos_and_Order(Aircraft *a); if (a->state == FLYING && a->targetairport != destination) {
AircraftNextAirportPos_and_Order((Aircraft *)this); /* The aircraft is now heading for a different hangar than the next in the orders */
extern void AircraftNextAirportPos_and_Order(Aircraft *a);
AircraftNextAirportPos_and_Order(a);
}
} }
} }

View File

@ -149,15 +149,6 @@ enum VehicleRailFlags {
VRF_TRAIN_STUCK = 8, VRF_TRAIN_STUCK = 8,
}; };
struct VehicleAir {
uint16 crashed_counter;
uint16 cached_max_speed;
byte pos;
byte previous_pos;
StationID targetairport;
byte state;
};
struct VehicleRoad { struct VehicleRoad {
byte state; ///< @see RoadVehicleStates byte state; ///< @see RoadVehicleStates
byte frame; byte frame;
@ -304,7 +295,6 @@ public:
union { union {
VehicleRail rail; VehicleRail rail;
VehicleAir air;
VehicleRoad road; VehicleRoad road;
} u; } u;

View File

@ -10,6 +10,7 @@
#include "company_func.h" #include "company_func.h"
#include "vehicle_gui.h" #include "vehicle_gui.h"
#include "train.h" #include "train.h"
#include "aircraft.h"
#include "newgrf_engine.h" #include "newgrf_engine.h"
#include "newgrf_text.h" #include "newgrf_text.h"
#include "functions.h" #include "functions.h"
@ -73,10 +74,11 @@ CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
case VEH_ROAD: case VEH_ROAD:
break; break;
case VEH_AIRCRAFT: case VEH_AIRCRAFT: {
Aircraft *a = (Aircraft *)v;
/* cannot stop airplane when in flight, or when taking off / landing */ /* cannot stop airplane when in flight, or when taking off / landing */
if (v->u.air.state >= STARTTAKEOFF && v->u.air.state < TERM7) return_cmd_error(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT); if (a->state >= STARTTAKEOFF && a->state < TERM7) return_cmd_error(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT);
break; } break;
default: return CMD_ERROR; default: return CMD_ERROR;
} }

View File

@ -828,7 +828,7 @@ static void FloodVehicle(Vehicle *v)
case VEH_AIRCRAFT: case VEH_AIRCRAFT:
pass += 2; // driver pass += 2; // driver
v->u.air.crashed_counter = 9000; // max 10000, disappear pretty fast ((Aircraft *)v)->crashed_counter = 9000; // max 10000, disappear pretty fast
InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0); InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
break; break;
} }