]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/tower.hxx
Return position
[flightgear.git] / src / ATC / tower.hxx
index 48f1c4fd548045f102acba52bb5a986be2af7601..db0899c0fef207edca6ee9e79cf9121cfb193cc9 100644 (file)
@@ -38,6 +38,7 @@ SG_USING_STD(ios);
 //#include "ATCmgr.hxx"
 #include "ground.hxx"
 #include "ATCProjection.hxx"
+#include "AIPlane.hxx"
 
 //DCL - a complete guess for now.
 #define FG_TOWER_DEFAULT_RANGE 30
@@ -46,21 +47,10 @@ enum tower_traffic_type {
        CIRCUIT,
        INBOUND,
        OUTBOUND,
+       TTT_UNKNOWN,    // departure, but we don't know if for circuits or leaving properly
        STRAIGHT_IN
        // Umm - what's the difference between INBOUND and STRAIGHT_IN ?
-};
-
-// Much simplified compared to AILocalTraffic
-enum TwrPatternLeg {
-       TWR_LANDING_ROLL,
-       TWR_FINAL,
-       TWR_BASE,
-       TWR_DOWNWIND,
-       TWR_CROSSWIND,
-       TWR_CLIMBOUT,
-       TWR_TAKEOFF_ROLL,
-       TWR_UNKNOWN
-};
+};     // TODO - need some differentiation of IFR and VFR traffic in order to give the former priority.
 
 // Structure for holding details of a plane under tower control.
 // Not fixed yet - may include more stuff later.
@@ -73,7 +63,7 @@ public:
        TowerPlaneRec(Point3D pt);
        TowerPlaneRec(PlaneRec p, Point3D pt);
        
-       FGAIEntity* planePtr;   // This might move to the planeRec eventually
+       FGAIPlane* planePtr;    // This might move to the planeRec eventually
        PlaneRec plane;
        
        Point3D pos;
@@ -97,7 +87,7 @@ public:
        tower_traffic_type opType;
        
        // Whereabouts in circuit if doing circuits
-       TwrPatternLeg leg;
+       PatternLeg leg;
        
        bool isUser;    // true if this plane is the user
 };
@@ -130,8 +120,8 @@ public:
        void ReportRunwayVacated(string ID);
        void ReportReadyForDeparture(string ID);
        
-       // Contact tower when at a hold short for departure
-       void ContactAtHoldShort(PlaneRec plane, FGAIEntity* requestee, tower_traffic_type operation);
+       // Contact tower when at a hold short for departure - for now we'll assume plane - maybe vehicles might want to cross runway eventually?
+       void ContactAtHoldShort(PlaneRec plane, FGAIPlane* requestee, tower_traffic_type operation);
        
        // Public interface to the active runway - this will get more complex 
        // in the future and consider multi-runway use, airplane weight etc.
@@ -145,6 +135,21 @@ public:
        inline atc_type GetType() { return TOWER; }
        
        inline FGGround* GetGroundPtr() { return ground; }
+       
+       // Returns true if positions of crosswind/downwind/base leg turns should be constrained by previous traffic
+       // plus the constraint position as a rwy orientated orthopos (meters)
+       bool GetCrosswindConstraint(double& cpos);
+       bool GetDownwindConstraint(double& dpos);
+       bool GetBaseConstraint(double& bpos);
+       
+       // Returns true if OK to transmit on this frequency
+       inline bool FreqClear() { return freqClear; }
+       // Indicate that the frequency is in use
+       inline void FreqInUse() { freqClear = false; }
+       // The idea is that AI traffic or the user ATC dialog box calls FreqInUse() when they begin transmitting,
+       // and that the tower control sets freqClear back to true following a reply.
+       // AI traffic should check FreqClear() is true prior to transmitting.
+       // The user will just have to wait for a gap in dialog as in real life.
 
 private:
        FGATCMgr* ATCmgr;       
@@ -157,14 +162,23 @@ private:
        // Figure out if a given position lies on a runway or not
        bool OnAnyRunway(Point3D pt);
        
-       // Calculate the eta of each plane to the threshold.
+       // Calculate the eta of a plane to the threshold.
        // For ground traffic this is the fastest they can get there.
        // For air traffic this is the middle approximation.
