21#ifndef _TRAFFIC_CONTROL_HXX_
22#define _TRAFFIC_CONTROL_HXX_
27#include <osg/Geometry>
28#include <osg/MatrixTransform>
31#include <simgear/compiler.h>
33#include <simgear/math/sg_geodesy.hxx>
34#include <simgear/debug/logstream.hxx>
35#include <simgear/structure/SGReferenced.hxx>
36#include <simgear/structure/SGSharedPtr.hxx>
68 bool holdPattern =
false;
69 int requestedArrivalTime{0};
70 bool holdPosition =
false;
71 bool requestHoldPosition =
false;
72 bool resumeTaxi =
false;
73 bool changeSpeed =
false;
74 bool changeHeading =
false;
75 bool changeAltitude =
false;
76 bool resolveCircularWait =
false;
80 double speed = std::numeric_limits<double>::max();
93 requestedArrivalTime = val;
96 return requestedArrivalTime;
102 return requestHoldPosition;
112 return changeHeading;
115 return changeAltitude;
118 return resolveCircularWait;
145 requestHoldPosition = val;
157 changeAltitude = val;
160 resolveCircularWait = val;
195 bool allowTransmission;
198 int plannedArrivalTime{0};
209 time_t takeOffTimeSlot{0};
210 std::string callsign;
212 SGSharedPtr<FGAIAircraft> aircraft;
251 return instruction.hasInstruction();
271 return instruction.getChangeSpeed();
274 plannedArrivalTime = val;
278 return plannedArrivalTime;
281 if (plannedArrivalTime) {
282 SG_LOG(SG_ATC, SG_BULK, callsign <<
"(" <<
id <<
") Runwayslot timedelta " << (val-plannedArrivalTime));
284 instruction.setRunwaySlot(val);
288 return instruction.getRunwaySlot();
311 return instruction.getWaitsForId();
314 return instruction.getWaitingSince();
320 instruction.setChangeSpeed (
false);
323 instruction.setChangeHeading(
false);
327 return instruction.getChangeHeading();
330 return instruction.getHoldPosition();
333 return instruction.getRequestHoldPosition();
336 return instruction.getResumeTaxi();
339 instruction.setHoldPosition(inst);
342 instruction.setRequestHoldPosition(inst);
345 instruction.setResumeTaxi(inst);
348 return instruction.getWaitsForId();
351 instruction.setWaitsForId(
id);
354 instruction.setWaitingSince(
id);
359 instruction.setResolveCircularWait(
true);
362 instruction.setResolveCircularWait(
false);
378 allowTransmission=
true;
395 return allowTransmission;
400 allowTransmission=
false;
403 allowTransmission=
true;
432 const std::string icao;
433 const std::string rwy;
434 int currentlyCleared;
435 double distanceToFinal;
436 using AircraftRefVec = std::vector<SGSharedPtr<FGTrafficRecord>>;
437 AircraftRefVec runwayQueue;
449 return currentlyCleared;
454 return distanceToFinal;
460 void addToQueue(SGSharedPtr<FGTrafficRecord> ac);
463 currentlyCleared = number;
466 void updateFirst(SGSharedPtr<FGTrafficRecord> eta, time_t newETA);
469 return runwayQueue.size();
476 const SGSharedPtr<FGTrafficRecord>
get(
int id)
const;
487 std::sort(runwayQueue.begin(), runwayQueue.end(),
488 [](
const SGSharedPtr<FGTrafficRecord> a,
const SGSharedPtr<FGTrafficRecord> b) {
489 return a->getRunwaySlot() < b->getRunwaySlot();
const SGSharedPtr< FGTrafficRecord > get(int id) const
Fetch the first aircraft in the departure queue with a certain status.
double getApproachDistance() const
void setCleared(int number)
ActiveRunwayQueue(const std::string &apt, const std::string &r, int cc)
void updateDepartureQueue()
const time_t SEPARATION
Separation between aircraft in seconds.
void updateFirst(SGSharedPtr< FGTrafficRecord > eta, time_t newETA)
Update the first and move all records backwards.
void requestTimeSlot(SGSharedPtr< FGTrafficRecord > eta)
Fetch next slot for the active runway.
const std::string & getRunwayName() const
const SGSharedPtr< FGTrafficRecord > getFirstAircraftInDepartureQueue() const
int getCleared() const
Get id of cleared AI Aircraft.
void printRunwayQueue() const
Output the contents of the departure queue vector nicely formatted.
const SGSharedPtr< FGTrafficRecord > getFirstOfStatus(int stat) const
Fetch the first aircraft in the departure queue with a certain status.
void removeFromQueue(int id)
void addToQueue(SGSharedPtr< FGTrafficRecord > ac)
void setHoldPattern(bool val)
void setResolveCircularWait(bool val)
bool getChangeHeading() const
bool getChangeAltitude() const
bool getHoldPosition() const
void setChangeHeading(bool val)
void setRunwaySlot(int val)
int getWaitsForId() const
bool getChangeSpeed() const
void setWaitsForId(int id)
void setResumeTaxi(bool val)
double getHeading() const
void setSpeed(double val)
void setChangeSpeed(bool val)
int getWaitingSince() const
void setHeading(double val)
bool hasInstruction() const
bool getCheckForCircularWait() const
void setHoldPosition(bool val)
int getRunwaySlot() const
void setChangeAltitude(bool val)
void setRequestHoldPosition(bool val)
void setWaitingSince(int t)
bool getResumeTaxi() const
bool getHoldPattern() const
bool getRequestHoldPosition() const
void setRequestHoldPosition(bool inst)
void setHeadingAdjustment(double heading)
bool checkPositionAndIntentions(FGTrafficRecord &other)
Check if another aircraft is ahead of the current one, and on the same taxiway.
int getCurrentPosition() const
void setPlannedArrivalTime(int val)
void setWaitingSince(int id)
void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt, int leg)
void setSpeedAdjustment(double spd)
void setResolveCircularWait()
bool isActive(int margin) const
bool hasHoldPosition() const
bool getRequestHoldPosition() const
void setPositionAndIntentions(int pos, FGAIFlightPlan *route)
bool allowTransmissions() const
bool pushBackAllowed() const
bool getSpeedAdjustment() const
void setState(int s)
Set the current ATC State of type.
double getHeadingDiff() const
The last diff of heading when turning.
void setRadius(double rad)
void allowRepeatedTransmissions()
bool isOpposing(FGGroundNetwork *, FGTrafficRecord &other, int node)
bool hasHeadingAdjustment() const
double getFAltitude() const
int getState() const
Return the current ATC State of type.
int crosses(FGGroundNetwork *, FGTrafficRecord &other)
void suppressRepeatedTransmissions()
int getPlannedArrivalTime() const
Arrival time planned by aircraft.
const std::string & getRunway() const
FGAIAircraft * getAircraft() const
void setCallsign(const std::string &clsgn)
int getWaitingSince() const
void setTakeOffSlot(time_t timeSlot)
FGATCInstruction getInstruction() const
void setHoldPosition(bool inst)
void setTakeOffStatus(int status)
void clearHeadingAdjustment()
double getHeading() const
void setRunwaySlot(int val)
const std::string & getCallsign() const
int getNextFrequency() const
virtual ~FGTrafficRecord()
void setResumeTaxi(bool inst)
void setWaitsForId(int id)
int getRunwaySlot()
Arrival time requested by ATC.
void setAircraft(FGAIAircraft *ref)
bool hasInstruction() const
int getWaitsForId() const
void setTime(time_t time)
void clearATCController() const
bool getResumeTaxi() const
void clearSpeedAdjustment()
bool onRoute(FGGroundNetwork *, FGTrafficRecord &other)
void clearResolveCircularWait()
void resetTakeOffStatus()
void setRunway(const std::string &rwy)
std::vector< int > intVec
std::vector< int >::iterator intVecIterator
std::vector< int > intVec
std::vector< FGAIFlightPlan * >::iterator FlightPlanVecIterator
std::list< SGSharedPtr< FGTrafficRecord > >::const_iterator TrafficVectorIterator
std::vector< FGAIAircraft * > AircraftVec
std::map< std::string, FlightPlanVec > FlightPlanVecMap
std::vector< FGAIAircraft * >::iterator AircraftVecIterator
std::vector< ActiveRunwayQueue > ActiveRunwayVec
std::vector< ActiveRunwayQueue >::iterator ActiveRunwayVecIterator
std::vector< FGAIFlightPlan * > FlightPlanVec
std::list< SGSharedPtr< FGTrafficRecord > > TrafficVector