]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/ground.hxx
This innocuous looking typo was crashing the sim whenever an AI plane was asked to...
[flightgear.git] / src / ATC / ground.hxx
index 1fab75c1eef317c4d640a3993e15a90c696173f0..318191c82668f66c80699710a1cf45f9a409ed04 100644 (file)
@@ -16,7 +16,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 #ifndef _FG_GROUND_HXX
 #define _FG_GROUND_HXX
@@ -25,9 +25,7 @@
 #include STL_STRING
 
 SG_USING_STD(string);
-#ifndef SG_HAVE_NATIVE_SGI_COMPILERS
 SG_USING_STD(ios);
-#endif
 
 #include <map>
 #include <vector>
@@ -37,7 +35,10 @@ SG_USING_STD(ios);
 #include <simgear/math/sg_geodesy.hxx>
 
 #include "ATC.hxx"
+//#include "ATCmgr.hxx"
 #include "ATCProjection.hxx"
+#include "AIEntity.hxx"
+//#include "AILocalTraffic.hxx"        // RunwayDetails - this is a temporary hack
 
 SG_USING_STD(map);
 SG_USING_STD(vector);
@@ -45,12 +46,12 @@ SG_USING_STD(list);
 
 //////////////////////////////////////////////////////
 // Types for the logical network data structure
-typedef enum arc_type {
+enum arc_type {
        RUNWAY,
        TAXIWAY
 };
 
-typedef enum node_type {
+enum node_type {
        GATE,
        APRON,
        HOLD,
@@ -72,7 +73,7 @@ enum GateType {
        OTHER   // ie. anything goes!!
 };
 
-typedef enum network_element_type {
+enum network_element_type {
        NODE,
        ARC
 };
@@ -83,7 +84,7 @@ struct ground_network_element {
 
 struct arc : public ground_network_element {
        int distance;
-       char* name;
+       string name;
        arc_type type;
        bool directed;  //false if 2-way, true if 1-way.  
        //This is a can of worms since arcs might be one way in different directions under different circumstances
@@ -97,10 +98,13 @@ typedef arc_array_type::iterator arc_array_iterator;
 typedef arc_array_type::const_iterator arc_array_const_iterator; 
 
 struct node : public ground_network_element {
+       node();
+       ~node();
+       
        unsigned int nodeID;    //each node in an airport needs a unique ID number - this is ZERO-BASED to match array position
        Point3D pos;
        Point3D orthoPos;
-       char* name;
+       string name;
        node_type type;
        arc_array_type arcs;
        double max_turn_radius;
@@ -115,23 +119,23 @@ struct Gate : public node {
        int max_weight; //units??
        //airline_code airline; //For the future - we don't have any airline codes ATM
        int id; // The gate number in the logical scheme of things
-       string sid;     // The real-world gate letter/number
+       string name;    // The real-world gate letter/number
        //node* pNode;
        bool used;
        double heading; // The direction the parked-up plane should point in degrees
 };
 
-typedef vector < Gate > gate_vec_type;
+typedef vector < Gate* > gate_vec_type;
 typedef gate_vec_type::iterator gate_vec_iterator;
 typedef gate_vec_type::const_iterator gate_vec_const_iterator;
 
 // A map of gate vs. the logical (internal FGFS) gate ID
-typedef map < int, Gate > gate_map_type;
+typedef map < int, Gate* > gate_map_type;
 typedef gate_map_type::iterator gate_map_iterator;
 typedef gate_map_type::const_iterator gate_map_const_iterator;
 
 // Runways - all the runway stuff is likely to change in the future
-typedef struct Rwy {
+struct Rwy {
        int id; //note this is a very simplified scheme for now - R & L are not differentiated
        //It should work for simple one rwy airports
        node_array_type exits;  //Array of available exits from runway
@@ -139,6 +143,7 @@ typedef struct Rwy {
        // Eventually we will also want some encoding of real-life preferred runways
        // This will get us up and running for single runway airports though.
 };
+
 typedef vector < Rwy > runway_array_type;
 typedef runway_array_type::iterator runway_array_iterator;
 typedef runway_array_type::const_iterator runway_array_const_iterator;
@@ -156,29 +161,61 @@ typedef ground_network_path_type::const_iterator ground_network_path_const_itera
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
+////////////////////////////////////////////////
+//
+// Stuff for the shortest-path algorithms
+struct a_path {
+       a_path();
+       
+       ground_network_path_type path;
+       int cost;
+};
+
+// Paths mapped by nodeID reached so-far
+typedef map < unsigned int, a_path* > shortest_path_map_type;
+typedef shortest_path_map_type::iterator shortest_path_map_iterator;
+
+// Nodes mapped by their ID
+//typedef map < unsigned int, node* > node_map_type;
+//typedef node_map_type::iterator node_map_iterator;
+////////////////////////////////////////////////
+
 // Planes active within the ground network.
-// somewhere in the ATC/AI system we are going to have defined something like
-// typedef struct plane_rec
-// list <PlaneRec> plane_rec_list_type
-/*
+
 // A more specialist plane rec to include ground information
-typedef struct ground_rec {
-    plane_rec plane;
-    point current_pos;
-    node destination;
-    node last_clearance;
+struct GroundRec {
+       FGAIEntity* planePtr;   // This might move to the planeRec eventually
+       
+    PlaneRec plane;
+    Point3D current_pos;
+    node* destination;
+    node* last_clearance;
+       bool taxiRequestOutstanding;    // Plane has requested taxi and we haven't responded yet
+       double clearanceCounter;                // Hack for communication timing - counter since clearance requested in seconds 
+       
     bool cleared;  // set true when the plane has been cleared to somewhere
     bool incoming; //true for arrivals, false for departures
     // status?
     // Almost certainly need to add more here
 };
 
-typedef list<ground_rec*> ground_rec_list;
+typedef list < GroundRec* > ground_rec_list;
 typedef ground_rec_list::iterator ground_rec_list_itr;
 typedef ground_rec_list::const_iterator ground_rec_list_const_itr;
-*/
+
 //////////////////////////////////////////////////////////////////////////////////////////
 
+// Hack
+// perhaps we could use an FGRunway instead of this
+struct GRunwayDetails {
+       Point3D threshold_pos;
+       Point3D end1ortho;      // ortho projection end1 (the threshold ATM)
+       Point3D end2ortho;      // ortho projection end2 (the take off end in the current hardwired scheme)
+       double hdg;             // true runway heading
+       double length;  // In *METERS*
+       string rwyID;
+};
+
 ///////////////////////////////////////////////////////////////////////////////
 //
 // FGGround
@@ -188,35 +225,19 @@ class FGGround : public FGATC {
 
 public:
        FGGround();
+       FGGround(const string& id);
        ~FGGround();
     void Init();
 
-    void Update();
+    void Update(double dt);
        
-       inline char get_type() const { return type; }
-       inline double get_lon() const { return lon; }
-       inline double get_lat() const { return lat; }
-       inline double get_elev() const { return elev; }
-       inline double get_x() const { return x; }
-       inline double get_y() const { return y; }
-       inline double get_z() const { return z; }
-       inline int get_freq() const { return freq; }
-       inline int get_range() const { return range; }
-       inline const char* GetIdent() { return ident.c_str(); }
-       inline string get_trans_ident() { return trans_ident; }
-       inline string get_name() { return name; }
-       inline atc_type GetType() { return GROUND; }
-
-    inline void SetDisplay() {display = true;}
-    inline void SetNoDisplay() {display = false;}
-
-    // Its possible that NewArrival and NewDeparture should simply be rolled into Request.
+       inline const string& get_trans_ident() { return trans_ident; }
 
     // Contact ground control on arrival, assumed to request any gate
     //void NewArrival(plane_rec plane);
 
     // Contact ground control on departure, assumed to request currently active runway.
-    //void NewDeparture(plane_rec plane);
+    void RequestDeparture(const PlaneRec& plane, FGAIEntity* requestee);
 
     // Contact ground control when the calling routine doesn't know if arrival
     // or departure is appropriate.
@@ -231,22 +252,31 @@ public:
        // Return a suitable gate (maybe this should be a list of suitable gates so the plane or controller can choose the closest one)
        void ReturnGate(Gate &gate, GateType type);
        
-       //The following two functions have been made public for now but may go private with a higher level accessor at some point
-       // Return the internal ID of a random, suitable, unused gate
-       // For now we are simply implementing as any random unused gate
-       int GetRandomGateID();
-       // Return a pointer to a node based on the gate ID
-       Gate* GetGateNode(int gateID);
+       // Return a pointer to an unused gate
+       Gate* GetGateNode();
+       
+       // Return a pointer to a hold short node
+       node* GetHoldShortNode(const string& rwyID);
        
        // Runway stuff - this might change in the future.
        // Get a list of exits from a given runway
-       node_array_type GetExits(int rwyID);
+       // It is up to the calling function to check for non-zero size of returned array before use
+       node_array_type GetExits(const string& rwyID);
        
        // Get a path from one node to another
-       ground_network_path_type GetPath(node* A, node* B); 
+       ground_network_path_type GetPath(node* A, node* B);
+       
+       // Get a path from a node to a runway threshold
+       ground_network_path_type GetPath(node* A, const string& rwyID);
+       
+       // Get a path from a node to a runway hold short point
+       // Bit of a hack this at the moment!
+       ground_network_path_type GetPathToHoldShort(node* A, const string& rwyID);
 
 private:
-
+       FGATCMgr* ATCmgr;       
+       // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
+       
     // Need a data structure to hold details of the various active planes
     // Need a data structure to hold details of the logical network
     // including which gates are filled - or possibly another data structure
@@ -262,10 +292,6 @@ private:
        // A map of all the gates indexed against internal (FGFS) ID
        gate_map_type gates;
        gate_map_iterator gatesItr;
-       
-       // Runway stuff - this might change in the future.
-       //runway_array_type runways;    // STL way
-       Rwy runways[36];        // quick hack!
 
        FGATCAlignedProjection ortho;
        
@@ -275,77 +301,65 @@ private:
     // Find the shortest route through the logical network between two points.
     //FindShortestRoute(point a, point b);
 
-    // Project a point in WGS84 lat/lon onto the local gnomonic.
-    //ConvertWGS84ToXY(sgVec3 wgs84, point xy);
-
     // Assign a gate or parking location to a new arrival
     //AssignGate(ground_rec &g);
 
     // Generate the next clearance for an airplane
     //NextClearance(ground_rec &g);
        
-       char type;
-       double lon, lat;
-       double elev;
-       double x, y, z;
-       int freq;
-       int range;
-       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.
-       string ident;           // Code of the airport its at.
-       string name;            // Name generally used in transmissions.
+       // 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
+       
        // for failure modeling
        string trans_ident;             // transmitted ident
        bool ground_failed;             // ground failed?
+       bool networkLoadOK;             // Indicates whether LoadNetwork returned true or false at last attempt
        
-       friend istream& operator>> ( istream&, FGGround& );
-};
+       // Tower control
+       bool untowered;         // True if this is an untowered airport (we still need the ground class for shortest path implementation etc
+       //FGATC* tower;         // Pointer to the tower control
 
-inline istream&
-operator >> ( istream& in, FGGround& g )
-{
-       double f;
-       char ch;
-       
-       in >> g.type;
+       // Logical runway details - this might change in the future.
+       //runway_array_type runways;    // STL way
+       Rwy runways[37];        // quick hack!
        
-       if ( g.type == '[' )
-               return in >> skipeol;
+       // Physical runway details
+       double aptElev;         // Airport elevation
+       string activeRwy;       // Active runway number - For now we'll disregard multiple / alternate runway operation.
+       RunwayDetails rwy;      // Assumed to be the active one for now.// Figure out which runways are active.
        
-       in >> g.lat >> g.lon >> g.elev >> f >> g.range 
-       >> g.ident;
+       // For now we'll just be simple and do one active runway - eventually this will get much more complex
+       // Copied from FGTower - TODO - it would be better to implement this just once, and have ground call tower
+       // for runway operation details, but at the moment we can't guarantee that tower control at a given airport
+       // will be initialised before ground so we can't do that.
+       void DoRwyDetails();    
        
-       g.name = "";
-       in >> ch;
-       g.name += ch;
-       while(1) {
-               //in >> noskipws
-               in.unsetf(ios::skipws);
-               in >> ch;
-               g.name += ch;
-               if((ch == '"') || (ch == 0x0A)) {
-                       break;
-               }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
-       }
-       in.setf(ios::skipws);
-       //cout << "tower.name = " << t.name << '\n';
+       // Load the logical ground network for this airport from file.
+       // Return true if successfull.
+       bool LoadNetwork();
        
-       g.freq = (int)(f*100.0 + 0.5);
+       // Parse a runway exit string and push the supplied node pointer onto the runway exit list
+       void ParseRwyExits(node* np, char* es);
        
-       // cout << g.ident << endl;
+       // Return a random gate ID of an unused gate.
+       // Two error values may be returned and must be checked for by the calling function:
+       // -2 signifies that no gates exist at this airport.
+       // -1 signifies that all gates are currently full.
+       // TODO - modify to return a suitable gate based on aircraft size/weight.
+       int GetRandomGateID();
        
-       // generate cartesian coordinates
-       Point3D geod( g.lon * SGD_DEGREES_TO_RADIANS, g.lat * SGD_DEGREES_TO_RADIANS, g.elev );
-       Point3D cart = sgGeodToCart( geod );
-       g.x = cart.x();
-       g.y = cart.y();
-       g.z = cart.z();
+       // Return a pointer to the node at a runway threshold
+       // Returns NULL if unsuccessful.
+       node* GetThresholdNode(const string& rwyID);
        
-       g.trans_ident = g.ident;
-       g.ground_failed = false;
+       // A shortest path algorithm from memory (I can't find the bl&*dy book again!)
+       ground_network_path_type GetShortestPath(node* A, node* B); 
        
-       return in >> skipeol;
-}
+       // Planes
+       ground_rec_list ground_traffic;
+       ground_rec_list_itr ground_traffic_itr;
+};
 
 #endif // _FG_GROUND_HXX