+       void CalcETA(TowerPlaneRec* tpr);
+       
+       // Iterate through all the lists and call CalcETA for all the planes.
        void doThresholdETACalc();
        
        // Order the list of traffic as per expected threshold use and flag any conflicts
        bool doThresholdUseOrder();
        
+       // Calculate the crow-flys distance of a plane to the threshold in meters
+       double CalcDistOutM(TowerPlaneRec* tpr);
+
+       // Calculate the crow-flys distance of a plane to the threshold in miles
+       double CalcDistOutMiles(TowerPlaneRec* tpr);
+       
        void doCommunication();
        
        void IssueLandingClearance(TowerPlaneRec* tpr);
@@ -174,6 +188,8 @@ private:
        bool display;           // Flag to indicate whether we should be outputting to the ATC display.
        bool displaying;                // Flag to indicate whether we are outputting to the ATC display.
        
+       bool freqClear;         // Flag to indicate if the frequency is clear of ongoing dialog
+       
        // environment - need to make sure we're getting the surface winds and not winds aloft.
        SGPropertyNode* wind_from_hdg;  //degrees
        SGPropertyNode* wind_speed_knots;               //knots
@@ -193,12 +209,18 @@ private:
        // or possibly another data structure with the positions of the inactive planes.
        // Need a data structure to hold outstanding communications from aircraft.
        
-       // Linked-list of planes on approach ordered with nearest first (timewise).
+       // Linked-list of planes on approach to active rwy ordered with nearest first (timewise).
        // Includes planes that have landed but not yet vacated runway.
        // Somewhat analagous to the paper strips used (used to be used?) in real life.
        // Doesn't include planes in circuit until they turn onto base/final?
+       // TODO - may need to alter this for operation to more than one active rwy.
        tower_plane_rec_list_type appList;
        tower_plane_rec_list_iterator appListItr;
+
+       // What should we do with planes approaching the airport to join the circuit somewhere
+       // but not on straight-in though? - put them in here for now.   
+       tower_plane_rec_list_type circuitAppList;
+       tower_plane_rec_list_iterator circuitAppListItr;
        
        // List of departed planes (planes doing circuits go into circuitList not depList after departure)
        tower_plane_rec_list_type depList;
@@ -219,6 +241,17 @@ private:
        // List of all planes due to use a given rwy arranged in projected order of rwy use
        tower_plane_rec_list_type trafficList;  // TODO - needs to be expandable to more than one rwy
        tower_plane_rec_list_iterator trafficListItr;
+       
+       // Returns true if successful
+       bool RemoveFromTrafficList(string id);
+       
+       // Return the ETA of plane no. list_pos (1-based) in the traffic list.
+       // i.e. list_pos = 1 implies next to use runway.
+       double GetTrafficETA(unsigned int list_pos);
+       
+       // Add a tower plane rec with ETA to the traffic list in the correct position ETA-wise.
+       // Returns true if this could cause a threshold ETA conflict with other traffic, false otherwise.
+       bool AddToTrafficList(TowerPlaneRec* t, bool holding = false);
 
        // Ground can be separate or handled by tower in real life.
        // In the program we will always use a separate FGGround class, but we need to know
@@ -230,10 +263,17 @@ private:
        string trans_ident;             // transmitted ident
        bool tower_failed;              // tower failed?
        
-    // Pointers to current users position
-    SGPropertyNode* user_lon_node;
-    SGPropertyNode* user_lat_node;
-    SGPropertyNode* user_elev_node;
+       // Pointers to current users position and orientation
+       SGPropertyNode* user_lon_node;
+       SGPropertyNode* user_lat_node;
+       SGPropertyNode* user_elev_node;
+       SGPropertyNode* user_hdg_node;
+       
+       // Details of the general traffic flow etc in the circuit
+       double crosswind_leg_pos;       // Distance from threshold crosswind leg is being turned to in meters (actual operation - *not* ideal circuit)
+       double downwind_leg_pos;        // Actual offset distance in meters from the runway that planes are flying the downwind leg
+       // Currently not sure whether the above should be always +ve or just take the natural orthopos sign (+ve for RH circuit, -ve for LH).
+       double base_leg_pos;            // Actual offset distance from the threshold (-ve) that planes are turning to base leg.
        
        friend istream& operator>> ( istream&, FGTower& );
 };