]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/ground.cxx
Catch sound exceptions at the earliest, report problem has an alert, and continue...
[flightgear.git] / src / ATC / ground.cxx
index a6dc207905b9363c8ccd565588c81e38b1510128..ebd172d2319731508187897d9403e51540bab321 100644 (file)
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/math/sg_random.h>
 #include <simgear/debug/logstream.hxx>
@@ -53,7 +57,7 @@ a_path::a_path() {
 
 FGGround::FGGround() {
        ATCmgr = globals->get_ATC_mgr();
-       display = false;
+       _type = GROUND;
        networkLoadOK = false;
        ground_traffic.erase(ground_traffic.begin(), ground_traffic.end());
        ground_traffic_itr = ground_traffic.begin();
@@ -66,9 +70,8 @@ FGGround::FGGround() {
        aptElev = 0.0;
 }
 
-FGGround::FGGround(string id) {
+FGGround::FGGround(const string& id) {
        ATCmgr = globals->get_ATC_mgr();
-       display = false;
        networkLoadOK = false;
        ground_traffic.erase(ground_traffic.begin(), ground_traffic.end());
        ground_traffic_itr = ground_traffic.begin();
@@ -273,7 +276,6 @@ bool FGGround::LoadNetwork() {
 }
 
 void FGGround::Init() {
-       display = false;
        untowered = false;
        
        // Figure out which is the active runway - TODO - it would be better to have ground call tower
@@ -317,7 +319,8 @@ void FGGround::Update(double dt) {
                                trns += " taxi holding point runway ";  // TODO - add the holding point name
                                // eg " taxi holding point G2 runway "
                                trns += ConvertRwyNumToSpokenString(activeRwy);
-                               if(display) {
+                               if(_display) {
+                                       fgSetString("/sim/messages/ground", trns.c_str());
                                        globals->get_ATC_display()->RegisterSingleMessage(trns, 0);
                                }
                                g->planePtr->RegisterTransmission(1);   // cleared to taxi
@@ -331,11 +334,12 @@ void FGGround::Update(double dt) {
                        // NOTE - we don't need to do the contact tower bit unless we have separate tower and ground
                        string trns = g->plane.callsign;
                        trns += " contact Tower ";
-                       double f = globals->get_ATC_mgr()->GetFrequency(ident, TOWER);
+                       double f = globals->get_ATC_mgr()->GetFrequency(ident, TOWER) / 100.0;
                        char buf[10];
-                       sprintf(buf, "%f", f);
+                       sprintf(buf, "%.2f", f);
                        trns += buf;
-                       if(display) {
+                       if(_display) {
+                               fgSetString("/sim/messages/ground", trns.c_str());
                                globals->get_ATC_display()->RegisterSingleMessage(trns, 0);
                        }
                        g->planePtr->RegisterTransmission(2);   // contact tower
@@ -345,6 +349,9 @@ void FGGround::Update(double dt) {
                }                               
                ++ground_traffic_itr;
        }
+       
+       // Call the base class update for the response time handling.
+       FGATC::Update(dt);
 }
 
 // Figure out which runways are active.
@@ -356,10 +363,6 @@ void FGGround::DoRwyDetails() {
        //cout << "GetRwyDetails called" << endl;
        
        // Based on the airport-id and wind get the active runway
-       SGPath path( globals->get_fg_root() );
-       path.append( "Airports" );
-       path.append( "runways.mk4" );
-       FGRunways r_ways( path.c_str() );
        
        //wind
        double hdg = wind_from_hdg->getDoubleValue();
@@ -368,27 +371,27 @@ void FGGround::DoRwyDetails() {
        //cout << "Heading = " << hdg << '\n';
        
        FGRunway runway;
-       bool rwyGood = r_ways.search(ident, int(hdg), &runway);
+       bool rwyGood = globals->get_runways()->search(ident, int(hdg), &runway);
        if(rwyGood) {
-               activeRwy = runway.rwy_no;
-               rwy.rwyID = runway.rwy_no;
+               activeRwy = runway._rwy_no;
+               rwy.rwyID = runway._rwy_no;
                SG_LOG(SG_ATC, SG_INFO, "In FGGround, active runway for airport " << ident << " is " << activeRwy);
                
                // Get the threshold position
-               double other_way = runway.heading - 180.0;
+               double other_way = runway._heading - 180.0;
                while(other_way <= 0.0) {
                        other_way += 360.0;
                }
        // move to the +l end/center of the runway
-               //cout << "Runway center is at " << runway.lon << ", " << runway.lat << '\n';
-       Point3D origin = Point3D(runway.lon, runway.lat, aptElev);
+               //cout << "Runway center is at " << runway._lon << ", " << runway._lat << '\n';
+       Point3D origin = Point3D(runway._lon, runway._lat, aptElev);
                Point3D ref = origin;
        double tshlon, tshlat, tshr;
                double tolon, tolat, tor;
-               rwy.length = runway.length * SG_FEET_TO_METER;
+               rwy.length = runway._length * SG_FEET_TO_METER;
        geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), other_way, 
                                rwy.length / 2.0 - 25.0, &tshlat, &tshlon, &tshr );
-       geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), runway.heading, 
+       geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), runway._heading, 
                                rwy.length / 2.0 - 25.0, &tolat, &tolon, &tor );
                // Note - 25 meters in from the runway end is a bit of a hack to put the plane ahead of the user.
                // now copy what we need out of runway into rwy
@@ -396,7 +399,7 @@ void FGGround::DoRwyDetails() {
                Point3D takeoff_end = Point3D(tolon, tolat, aptElev);
                //cout << "Threshold position = " << tshlon << ", " << tshlat << ", " << aptElev << '\n';
                //cout << "Takeoff position = " << tolon << ", " << tolat << ", " << aptElev << '\n';
-               rwy.hdg = runway.heading;
+               rwy.hdg = runway._heading;
                // Set the projection for the local area based on this active runway
                ortho.Init(rwy.threshold_pos, rwy.hdg); 
                rwy.end1ortho = ortho.ConvertToLocal(rwy.threshold_pos);        // should come out as zero
@@ -455,10 +458,15 @@ Gate* FGGround::GetGateNode() {
 }
 
 
+node* FGGround::GetHoldShortNode(const string& rwyID) {
+       return(NULL);   // TODO - either implement me or remove me!!!
+}
+
+
 // WARNING - This is hardwired to my prototype logical network format
 // and will almost certainly change when Bernie's stuff comes on-line.
 // Returns NULL if it can't find a valid node.
-node* FGGround::GetThresholdNode(string rwyID) {
+node* FGGround::GetThresholdNode(const string& rwyID) {
        // For now go through all the nodes and parse their names
        // Maybe in the future we'll map threshold nodes by ID
        //cout << "Size of network is " << network.size() << '\n';
@@ -493,10 +501,10 @@ ground_network_path_type FGGround::GetPath(node* A, node* B) {
 };
 
 // Get a path from a node to a runway threshold
-ground_network_path_type FGGround::GetPath(node* A, string rwyID) {
+ground_network_path_type FGGround::GetPath(node* A, const string& rwyID) {
        node* b = GetThresholdNode(rwyID);
        if(b == NULL) {
-               SG_LOG(SG_ATC, SG_ALERT, "ERROR - unable to find path to runway theshold in ground.cxx\n");
+               SG_LOG(SG_ATC, SG_ALERT, "ERROR - unable to find path to runway theshold in ground.cxx for airport " << ident << '\n');
                ground_network_path_type emptyPath;
                emptyPath.erase(emptyPath.begin(), emptyPath.end());
                return(emptyPath);
@@ -506,7 +514,7 @@ ground_network_path_type FGGround::GetPath(node* A, 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 FGGround::GetPathToHoldShort(node* A, string rwyID) {
+ground_network_path_type FGGround::GetPathToHoldShort(node* A, const string& rwyID) {
        ground_network_path_type path = GetPath(A, rwyID);
        path.pop_back();        // That should be the threshold stripped of 
        path.pop_back();        // and that should be the arc from hold short to threshold
@@ -655,12 +663,12 @@ ground_network_path_type FGGround::GetShortestPath(node* A, node* B) {
 
 // Return a list of exits from a given runway
 // It is up to the calling function to check for non-zero size of returned array before use
-node_array_type FGGround::GetExits(string rwyID) {
+node_array_type FGGround::GetExits(const string& rwyID) {
        // FIXME - get a 07L or similar in here and we're stuffed!!!
        return(runways[atoi(rwyID.c_str())].exits);
 }
 
-void FGGround::RequestDeparture(PlaneRec plane, FGAIEntity* requestee) {
+void FGGround::RequestDeparture(const PlaneRec& plane, FGAIEntity* requestee) {
        // For now we'll just automatically clear all planes to the runway hold.
        // This communication needs to be delayed 20 sec or so from receiving the request.
        // Even if display=false we still need to start the timer in case display=true when communication starts.