summaryrefslogtreecommitdiff
path: root/src/aircraft_cmd.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-05-22 20:07:26 +0000
committerrubidium <rubidium@openttd.org>2009-05-22 20:07:26 +0000
commitc882248348510265e1926b0abc031b4c6fb0f97f (patch)
treee2e97af6a402e4babea7d19de728a50ead416f51 /src/aircraft_cmd.cpp
parentada30679605644a228be26850a76370fea723799 (diff)
downloadopenttd-c882248348510265e1926b0abc031b4c6fb0f97f.tar.xz
(svn r16388) -Codechange: move u.air to Aircraft
Diffstat (limited to 'src/aircraft_cmd.cpp')
-rw-r--r--src/aircraft_cmd.cpp208
1 files changed, 104 insertions, 104 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 1a0469819..c06e3e64b 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -40,7 +40,7 @@ void Aircraft::UpdateDeltaXY(Direction direction)
default: NOT_REACHED();
case AIR_AIRCRAFT:
case AIR_HELICOPTER:
- switch (this->u.air.state) {
+ switch (this->state) {
case ENDTAKEOFF:
case LANDING:
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 SPR_ROTOR_STOPPED + w->u.air.state;
+ return SPR_ROTOR_STOPPED + w->state;
}
static SpriteID GetAircraftIcon(EngineID engine)
@@ -368,14 +368,14 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
assert(i != apc->nof_depots);
if (st->airport_tile + ToTileIndexDiff(apc->airport_depots[i]) == tile) {
assert(apc->layout[i].heading == HANGAR);
- v->u.air.pos = apc->layout[i].position;
+ v->pos = apc->layout[i].position;
break;
}
}
- v->u.air.state = HANGAR;
- v->u.air.previous_pos = v->u.air.pos;
- v->u.air.targetairport = GetStationIndex(tile);
+ v->state = HANGAR;
+ v->previous_pos = v->pos;
+ v->targetairport = GetStationIndex(tile);
v->SetNext(u);
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->random_bits = VehicleRandomBits();
/* 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);
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) */
if (st->airport_tile != INVALID_TILE && st->Airport()->terminals != NULL) {
-// printf("targetairport = %d, st->index = %d\n", v->u.air.targetairport, st->index);
-// v->u.air.targetairport = st->index;
+// printf("targetairport = %d, st->index = %d\n", v->targetairport, st->index);
+// v->targetairport = st->index;
v->current_order.MakeGoToDepot(st->index, ODTFB_SERVICE);
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
} 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 (u->cur_speed != 0) {
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;
}
}
@@ -672,13 +672,13 @@ static void HelicopterTickHandler(Aircraft *v)
SpriteID img;
if (spd == 0) {
- u->u.air.state = HRS_ROTOR_STOPPED;
+ u->state = HRS_ROTOR_STOPPED;
img = GetRotorImage(v);
if (u->cur_image == img) return;
} else if (tick >= spd) {
u->tick_counter = 0;
- u->u.air.state++;
- if (u->u.air.state > HRS_ROTOR_MOVING_3) u->u.air.state = HRS_ROTOR_MOVING_1;
+ u->state++;
+ if (u->state > HRS_ROTOR_MOVING_3) u->state = HRS_ROTOR_MOVING_1;
img = GetRotorImage(v);
} else {
return;
@@ -757,9 +757,9 @@ void UpdateAircraftCache(Aircraft *v)
/* Convert from original units to (approx) km/h */
max_speed = (max_speed * 129) / 10;
- v->u.air.cached_max_speed = max_speed;
+ v->cached_max_speed = max_speed;
} 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. */
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;
- speed_limit = v->u.air.cached_max_speed;
+ speed_limit = v->cached_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 */
TileIndex tile = 0;
- const Station *st = Station::GetIfValid(v->u.air.targetairport);
+ const Station *st = Station::GetIfValid(v->targetairport);
if (st != NULL) {
/* 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;
@@ -921,7 +921,7 @@ static bool AircraftController(Aircraft *v)
int count;
/* 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 */
TileIndex tile = INVALID_TILE;
if (st != NULL) {
@@ -933,11 +933,11 @@ static bool AircraftController(Aircraft *v)
/* prevent going to INVALID_TILE if airport is deleted. */
if (st == NULL || st->airport_tile == INVALID_TILE) {
/* Jump into our "holding pattern" state machine if possible */
- if (v->u.air.pos >= afc->nofelements) {
- v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, afc);
- } else if (v->u.air.targetairport != v->current_order.GetDestination()) {
+ if (v->pos >= afc->nofelements) {
+ v->pos = v->previous_pos = AircraftGetEntryPoint(v, afc);
+ } else if (v->targetairport != v->current_order.GetDestination()) {
/* If not possible, just get out of here fast */
- v->u.air.state = FLYING;
+ v->state = FLYING;
UpdateAircraftCache(v);
AircraftNextAirportPos_and_Order(v);
/* get aircraft back on running altitude */
@@ -947,7 +947,7 @@ static bool AircraftController(Aircraft *v)
}
/* 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 y = TileY(tile) * TILE_SIZE;
@@ -983,7 +983,7 @@ static bool AircraftController(Aircraft *v)
/* FIXME - AircraftController -> if station no longer exists, do not land
* 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 */
- v->u.air.state = FLYING;
+ v->state = FLYING;
UpdateAircraftCache(v);
AircraftNextAirportPos_and_Order(v);
return false;
@@ -1102,7 +1102,7 @@ static bool AircraftController(Aircraft *v)
if (amd->flag & AMED_LAND) {
if (st->airport_tile == INVALID_TILE) {
/* Airport has been removed, abort the landing procedure */
- v->u.air.state = FLYING;
+ v->state = FLYING;
UpdateAircraftCache(v);
AircraftNextAirportPos_and_Order(v);
/* get aircraft back on running altitude */
@@ -1142,21 +1142,21 @@ static bool AircraftController(Aircraft *v)
static bool HandleCrashedAircraft(Aircraft *v)
{
- v->u.air.crashed_counter += 3;
+ v->crashed_counter += 3;
Station *st = GetTargetAirportIfValid(v);
/* 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);
v->z_pos -= 1;
if (v->z_pos == z) {
- v->u.air.crashed_counter = 500;
+ v->crashed_counter = 500;
v->z_pos++;
}
}
- if (v->u.air.crashed_counter < 650) {
+ if (v->crashed_counter < 650) {
uint32 r;
if (Chance16R(1,32,r)) {
static const DirDiff delta[] = {
@@ -1172,7 +1172,7 @@ static bool HandleCrashedAircraft(Aircraft *v)
GB(r, 8, 4),
EV_EXPLOSION_SMALL);
}
- } else if (v->u.air.crashed_counter >= 10000) {
+ } else if (v->crashed_counter >= 10000) {
/* remove rubble of crashed airplane */
/* clear runway-in on all airports, set by crashing plane
@@ -1276,7 +1276,7 @@ void HandleMissingAircraftOrders(Aircraft *v)
TileIndex Aircraft::GetOrderStationLocation(StationID 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);
}
@@ -1294,7 +1294,7 @@ void Aircraft::MarkDirty()
static void CrashAirplane(Aircraft *v)
{
v->vehstatus |= VS_CRASHED;
- v->u.air.crashed_counter = 0;
+ v->crashed_counter = 0;
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
@@ -1330,7 +1330,7 @@ static void CrashAirplane(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 */
uint16 prob = 0x10000 / 1500;
@@ -1356,8 +1356,8 @@ static void AircraftEntersTerminal(Aircraft *v)
{
if (v->current_order.IsType(OT_GOTO_DEPOT)) return;
- Station *st = Station::Get(v->u.air.targetairport);
- v->last_station_visited = v->u.air.targetairport;
+ Station *st = Station::Get(v->targetairport);
+ v->last_station_visited = v->targetairport;
/* Check if station was ever visited before */
if (!(st->had_vehicle_of_type & HVOT_AIRCRAFT)) {
@@ -1391,12 +1391,12 @@ static void AircraftLandAirplane(Aircraft *v)
void AircraftNextAirportPos_and_Order(Aircraft *v)
{
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 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)
@@ -1470,20 +1470,20 @@ static inline bool CheckSendAircraftToHangarForReplacement(const Vehicle *v)
static void AircraftEventHandler_EnterTerminal(Aircraft *v, const AirportFTAClass *apc)
{
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)
{
VehicleEnterDepot(v);
- v->u.air.state = apc->layout[v->u.air.pos].heading;
+ v->state = apc->layout[v->pos].heading;
}
/** In an Airport Hangar */
static void AircraftEventHandler_InHangar(Aircraft *v, const AirportFTAClass *apc)
{
/* 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);
return;
}
@@ -1499,10 +1499,10 @@ static void AircraftEventHandler_InHangar(Aircraft *v, const AirportFTAClass *ap
return;
/* 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 */
- if (v->current_order.GetDestination() == v->u.air.targetairport) {
+ if (v->current_order.GetDestination() == v->targetairport) {
/* FindFreeTerminal:
* 1. Find a free terminal, 2. Occupy it, 3. Set the vehicle's state to that terminal */
if (v->subtype == AIR_HELICOPTER) {
@@ -1512,7 +1512,7 @@ static void AircraftEventHandler_InHangar(Aircraft *v, const AirportFTAClass *ap
}
} else { // Else prepare for launch.
/* 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);
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)
{
/* 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);
/* on an airport with helipads, a helicopter will always land there
* 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 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
* ---> start moving */
@@ -1551,7 +1551,7 @@ static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *
case OT_GOTO_STATION: // ready to fly to another airport
break;
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;
case OT_CONDITIONAL:
/* 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;
default: // orders have been deleted (no orders), goto depot and don't bother us
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) {
- v->u.air.state = HANGAR;
+ v->state = HANGAR;
} else {
/* 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);
}
@@ -1580,25 +1580,25 @@ static void AircraftEventHandler_General(Aircraft *v, const AirportFTAClass *apc
static void AircraftEventHandler_TakeOff(Aircraft *v, const AirportFTAClass *apc)
{
PlayAircraftSound(v); // play takeoffsound for airplanes
- v->u.air.state = STARTTAKEOFF;
+ v->state = STARTTAKEOFF;
}
static void AircraftEventHandler_StartTakeOff(Aircraft *v, const AirportFTAClass *apc)
{
- v->u.air.state = ENDTAKEOFF;
+ v->state = ENDTAKEOFF;
v->UpdateDeltaXY(INVALID_DIR);
}
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 */
AircraftNextAirportPos_and_Order(v);
}
static void AircraftEventHandler_HeliTakeOff(Aircraft *v, const AirportFTAClass *apc)
{
- v->u.air.state = FLYING;
+ v->state = FLYING;
v->UpdateDeltaXY(INVALID_DIR);
/* 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)
{
- Station *st = Station::Get(v->u.air.targetairport);
+ Station *st = Station::Get(v->targetairport);
/* runway busy or not allowed to use this airstation, circle */
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
* 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;
- const AirportFTA *current = apc->layout[v->u.air.pos].next;
+ const AirportFTA *current = apc->layout[v->pos].next;
while (current != NULL) {
if (current->heading == landingtype) {
/* 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 tsubspeed = v->subspeed;
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
* if there are multiple runways, plane won't know which one it took (because
* they all have heading LANDING). And also occupy that block! */
- v->u.air.pos = current->next_position;
- SETBITS(st->airport_flags, apc->layout[v->u.air.pos].block);
+ v->pos = current->next_position;
+ SETBITS(st->airport_flags, apc->layout[v->pos].block);
return;
}
v->cur_speed = tcur_speed;
@@ -1647,13 +1647,13 @@ static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc)
current = current->next;
}
}
- v->u.air.state = FLYING;
- v->u.air.pos = apc->layout[v->u.air.pos].next_position;
+ v->state = FLYING;
+ v->pos = apc->layout[v->pos].next_position;
}
static void AircraftEventHandler_Landing(Aircraft *v, const AirportFTAClass *apc)
{
- v->u.air.state = ENDLANDING;
+ v->state = ENDLANDING;
AircraftLandAirplane(v); // maybe crash airplane
/* 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)
{
- v->u.air.state = HELIENDLANDING;
+ v->state = HELIENDLANDING;
v->UpdateDeltaXY(INVALID_DIR);
}
static void AircraftEventHandler_EndLanding(Aircraft *v, const AirportFTAClass *apc)
{
/* 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
* 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 (AirportFindFreeTerminal(v, apc)) return;
}
- v->u.air.state = HANGAR;
+ v->state = HANGAR;
}
static void AircraftEventHandler_HeliEndLanding(Aircraft *v, const AirportFTAClass *apc)
{
/* 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
* 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 (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);
@@ -1734,10 +1734,10 @@ static AircraftStateHandler * const _aircraft_state_handlers[] = {
static void AirportClearBlock(const Aircraft *v, const AirportFTAClass *apc)
{
/* 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) {
- Station *st = Station::Get(v->u.air.targetairport);
+ if (apc->layout[v->previous_pos].block != apc->layout[v->pos].block) {
+ 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 (!AircraftController(v)) return;
- const AirportFTAClass *apc = Station::Get(v->u.air.targetairport)->Airport();
+ const AirportFTAClass *apc = Station::Get(v->targetairport)->Airport();
AirportClearBlock(v, apc);
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)
{
/* error handling */
- if (v->u.air.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);
- assert(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->pos, apc->nofelements-1);
+ 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.) */
- if (current->heading == v->u.air.state) {
- byte prev_pos = v->u.air.pos; // location could be changed in state, so save it before-hand
- byte prev_state = v->u.air.state;
- _aircraft_state_handlers[v->u.air.state](v, apc);
- if (v->u.air.state != FLYING) v->u.air.previous_pos = prev_pos;
- if (v->u.air.state != prev_state || v->u.air.pos != prev_pos) UpdateAircraftCache(v);
+ if (current->heading == v->state) {
+ byte prev_pos = v->pos; // location could be changed in state, so save it before-hand
+ byte prev_state = v->state;
+ _aircraft_state_handlers[v->state](v, apc);
+ if (v->state != FLYING) v->previous_pos = prev_pos;
+ if (v->state != prev_state || v->pos != prev_pos) UpdateAircraftCache(v);
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 */
if (current->next == NULL) {
if (AirportSetBlocks(v, current, apc)) {
- v->u.air.pos = current->next_position;
+ v->pos = current->next_position;
UpdateAircraftCache(v);
} // move to next position
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
* matches our heading */
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)) {
- v->u.air.pos = current->next_position;
+ v->pos = current->next_position;
UpdateAircraftCache(v);
} // move to next position
return false;
@@ -1796,7 +1796,7 @@ static bool AirportMove(Aircraft *v, const AirportFTAClass *apc)
current = current->next;
} 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);
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 */
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];
/* same block, then of course we can move */
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;
/* 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)
{
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 ((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 */
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)) {
v->cur_speed = 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)
{
- Station *st = Station::Get(v->u.air.targetairport);
+ Station *st = Station::Get(v->targetairport);
for (; i < last_terminal; i++) {
if (!HasBit(st->airport_flags, _airport_terminal_flag[i])) {
/* 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
return true;
}
@@ -1907,8 +1907,8 @@ static bool AirportFindFreeTerminal(Aircraft *v, const AirportFTAClass *apc)
* fails, then attempt fails and plane waits
*/
if (apc->terminals[0] > 1) {
- const Station *st = Station::Get(v->u.air.targetairport);
- const AirportFTA *temp = apc->layout[v->u.air.pos].next;
+ const Station *st = Station::Get(v->targetairport);
+ const AirportFTA *temp = apc->layout[v->pos].next;
while (temp != NULL) {
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 (apc->helipads[0] > 1) {
- const Station *st = Station::Get(v->u.air.targetairport);
- const AirportFTA *temp = apc->layout[v->u.air.pos].next;
+ const Station *st = Station::Get(v->targetairport);
+ const AirportFTA *temp = apc->layout[v->pos].next;
while (temp != NULL) {
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.
* @param v vehicle to get target airport for
* @return pointer to target station, NULL if invalid
@@ -2058,7 +2058,7 @@ Station *GetTargetAirportIfValid(const Aircraft *v)
{
assert(v->type == VEH_AIRCRAFT);
- Station *st = Station::GetIfValid(v->u.air.targetairport);
+ Station *st = Station::GetIfValid(v->targetairport);
if (st == NULL) return NULL;
return st->airport_tile == INVALID_TILE ? NULL : st;
@@ -2077,12 +2077,12 @@ void UpdateAirplanesOnNewStation(const Station *st)
FOR_ALL_VEHICLES(u) {
if (u->type == VEH_AIRCRAFT && IsNormalAircraft(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
* you cannot delete airport, so it doesn't matter */
- if (v->u.air.state >= FLYING) { // circle around
- v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, ap);
- v->u.air.state = FLYING;
+ if (v->state >= FLYING) { // circle around
+ v->pos = v->previous_pos = AircraftGetEntryPoint(v, ap);
+ v->state = FLYING;
UpdateAircraftCache(v);
/* 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 */
@@ -2090,13 +2090,13 @@ void UpdateAirplanesOnNewStation(const Station *st)
/* set new position x,y,z */
SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v));
} 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;
/* search in airportdata for that heading
* easiest to do, since this doesn't happen a lot */
for (uint cnt = 0; cnt < ap->nofelements; cnt++) {
if (ap->layout[cnt].heading == takeofftype) {
- v->u.air.pos = ap->layout[cnt].position;
+ v->pos = ap->layout[cnt].position;
UpdateAircraftCache(v);
break;
}