mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
conformance (AirportFTAClass), *FA to *apFA (to better reflect its type AirportFTAbuildup), and ->next_in_chain into ->next.
This commit is contained in:
parent
c84ffc2f1f
commit
9c508259a9
184
aircraft_cmd.c
184
aircraft_cmd.c
|
@ -26,12 +26,12 @@
|
||||||
#include "newgrf_sound.h"
|
#include "newgrf_sound.h"
|
||||||
#include "date.h"
|
#include "date.h"
|
||||||
|
|
||||||
static bool AirportMove(Vehicle *v, const AirportFTAClass *Airport);
|
static bool AirportMove(Vehicle *v, const AirportFTAClass *apc);
|
||||||
static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport);
|
static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *apc);
|
||||||
static bool AirportHasBlock(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport);
|
static bool AirportHasBlock(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *apc);
|
||||||
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport);
|
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *apc);
|
||||||
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport);
|
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *apc);
|
||||||
static void AirportGoToNextPosition(Vehicle *v, const AirportFTAClass *Airport);
|
static void AirportGoToNextPosition(Vehicle *v, const AirportFTAClass *apc);
|
||||||
static void CrashAirplane(Vehicle *v);
|
static void CrashAirplane(Vehicle *v);
|
||||||
|
|
||||||
static void AircraftNextAirportPos_and_Order(Vehicle *v);
|
static void AircraftNextAirportPos_and_Order(Vehicle *v);
|
||||||
|
@ -1401,15 +1401,15 @@ static void AircraftLandAirplane(Vehicle *v)
|
||||||
static void AircraftNextAirportPos_and_Order(Vehicle *v)
|
static void AircraftNextAirportPos_and_Order(Vehicle *v)
|
||||||
{
|
{
|
||||||
const Station* st;
|
const Station* st;
|
||||||
const AirportFTAClass *Airport;
|
const AirportFTAClass *apc;
|
||||||
|
|
||||||
if (v->current_order.type == OT_GOTO_STATION ||
|
if (v->current_order.type == OT_GOTO_STATION ||
|
||||||
v->current_order.type == OT_GOTO_DEPOT)
|
v->current_order.type == OT_GOTO_DEPOT)
|
||||||
v->u.air.targetairport = v->current_order.dest;
|
v->u.air.targetairport = v->current_order.dest;
|
||||||
|
|
||||||
st = GetStation(v->u.air.targetairport);
|
st = GetStation(v->u.air.targetairport);
|
||||||
Airport = GetAirport(st->airport_type);
|
apc = GetAirport(st->airport_type);
|
||||||
v->u.air.pos = v->u.air.previous_pos = Airport->entry_point;
|
v->u.air.pos = v->u.air.previous_pos = apc->entry_point;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AircraftLeaveHangar(Vehicle *v)
|
static void AircraftLeaveHangar(Vehicle *v)
|
||||||
|
@ -1442,24 +1442,24 @@ static void AircraftLeaveHangar(Vehicle *v)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/////////////////// AIRCRAFT MOVEMENT SCHEME ////////////////////////////////
|
/////////////////// AIRCRAFT MOVEMENT SCHEME ////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
static void AircraftEventHandler_EnterTerminal(Vehicle *v, const AirportFTAClass *Airport)
|
static void AircraftEventHandler_EnterTerminal(Vehicle *v, const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
AircraftEntersTerminal(v);
|
AircraftEntersTerminal(v);
|
||||||
v->u.air.state = Airport->layout[v->u.air.pos].heading;
|
v->u.air.state = apc->layout[v->u.air.pos].heading;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AircraftEventHandler_EnterHangar(Vehicle *v, const AirportFTAClass *Airport)
|
static void AircraftEventHandler_EnterHangar(Vehicle *v, const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
VehicleEnterDepot(v);
|
VehicleEnterDepot(v);
|
||||||
v->u.air.state = Airport->layout[v->u.air.pos].heading;
|
v->u.air.state = apc->layout[v->u.air.pos].heading;
|
||||||
}
|
}
|
||||||
|
|
||||||
// In an Airport Hangar
|
// In an Airport Hangar
|
||||||
static void AircraftEventHandler_InHangar(Vehicle *v, const AirportFTAClass *Airport)
|
static void AircraftEventHandler_InHangar(Vehicle *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->u.air.previous_pos != v->u.air.pos) {
|
||||||
AircraftEventHandler_EnterHangar(v, Airport);
|
AircraftEventHandler_EnterHangar(v, apc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1475,35 +1475,35 @@ static void AircraftEventHandler_InHangar(Vehicle *v, const AirportFTAClass *Air
|
||||||
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, &Airport->layout[v->u.air.pos], Airport)) return;
|
if (AirportHasBlock(v, &apc->layout[v->u.air.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.dest == v->u.air.targetairport) {
|
if (v->current_order.dest == v->u.air.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 != 0) {
|
if (v->subtype != 0) {
|
||||||
if (!AirportFindFreeTerminal(v, Airport)) return; // airplane
|
if (!AirportFindFreeTerminal(v, apc)) return; // airplane
|
||||||
} else {
|
} else {
|
||||||
if (!AirportFindFreeHelipad(v, Airport)) return; // helicopter
|
if (!AirportFindFreeHelipad(v, apc)) return; // helicopter
|
||||||
}
|
}
|
||||||
} 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 != 0) ? TAKEOFF : HELITAKEOFF;
|
v->u.air.state = (v->subtype != 0) ? TAKEOFF : HELITAKEOFF;
|
||||||
}
|
}
|
||||||
AircraftLeaveHangar(v);
|
AircraftLeaveHangar(v);
|
||||||
AirportMove(v, Airport);
|
AirportMove(v, apc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// At one of the Airport's Terminals
|
// At one of the Airport's Terminals
|
||||||
static void AircraftEventHandler_AtTerminal(Vehicle *v, const AirportFTAClass *Airport)
|
static void AircraftEventHandler_AtTerminal(Vehicle *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->u.air.previous_pos != v->u.air.pos) {
|
||||||
AircraftEventHandler_EnterTerminal(v, Airport);
|
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 - patch setting
|
// and get serviced at the same time - patch setting
|
||||||
if (_patches.serviceathelipad) {
|
if (_patches.serviceathelipad) {
|
||||||
if (v->subtype == 0 && Airport->helipads != NULL) {
|
if (v->subtype == 0 && apc->helipads != NULL) {
|
||||||
// an exerpt of ServiceAircraft, without the invisibility stuff
|
// an exerpt of ServiceAircraft, without the invisibility stuff
|
||||||
v->date_of_last_service = _date;
|
v->date_of_last_service = _date;
|
||||||
v->breakdowns_since_last_service = 0;
|
v->breakdowns_since_last_service = 0;
|
||||||
|
@ -1517,7 +1517,7 @@ static void AircraftEventHandler_AtTerminal(Vehicle *v, const AirportFTAClass *A
|
||||||
if (v->current_order.type == OT_NOTHING) return;
|
if (v->current_order.type == 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, &Airport->layout[v->u.air.pos], Airport)) {
|
if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1541,34 +1541,34 @@ static void AircraftEventHandler_AtTerminal(Vehicle *v, const AirportFTAClass *A
|
||||||
v->current_order.flags = 0;
|
v->current_order.flags = 0;
|
||||||
v->u.air.state = HANGAR;
|
v->u.air.state = HANGAR;
|
||||||
}
|
}
|
||||||
AirportMove(v, Airport);
|
AirportMove(v, apc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AircraftEventHandler_General(Vehicle *v, const AirportFTAClass *Airport)
|
static void AircraftEventHandler_General(Vehicle *v, const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
DEBUG(misc, 0) ("OK, you shouldn't be here, check your Airport Scheme!");
|
DEBUG(misc, 0) ("OK, you shouldn't be here, check your Airport Scheme!");
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AircraftEventHandler_TakeOff(Vehicle *v, const AirportFTAClass *Airport) {
|
static void AircraftEventHandler_TakeOff(Vehicle *v, const AirportFTAClass *apc) {
|
||||||
PlayAircraftSound(v); // play takeoffsound for airplanes
|
PlayAircraftSound(v); // play takeoffsound for airplanes
|
||||||
v->u.air.state = STARTTAKEOFF;
|
v->u.air.state = STARTTAKEOFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AircraftEventHandler_StartTakeOff(Vehicle *v, const AirportFTAClass *Airport)
|
static void AircraftEventHandler_StartTakeOff(Vehicle *v, const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
v->sprite_width = v->sprite_height = 24; // ??? no idea what this is
|
v->sprite_width = v->sprite_height = 24; // ??? no idea what this is
|
||||||
v->u.air.state = ENDTAKEOFF;
|
v->u.air.state = ENDTAKEOFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AircraftEventHandler_EndTakeOff(Vehicle *v, const AirportFTAClass *Airport)
|
static void AircraftEventHandler_EndTakeOff(Vehicle *v, const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
v->u.air.state = FLYING;
|
v->u.air.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(Vehicle *v, const AirportFTAClass *Airport)
|
static void AircraftEventHandler_HeliTakeOff(Vehicle *v, const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
const Player* p = GetPlayer(v->owner);
|
const Player* p = GetPlayer(v->owner);
|
||||||
v->sprite_width = v->sprite_height = 24; // ??? no idea what this is
|
v->sprite_width = v->sprite_height = 24; // ??? no idea what this is
|
||||||
|
@ -1589,7 +1589,7 @@ static void AircraftEventHandler_HeliTakeOff(Vehicle *v, const AirportFTAClass *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AircraftEventHandler_Flying(Vehicle *v, const AirportFTAClass *Airport)
|
static void AircraftEventHandler_Flying(Vehicle *v, const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
Station *st;
|
Station *st;
|
||||||
byte landingtype;
|
byte landingtype;
|
||||||
|
@ -1602,14 +1602,14 @@ static void AircraftEventHandler_Flying(Vehicle *v, const AirportFTAClass *Airpo
|
||||||
// all other airports --> all types of flying devices (ALL)
|
// all other airports --> all types of flying devices (ALL)
|
||||||
// heliport/oilrig, etc --> no airplanes (HELICOPTERS_ONLY)
|
// heliport/oilrig, etc --> no airplanes (HELICOPTERS_ONLY)
|
||||||
// runway busy or not allowed to use this airstation, circle
|
// runway busy or not allowed to use this airstation, circle
|
||||||
if (v->subtype != Airport->acc_planes &&
|
if (v->subtype != apc->acc_planes &&
|
||||||
st->airport_tile != 0 &&
|
st->airport_tile != 0 &&
|
||||||
(st->owner == OWNER_NONE || st->owner == v->owner)) {
|
(st->owner == OWNER_NONE || st->owner == v->owner)) {
|
||||||
// {32,FLYING,NOTHING_block,37}, {32,LANDING,N,33}, {32,HELILANDING,N,41},
|
// {32,FLYING,NOTHING_block,37}, {32,LANDING,N,33}, {32,HELILANDING,N,41},
|
||||||
// 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
|
||||||
landingtype = (v->subtype != 0) ? LANDING : HELILANDING;
|
landingtype = (v->subtype != 0) ? LANDING : HELILANDING;
|
||||||
current = Airport->layout[v->u.air.pos].next_in_chain;
|
current = apc->layout[v->u.air.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
|
||||||
|
@ -1617,26 +1617,26 @@ static void AircraftEventHandler_Flying(Vehicle *v, const AirportFTAClass *Airpo
|
||||||
// hack for speed thingie
|
// hack for speed thingie
|
||||||
tcur_speed = v->cur_speed;
|
tcur_speed = v->cur_speed;
|
||||||
tsubspeed = v->subspeed;
|
tsubspeed = v->subspeed;
|
||||||
if (!AirportHasBlock(v, current, Airport)) {
|
if (!AirportHasBlock(v, current, apc)) {
|
||||||
v->u.air.state = landingtype; // LANDING / HELILANDING
|
v->u.air.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->u.air.pos = current->next_position;
|
||||||
SETBITS(st->airport_flags, Airport->layout[v->u.air.pos].block);
|
SETBITS(st->airport_flags, apc->layout[v->u.air.pos].block);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
v->cur_speed = tcur_speed;
|
v->cur_speed = tcur_speed;
|
||||||
v->subspeed = tsubspeed;
|
v->subspeed = tsubspeed;
|
||||||
}
|
}
|
||||||
current = current->next_in_chain;
|
current = current->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v->u.air.state = FLYING;
|
v->u.air.state = FLYING;
|
||||||
v->u.air.pos = Airport->layout[v->u.air.pos].next_position;
|
v->u.air.pos = apc->layout[v->u.air.pos].next_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AircraftEventHandler_Landing(Vehicle *v, const AirportFTAClass *Airport)
|
static void AircraftEventHandler_Landing(Vehicle *v, const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
const Player* p = GetPlayer(v->owner);
|
const Player* p = GetPlayer(v->owner);
|
||||||
AircraftLandAirplane(v); // maybe crash airplane
|
AircraftLandAirplane(v); // maybe crash airplane
|
||||||
|
@ -1654,32 +1654,32 @@ static void AircraftEventHandler_Landing(Vehicle *v, const AirportFTAClass *Airp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AircraftEventHandler_HeliLanding(Vehicle *v, const AirportFTAClass *Airport)
|
static void AircraftEventHandler_HeliLanding(Vehicle *v, const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
AircraftLand(v); // helicopters don't crash
|
AircraftLand(v); // helicopters don't crash
|
||||||
v->u.air.state = HELIENDLANDING;
|
v->u.air.state = HELIENDLANDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AircraftEventHandler_EndLanding(Vehicle *v, const AirportFTAClass *Airport)
|
static void AircraftEventHandler_EndLanding(Vehicle *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, &Airport->layout[v->u.air.pos], Airport)) return;
|
if (AirportHasBlock(v, &apc->layout[v->u.air.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
|
||||||
// 2. not going for terminal (but depot, no order),
|
// 2. not going for terminal (but depot, no order),
|
||||||
// --> get out of the way to the hangar.
|
// --> get out of the way to the hangar.
|
||||||
if (v->current_order.type == OT_GOTO_STATION) {
|
if (v->current_order.type == OT_GOTO_STATION) {
|
||||||
if (AirportFindFreeTerminal(v, Airport)) return;
|
if (AirportFindFreeTerminal(v, apc)) return;
|
||||||
}
|
}
|
||||||
v->u.air.state = HANGAR;
|
v->u.air.state = HANGAR;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AircraftEventHandler_HeliEndLanding(Vehicle *v, const AirportFTAClass *Airport)
|
static void AircraftEventHandler_HeliEndLanding(Vehicle *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, &Airport->layout[v->u.air.pos], Airport)) return;
|
if (AirportHasBlock(v, &apc->layout[v->u.air.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
|
||||||
|
@ -1689,12 +1689,12 @@ static void AircraftEventHandler_HeliEndLanding(Vehicle *v, const AirportFTAClas
|
||||||
// the reason behind this is that if an airport has a terminal, it also has a hangar. Airplanes
|
// the reason behind this is that if an airport has a terminal, it also has a hangar. Airplanes
|
||||||
// must go to a hangar.
|
// must go to a hangar.
|
||||||
if (v->current_order.type == OT_GOTO_STATION) {
|
if (v->current_order.type == OT_GOTO_STATION) {
|
||||||
if (AirportFindFreeHelipad(v, Airport)) return;
|
if (AirportFindFreeHelipad(v, apc)) return;
|
||||||
}
|
}
|
||||||
v->u.air.state = (Airport->nof_depots != 0) ? HANGAR : HELITAKEOFF;
|
v->u.air.state = (apc->nof_depots != 0) ? HANGAR : HELITAKEOFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef void AircraftStateHandler(Vehicle *v, const AirportFTAClass *Airport);
|
typedef void AircraftStateHandler(Vehicle *v, const AirportFTAClass *apc);
|
||||||
static AircraftStateHandler * const _aircraft_state_handlers[] = {
|
static AircraftStateHandler * const _aircraft_state_handlers[] = {
|
||||||
AircraftEventHandler_General, // TO_ALL = 0
|
AircraftEventHandler_General, // TO_ALL = 0
|
||||||
AircraftEventHandler_InHangar, // HANGAR = 1
|
AircraftEventHandler_InHangar, // HANGAR = 1
|
||||||
|
@ -1721,42 +1721,42 @@ static AircraftStateHandler * const _aircraft_state_handlers[] = {
|
||||||
AircraftEventHandler_AtTerminal, // HELIPAD4 = 22
|
AircraftEventHandler_AtTerminal, // HELIPAD4 = 22
|
||||||
};
|
};
|
||||||
|
|
||||||
static void AirportClearBlock(const Vehicle *v, const AirportFTAClass *Airport)
|
static void AirportClearBlock(const Vehicle *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 (Airport->layout[v->u.air.previous_pos].block != Airport->layout[v->u.air.pos].block) {
|
if (apc->layout[v->u.air.previous_pos].block != apc->layout[v->u.air.pos].block) {
|
||||||
Station *st = GetStation(v->u.air.targetairport);
|
Station *st = GetStation(v->u.air.targetairport);
|
||||||
|
|
||||||
CLRBITS(st->airport_flags, Airport->layout[v->u.air.previous_pos].block);
|
CLRBITS(st->airport_flags, apc->layout[v->u.air.previous_pos].block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AirportGoToNextPosition(Vehicle *v, const AirportFTAClass *Airport)
|
static void AirportGoToNextPosition(Vehicle *v, const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
// 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;
|
||||||
|
|
||||||
AirportClearBlock(v, Airport);
|
AirportClearBlock(v, apc);
|
||||||
AirportMove(v, Airport); // move aircraft to next position
|
AirportMove(v, apc); // move aircraft to next position
|
||||||
}
|
}
|
||||||
|
|
||||||
// gets pos from vehicle and next orders
|
// gets pos from vehicle and next orders
|
||||||
static bool AirportMove(Vehicle *v, const AirportFTAClass *Airport)
|
static bool AirportMove(Vehicle *v, const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
AirportFTA *current;
|
AirportFTA *current;
|
||||||
byte prev_pos;
|
byte prev_pos;
|
||||||
|
|
||||||
// error handling
|
// error handling
|
||||||
if (v->u.air.pos >= Airport->nofelements) {
|
if (v->u.air.pos >= apc->nofelements) {
|
||||||
DEBUG(misc, 0) ("position %d is not valid for current airport. Max position is %d", v->u.air.pos, Airport->nofelements-1);
|
DEBUG(misc, 0) ("position %d is not valid for current airport. Max position is %d", v->u.air.pos, apc->nofelements-1);
|
||||||
assert(v->u.air.pos < Airport->nofelements);
|
assert(v->u.air.pos < apc->nofelements);
|
||||||
}
|
}
|
||||||
|
|
||||||
current = &Airport->layout[v->u.air.pos];
|
current = &apc->layout[v->u.air.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->u.air.state) {
|
||||||
prev_pos = v->u.air.pos; // location could be changed in state, so save it before-hand
|
prev_pos = v->u.air.pos; // location could be changed in state, so save it before-hand
|
||||||
_aircraft_state_handlers[v->u.air.state](v, Airport);
|
_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 != FLYING) v->u.air.previous_pos = prev_pos;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1764,8 +1764,8 @@ static bool AirportMove(Vehicle *v, const AirportFTAClass *Airport)
|
||||||
v->u.air.previous_pos = v->u.air.pos; // save previous location
|
v->u.air.previous_pos = v->u.air.pos; // save previous location
|
||||||
|
|
||||||
// there is only one choice to move to
|
// there is only one choice to move to
|
||||||
if (current->next_in_chain == NULL) {
|
if (current->next == NULL) {
|
||||||
if (AirportSetBlocks(v, current, Airport)) {
|
if (AirportSetBlocks(v, current, apc)) {
|
||||||
v->u.air.pos = current->next_position;
|
v->u.air.pos = current->next_position;
|
||||||
} // move to next position
|
} // move to next position
|
||||||
return false;
|
return false;
|
||||||
|
@ -1775,28 +1775,28 @@ static bool AirportMove(Vehicle *v, const AirportFTAClass *Airport)
|
||||||
// matches our heading
|
// matches our heading
|
||||||
do {
|
do {
|
||||||
if (v->u.air.state == current->heading || current->heading == TO_ALL) {
|
if (v->u.air.state == current->heading || current->heading == TO_ALL) {
|
||||||
if (AirportSetBlocks(v, current, Airport)) {
|
if (AirportSetBlocks(v, current, apc)) {
|
||||||
v->u.air.pos = current->next_position;
|
v->u.air.pos = current->next_position;
|
||||||
} // move to next position
|
} // move to next position
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
current = current->next_in_chain;
|
current = current->next;
|
||||||
} while (current != NULL);
|
} while (current != NULL);
|
||||||
|
|
||||||
DEBUG(misc, 0) ("Cannot move further on Airport...! pos:%d state:%d", v->u.air.pos, v->u.air.state);
|
DEBUG(misc, 0) ("Cannot move further on Airport...! pos:%d state:%d", v->u.air.pos, v->u.air.state);
|
||||||
DEBUG(misc, 0) ("Airport entry point: %d, Vehicle: %d", Airport->entry_point, v->index);
|
DEBUG(misc, 0) ("Airport entry point: %d, Vehicle: %d", apc->entry_point, v->index);
|
||||||
assert(0);
|
assert(0);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport)
|
static bool AirportHasBlock(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
const AirportFTA* reference = &Airport->layout[v->u.air.pos];
|
const AirportFTA* reference = &apc->layout[v->u.air.pos];
|
||||||
const AirportFTA* next = &Airport->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 (Airport->layout[current_pos->position].block != next->block) {
|
if (apc->layout[current_pos->position].block != next->block) {
|
||||||
const Station* st = GetStation(v->u.air.targetairport);
|
const Station* st = GetStation(v->u.air.targetairport);
|
||||||
uint32 airport_flags = next->block;
|
uint32 airport_flags = next->block;
|
||||||
|
|
||||||
|
@ -1815,26 +1815,26 @@ static bool AirportHasBlock(Vehicle *v, AirportFTA *current_pos, const AirportFT
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true on success. Eg, next block was free and we have occupied it
|
// returns true on success. Eg, next block was free and we have occupied it
|
||||||
static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport)
|
static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
AirportFTA* next = &Airport->layout[current_pos->next_position];
|
AirportFTA* next = &apc->layout[current_pos->next_position];
|
||||||
AirportFTA* reference = &Airport->layout[v->u.air.pos];
|
AirportFTA* reference = &apc->layout[v->u.air.pos];
|
||||||
AirportFTA* current;
|
AirportFTA* current;
|
||||||
|
|
||||||
// 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 ((Airport->layout[current_pos->position].block & next->block) != next->block) {
|
if ((apc->layout[current_pos->position].block & next->block) != next->block) {
|
||||||
uint32 airport_flags = next->block;
|
uint32 airport_flags = next->block;
|
||||||
Station* st = GetStation(v->u.air.targetairport);
|
Station* st = GetStation(v->u.air.targetairport);
|
||||||
//search for all all elements in the list with the same state, and blocks != N
|
//search for all all elements in the list with the same state, and blocks != N
|
||||||
// this means more blocks should be checked/set
|
// this means more blocks should be checked/set
|
||||||
current = current_pos;
|
current = current_pos;
|
||||||
if (current == reference) current = current->next_in_chain;
|
if (current == reference) current = current->next;
|
||||||
while (current != NULL) {
|
while (current != NULL) {
|
||||||
if (current->heading == current_pos->heading && current->block != 0) {
|
if (current->heading == current_pos->heading && current->block != 0) {
|
||||||
airport_flags |= current->block;
|
airport_flags |= current->block;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
current = current->next_in_chain;
|
current = current->next;
|
||||||
};
|
};
|
||||||
|
|
||||||
// if the block to be checked is in the next position, then exclude that from
|
// if the block to be checked is in the next position, then exclude that from
|
||||||
|
@ -1868,17 +1868,17 @@ static bool FreeTerminal(Vehicle *v, byte i, byte last_terminal)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint GetNumTerminals(const AirportFTAClass *Airport)
|
static uint GetNumTerminals(const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
uint num = 0;
|
uint num = 0;
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
for (i = Airport->terminals[0]; i > 0; i--) num += Airport->terminals[i];
|
for (i = apc->terminals[0]; i > 0; i--) num += apc->terminals[i];
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport)
|
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
AirportFTA *temp;
|
AirportFTA *temp;
|
||||||
Station *st;
|
Station *st;
|
||||||
|
@ -1893,9 +1893,9 @@ static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport)
|
||||||
* possible groups are checked (in this case group 1, since that is after group 0). If that
|
* possible groups are checked (in this case group 1, since that is after group 0). If that
|
||||||
* fails, then attempt fails and plane waits
|
* fails, then attempt fails and plane waits
|
||||||
*/
|
*/
|
||||||
if (Airport->terminals[0] > 1) {
|
if (apc->terminals[0] > 1) {
|
||||||
st = GetStation(v->u.air.targetairport);
|
st = GetStation(v->u.air.targetairport);
|
||||||
temp = Airport->layout[v->u.air.pos].next_in_chain;
|
temp = apc->layout[v->u.air.pos].next;
|
||||||
while (temp != NULL) {
|
while (temp != NULL) {
|
||||||
if (temp->heading == 255) {
|
if (temp->heading == 255) {
|
||||||
if (!HASBITS(st->airport_flags, temp->block)) {
|
if (!HASBITS(st->airport_flags, temp->block)) {
|
||||||
|
@ -1912,9 +1912,9 @@ static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport)
|
||||||
//that means, sum up all terminals of
|
//that means, sum up all terminals of
|
||||||
//groups with lower number
|
//groups with lower number
|
||||||
for (i = 1; i < target_group; i++)
|
for (i = 1; i < target_group; i++)
|
||||||
group_start += Airport->terminals[i];
|
group_start += apc->terminals[i];
|
||||||
|
|
||||||
group_end = group_start + Airport->terminals[target_group];
|
group_end = group_start + apc->terminals[target_group];
|
||||||
if (FreeTerminal(v, group_start, group_end)) return true;
|
if (FreeTerminal(v, group_start, group_end)) return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1922,34 +1922,34 @@ static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport)
|
||||||
* So we cannot move */
|
* So we cannot move */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
temp = temp->next_in_chain;
|
temp = temp->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there is only 1 terminalgroup, all terminals are checked (starting from 0 to max)
|
// if there is only 1 terminalgroup, all terminals are checked (starting from 0 to max)
|
||||||
return FreeTerminal(v, 0, GetNumTerminals(Airport));
|
return FreeTerminal(v, 0, GetNumTerminals(apc));
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint GetNumHelipads(const AirportFTAClass *Airport)
|
static uint GetNumHelipads(const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
uint num = 0;
|
uint num = 0;
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
for (i = Airport->helipads[0]; i > 0; i--) num += Airport->helipads[i];
|
for (i = apc->helipads[0]; i > 0; i--) num += apc->helipads[i];
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport)
|
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
// if an airport doesn't have helipads, use terminals
|
// if an airport doesn't have helipads, use terminals
|
||||||
if (Airport->helipads == NULL) return AirportFindFreeTerminal(v, Airport);
|
if (apc->helipads == NULL) return AirportFindFreeTerminal(v, apc);
|
||||||
|
|
||||||
// if there are more helicoptergroups, pick one, just as in AirportFindFreeTerminal()
|
// if there are more helicoptergroups, pick one, just as in AirportFindFreeTerminal()
|
||||||
if (Airport->helipads[0] > 1) {
|
if (apc->helipads[0] > 1) {
|
||||||
const Station* st = GetStation(v->u.air.targetairport);
|
const Station* st = GetStation(v->u.air.targetairport);
|
||||||
const AirportFTA* temp = Airport->layout[v->u.air.pos].next_in_chain;
|
const AirportFTA* temp = apc->layout[v->u.air.pos].next;
|
||||||
|
|
||||||
while (temp != NULL) {
|
while (temp != NULL) {
|
||||||
if (temp->heading == 255) {
|
if (temp->heading == 255) {
|
||||||
|
@ -1967,9 +1967,9 @@ static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport)
|
||||||
//that means, sum up all terminals of
|
//that means, sum up all terminals of
|
||||||
//groups with lower number
|
//groups with lower number
|
||||||
for (i = 1; i < target_group; i++)
|
for (i = 1; i < target_group; i++)
|
||||||
group_start += Airport->helipads[i];
|
group_start += apc->helipads[i];
|
||||||
|
|
||||||
group_end = group_start + Airport->helipads[target_group];
|
group_end = group_start + apc->helipads[target_group];
|
||||||
if (FreeTerminal(v, group_start, group_end)) return true;
|
if (FreeTerminal(v, group_start, group_end)) return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1977,12 +1977,12 @@ static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport)
|
||||||
* So we cannot move */
|
* So we cannot move */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
temp = temp->next_in_chain;
|
temp = temp->next;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// only 1 helicoptergroup, check all helipads
|
// only 1 helicoptergroup, check all helipads
|
||||||
// The blocks for helipads start after the last terminal (MAX_TERMINALS)
|
// The blocks for helipads start after the last terminal (MAX_TERMINALS)
|
||||||
return FreeTerminal(v, MAX_TERMINALS, GetNumHelipads(Airport) + MAX_TERMINALS);
|
return FreeTerminal(v, MAX_TERMINALS, GetNumHelipads(apc) + MAX_TERMINALS);
|
||||||
}
|
}
|
||||||
return false; // it shouldn't get here anytime, but just to be sure
|
return false; // it shouldn't get here anytime, but just to be sure
|
||||||
}
|
}
|
||||||
|
|
134
airport.c
134
airport.c
|
@ -21,20 +21,20 @@ static AirportFTAClass *HeliDepot;
|
||||||
static AirportFTAClass *IntercontinentalAirport;
|
static AirportFTAClass *IntercontinentalAirport;
|
||||||
static AirportFTAClass *HeliStation;
|
static AirportFTAClass *HeliStation;
|
||||||
|
|
||||||
static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
|
static void AirportFTAClass_Constructor(AirportFTAClass *apc,
|
||||||
const byte *terminals, const byte *helipads,
|
const byte *terminals, const byte *helipads,
|
||||||
const byte entry_point, const byte acc_planes,
|
const byte entry_point, const byte acc_planes,
|
||||||
const AirportFTAbuildup *FA,
|
const AirportFTAbuildup *apFA,
|
||||||
const TileIndexDiffC *depots, const byte nof_depots,
|
const TileIndexDiffC *depots, const byte nof_depots,
|
||||||
uint size_x, uint size_y
|
uint size_x, uint size_y
|
||||||
);
|
);
|
||||||
static void AirportFTAClass_Destructor(AirportFTAClass *Airport);
|
static void AirportFTAClass_Destructor(AirportFTAClass *apc);
|
||||||
|
|
||||||
static uint16 AirportGetNofElements(const AirportFTAbuildup *FA);
|
static uint16 AirportGetNofElements(const AirportFTAbuildup *apFA);
|
||||||
static void AirportBuildAutomata(AirportFTAClass *Airport, const AirportFTAbuildup *FA);
|
static void AirportBuildAutomata(AirportFTAClass *apc, const AirportFTAbuildup *apFA);
|
||||||
static byte AirportTestFTA(const AirportFTAClass *Airport);
|
static byte AirportTestFTA(const AirportFTAClass *apc);
|
||||||
#if 0
|
#if 0
|
||||||
static void AirportPrintOut(const AirportFTAClass *Airport, const bool full_report);
|
static void AirportPrintOut(const AirportFTAClass *apc, const bool full_report);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void InitializeAirports(void)
|
void InitializeAirports(void)
|
||||||
|
@ -191,11 +191,11 @@ void UnInitializeAirports(void)
|
||||||
AirportFTAClass_Destructor(HeliStation);
|
AirportFTAClass_Destructor(HeliStation);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
|
static void AirportFTAClass_Constructor(AirportFTAClass *apc,
|
||||||
const byte *terminals, const byte *helipads,
|
const byte *terminals, const byte *helipads,
|
||||||
const byte entry_point, const byte acc_planes,
|
const byte entry_point, const byte acc_planes,
|
||||||
const AirportFTAbuildup *FA,
|
const AirportFTAbuildup *apFA,
|
||||||
const TileIndexDiffC *depots, const byte nof_depots,
|
const TileIndexDiffC *depots, const byte nof_depots,
|
||||||
uint size_x, uint size_y
|
uint size_x, uint size_y
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -206,8 +206,8 @@ static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
|
||||||
int i;
|
int i;
|
||||||
nofterminals = nofhelipads = 0;
|
nofterminals = nofhelipads = 0;
|
||||||
|
|
||||||
Airport->size_x = size_x;
|
apc->size_x = size_x;
|
||||||
Airport->size_y = size_y;
|
apc->size_y = size_y;
|
||||||
|
|
||||||
//now we read the number of terminals we have
|
//now we read the number of terminals we have
|
||||||
if (terminals != NULL) {
|
if (terminals != NULL) {
|
||||||
|
@ -221,7 +221,7 @@ static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Airport->terminals = terminals;
|
apc->terminals = terminals;
|
||||||
|
|
||||||
//read helipads
|
//read helipads
|
||||||
if (helipads != NULL) {
|
if (helipads != NULL) {
|
||||||
|
@ -235,7 +235,7 @@ static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Airport->helipads = helipads;
|
apc->helipads = helipads;
|
||||||
|
|
||||||
// if there are more terminals than 6, internal variables have to be changed, so don't allow that
|
// if there are more terminals than 6, internal variables have to be changed, so don't allow that
|
||||||
// same goes for helipads
|
// same goes for helipads
|
||||||
|
@ -248,26 +248,26 @@ static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
|
||||||
assert(nofterminals <= MAX_TERMINALS);
|
assert(nofterminals <= MAX_TERMINALS);
|
||||||
assert(nofhelipads <= MAX_HELIPADS);
|
assert(nofhelipads <= MAX_HELIPADS);
|
||||||
|
|
||||||
Airport->nofelements = AirportGetNofElements(FA);
|
apc->nofelements = AirportGetNofElements(apFA);
|
||||||
// check
|
// check
|
||||||
if (entry_point >= Airport->nofelements) {printf("Entry point (%2d) must be within the airport positions (which is max %2d)\n", entry_point, Airport->nofelements);}
|
if (entry_point >= apc->nofelements) {printf("Entry point (%2d) must be within the airport positions (which is max %2d)\n", entry_point, apc->nofelements);}
|
||||||
assert(entry_point < Airport->nofelements);
|
assert(entry_point < apc->nofelements);
|
||||||
|
|
||||||
Airport->acc_planes = acc_planes;
|
apc->acc_planes = acc_planes;
|
||||||
Airport->entry_point = entry_point;
|
apc->entry_point = entry_point;
|
||||||
Airport->airport_depots = depots;
|
apc->airport_depots = depots;
|
||||||
Airport->nof_depots = nof_depots;
|
apc->nof_depots = nof_depots;
|
||||||
|
|
||||||
|
|
||||||
// build the state machine
|
// build the state machine
|
||||||
AirportBuildAutomata(Airport, FA);
|
AirportBuildAutomata(apc, apFA);
|
||||||
DEBUG(misc, 1) ("#Elements %2d; #Terminals %2d in %d group(s); #Helipads %2d in %d group(s); Entry Point %d",
|
DEBUG(misc, 1) ("#Elements %2d; #Terminals %2d in %d group(s); #Helipads %2d in %d group(s); Entry Point %d",
|
||||||
Airport->nofelements, nofterminals, nofterminalgroups, nofhelipads, nofhelipadgroups, Airport->entry_point
|
apc->nofelements, nofterminals, nofterminalgroups, nofhelipads, nofhelipadgroups, apc->entry_point
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
byte ret = AirportTestFTA(Airport);
|
byte ret = AirportTestFTA(apc);
|
||||||
if (ret != MAX_ELEMENTS) printf("ERROR with element: %d\n", ret - 1);
|
if (ret != MAX_ELEMENTS) printf("ERROR with element: %d\n", ret - 1);
|
||||||
assert(ret == MAX_ELEMENTS);
|
assert(ret == MAX_ELEMENTS);
|
||||||
}
|
}
|
||||||
|
@ -275,94 +275,94 @@ static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
|
||||||
// true -- full info including heading, block, etc
|
// true -- full info including heading, block, etc
|
||||||
// false -- short info, only position and next position
|
// false -- short info, only position and next position
|
||||||
#if 0
|
#if 0
|
||||||
AirportPrintOut(Airport, false);
|
AirportPrintOut(apc, false);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AirportFTAClass_Destructor(AirportFTAClass *Airport)
|
static void AirportFTAClass_Destructor(AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
AirportFTA *current, *next;
|
AirportFTA *current, *next;
|
||||||
|
|
||||||
for (i = 0; i < Airport->nofelements; i++) {
|
for (i = 0; i < apc->nofelements; i++) {
|
||||||
current = Airport->layout[i].next_in_chain;
|
current = apc->layout[i].next;
|
||||||
while (current != NULL) {
|
while (current != NULL) {
|
||||||
next = current->next_in_chain;
|
next = current->next;
|
||||||
free(current);
|
free(current);
|
||||||
current = next;
|
current = next;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
free(Airport->layout);
|
free(apc->layout);
|
||||||
free(Airport);
|
free(apc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16 AirportGetNofElements(const AirportFTAbuildup *FA)
|
static uint16 AirportGetNofElements(const AirportFTAbuildup *apFA)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint16 nofelements = 0;
|
uint16 nofelements = 0;
|
||||||
int temp = FA[0].position;
|
int temp = apFA[0].position;
|
||||||
|
|
||||||
for (i = 0; i < MAX_ELEMENTS; i++) {
|
for (i = 0; i < MAX_ELEMENTS; i++) {
|
||||||
if (temp != FA[i].position) {
|
if (temp != apFA[i].position) {
|
||||||
nofelements++;
|
nofelements++;
|
||||||
temp = FA[i].position;
|
temp = apFA[i].position;
|
||||||
}
|
}
|
||||||
if (FA[i].position == MAX_ELEMENTS) break;
|
if (apFA[i].position == MAX_ELEMENTS) break;
|
||||||
}
|
}
|
||||||
return nofelements;
|
return nofelements;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AirportBuildAutomata(AirportFTAClass *Airport, const AirportFTAbuildup *FA)
|
static void AirportBuildAutomata(AirportFTAClass *apc, const AirportFTAbuildup *apFA)
|
||||||
{
|
{
|
||||||
AirportFTA *FAutomata;
|
AirportFTA *FAutomata;
|
||||||
AirportFTA *current;
|
AirportFTA *current;
|
||||||
uint16 internalcounter, i;
|
uint16 internalcounter, i;
|
||||||
FAutomata = malloc(sizeof(AirportFTA) * Airport->nofelements);
|
FAutomata = malloc(sizeof(AirportFTA) * apc->nofelements);
|
||||||
Airport->layout = FAutomata;
|
apc->layout = FAutomata;
|
||||||
internalcounter = 0;
|
internalcounter = 0;
|
||||||
|
|
||||||
for (i = 0; i < Airport->nofelements; i++) {
|
for (i = 0; i < apc->nofelements; i++) {
|
||||||
current = &Airport->layout[i];
|
current = &apc->layout[i];
|
||||||
current->position = FA[internalcounter].position;
|
current->position = apFA[internalcounter].position;
|
||||||
current->heading = FA[internalcounter].heading;
|
current->heading = apFA[internalcounter].heading;
|
||||||
current->block = FA[internalcounter].block;
|
current->block = apFA[internalcounter].block;
|
||||||
current->next_position = FA[internalcounter].next_in_chain;
|
current->next_position = apFA[internalcounter].next;
|
||||||
|
|
||||||
// outgoing nodes from the same position, create linked list
|
// outgoing nodes from the same position, create linked list
|
||||||
while (current->position == FA[internalcounter + 1].position) {
|
while (current->position == apFA[internalcounter + 1].position) {
|
||||||
AirportFTA *newNode = malloc(sizeof(AirportFTA));
|
AirportFTA *newNode = malloc(sizeof(AirportFTA));
|
||||||
|
|
||||||
newNode->position = FA[internalcounter + 1].position;
|
newNode->position = apFA[internalcounter + 1].position;
|
||||||
newNode->heading = FA[internalcounter + 1].heading;
|
newNode->heading = apFA[internalcounter + 1].heading;
|
||||||
newNode->block = FA[internalcounter + 1].block;
|
newNode->block = apFA[internalcounter + 1].block;
|
||||||
newNode->next_position = FA[internalcounter + 1].next_in_chain;
|
newNode->next_position = apFA[internalcounter + 1].next;
|
||||||
// create link
|
// create link
|
||||||
current->next_in_chain = newNode;
|
current->next = newNode;
|
||||||
current = current->next_in_chain;
|
current = current->next;
|
||||||
internalcounter++;
|
internalcounter++;
|
||||||
} // while
|
} // while
|
||||||
current->next_in_chain = NULL;
|
current->next = NULL;
|
||||||
internalcounter++;
|
internalcounter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static byte AirportTestFTA(const AirportFTAClass *Airport)
|
static byte AirportTestFTA(const AirportFTAClass *apc)
|
||||||
{
|
{
|
||||||
byte position, i, next_element;
|
byte position, i, next_element;
|
||||||
AirportFTA *temp;
|
AirportFTA *temp;
|
||||||
next_element = 0;
|
next_element = 0;
|
||||||
|
|
||||||
for (i = 0; i < Airport->nofelements; i++) {
|
for (i = 0; i < apc->nofelements; i++) {
|
||||||
position = Airport->layout[i].position;
|
position = apc->layout[i].position;
|
||||||
if (position != next_element) return i;
|
if (position != next_element) return i;
|
||||||
temp = &Airport->layout[i];
|
temp = &apc->layout[i];
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (temp->heading > MAX_HEADINGS && temp->heading != 255) return i;
|
if (temp->heading > MAX_HEADINGS && temp->heading != 255) return i;
|
||||||
if (temp->heading == 0 && temp->next_in_chain != 0) return i;
|
if (temp->heading == 0 && temp->next != 0) return i;
|
||||||
if (position != temp->position) return i;
|
if (position != temp->position) return i;
|
||||||
if (temp->next_position >= Airport->nofelements) return i;
|
if (temp->next_position >= apc->nofelements) return i;
|
||||||
temp = temp->next_in_chain;
|
temp = temp->next;
|
||||||
} while (temp != NULL);
|
} while (temp != NULL);
|
||||||
next_element++;
|
next_element++;
|
||||||
}
|
}
|
||||||
|
@ -410,14 +410,14 @@ static uint AirportBlockToString(uint32 block)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void AirportPrintOut(const AirportFTAClass *Airport, const bool full_report)
|
static void AirportPrintOut(const AirportFTAClass *apc, const bool full_report)
|
||||||
{
|
{
|
||||||
byte heading;
|
byte heading;
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
printf("(P = Current Position; NP = Next Position)\n");
|
printf("(P = Current Position; NP = Next Position)\n");
|
||||||
for (i = 0; i < Airport->nofelements; i++) {
|
for (i = 0; i < apc->nofelements; i++) {
|
||||||
const AirportFTA* temp = &Airport->layout[i];
|
const AirportFTA* temp = &apc->layout[i];
|
||||||
|
|
||||||
if (full_report) {
|
if (full_report) {
|
||||||
heading = (temp->heading == 255) ? MAX_HEADINGS + 1 : temp->heading;
|
heading = (temp->heading == 255) ? MAX_HEADINGS + 1 : temp->heading;
|
||||||
|
@ -428,8 +428,8 @@ static void AirportPrintOut(const AirportFTAClass *Airport, const bool full_repo
|
||||||
} else {
|
} else {
|
||||||
printf("P:%2d NP:%2d", temp->position, temp->next_position);
|
printf("P:%2d NP:%2d", temp->position, temp->next_position);
|
||||||
}
|
}
|
||||||
while (temp->next_in_chain != NULL) {
|
while (temp->next != NULL) {
|
||||||
temp = temp->next_in_chain;
|
temp = temp->next;
|
||||||
if (full_report) {
|
if (full_report) {
|
||||||
heading = (temp->heading == 255) ? MAX_HEADINGS + 1 : temp->heading;
|
heading = (temp->heading == 255) ? MAX_HEADINGS + 1 : temp->heading;
|
||||||
printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n",
|
printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n",
|
||||||
|
|
10
airport.h
10
airport.h
|
@ -141,11 +141,11 @@ typedef struct AirportFTAClass {
|
||||||
|
|
||||||
// internal structure used in openttd - Finite sTate mAchine --> FTA
|
// internal structure used in openttd - Finite sTate mAchine --> FTA
|
||||||
typedef struct AirportFTA {
|
typedef struct AirportFTA {
|
||||||
byte position; // the position that an airplane is at
|
byte position; // the position that an airplane is at
|
||||||
byte next_position; // next position from this position
|
byte next_position; // next position from this position
|
||||||
uint32 block; // 32 bit blocks (st->airport_flags), should be enough for the most complex airports
|
uint32 block; // 32 bit blocks (st->airport_flags), should be enough for the most complex airports
|
||||||
byte heading; // heading (current orders), guiding an airplane to its target on an airport
|
byte heading; // heading (current orders), guiding an airplane to its target on an airport
|
||||||
struct AirportFTA *next_in_chain; // possible extra movement choices from this position
|
struct AirportFTA *next; // possible extra movement choices from this position
|
||||||
} AirportFTA;
|
} AirportFTA;
|
||||||
|
|
||||||
void InitializeAirports(void);
|
void InitializeAirports(void);
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
// state machine input struct (from external file, etc.)
|
// state machine input struct (from external file, etc.)
|
||||||
// Finite sTate mAchine --> FTA
|
// Finite sTate mAchine --> FTA
|
||||||
typedef struct AirportFTAbuildup {
|
typedef struct AirportFTAbuildup {
|
||||||
byte position; // the position that an airplane is at
|
byte position; // the position that an airplane is at
|
||||||
byte heading; // the current orders (eg. TAKEOFF, HANGAR, ENDLANDING, etc.)
|
byte heading; // the current orders (eg. TAKEOFF, HANGAR, ENDLANDING, etc.)
|
||||||
uint32 block; // the block this position is on on the airport (st->airport_flags)
|
uint32 block; // the block this position is on on the airport (st->airport_flags)
|
||||||
byte next_in_chain; // next position from this position
|
byte next; // next position from this position
|
||||||
} AirportFTAbuildup;
|
} AirportFTAbuildup;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue