]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/AIMgr.cxx
Recent SimGear changes seem to require more additions of config.h to FG in order...
[flightgear.git] / src / ATC / AIMgr.cxx
index 22cb4716a6790b8599eb1de96340154d749f76a9..34527a79f016b2c216c6d8617c6f30cb57be8eca 100644 (file)
 //
 // 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.
 
-#include <simgear/misc/sg_path.hxx>
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
 
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
+#include <simgear/misc/sg_path.hxx>
 #include <simgear/math/sg_random.h>
-
 #include <list>
 
 #ifdef _MSC_VER
@@ -49,7 +51,7 @@ SG_USING_STD(cout);
 FGAIMgr::FGAIMgr() {
        ATC = globals->get_ATC_mgr();
        initDone = false;
-       ai_callsigns_used["CFGFS"] = 1; // so we don't inadvertently use this
+       ai_callsigns_used["GFS"] = 1;   // so we don't inadvertently use this
        // TODO - use the proper user callsign when it becomes user settable.
        removalList.clear();
        activated.clear();
@@ -57,8 +59,6 @@ FGAIMgr::FGAIMgr() {
 }
 
 FGAIMgr::~FGAIMgr() {
-        ssgDeRefDelete(_defaultModel);
-       if(_havePiperModel) ssgDeRefDelete(_piperModel);
 }
 
 void FGAIMgr::init() {
@@ -75,14 +75,14 @@ void FGAIMgr::init() {
        
        // Load up models at the start to avoid pausing later
        // Hack alert - Hardwired paths!!
-       string planepath = "Aircraft/c172r/Models/c172-dpm.ac";
+       string planepath = "Aircraft/c172p/Models/c172p.xml";
        bool _loadedDefaultOK = true;
        try {
                _defaultModel = sgLoad3DModel( globals->get_fg_root(),
                                           planepath.c_str(),
                                                                           globals->get_props(),
                                                                           globals->get_sim_time_sec() );
-       } catch(sg_exception& e) {
+       } catch(sg_exception&) {
                _loadedDefaultOK = false;
        }
        
@@ -102,14 +102,10 @@ void FGAIMgr::init() {
                                         planepath.c_str(),
                                                                         globals->get_props(),
                                                                         globals->get_sim_time_sec() );
-       } catch(sg_exception& e) {
+       } catch(sg_exception&) {
                _havePiperModel = false;
        }
 
-       // We need to keep one ref of the models open to stop ssg deleting them behind our back!
-       _defaultModel->ref();
-       if(_havePiperModel) _piperModel->ref();
-
        // go through the $FG_ROOT/ATC directory and find all *.taxi files
        SGPath path(globals->get_fg_root());
        path.append("ATC/");
@@ -131,9 +127,9 @@ void FGAIMgr::init() {
                        ext = file.substr(pos + 1);
                        if(ext == "taxi") {
                                f_ident = file.substr(0, pos);
-                               FGAirport a;
-                               if(dclFindAirportID(f_ident, &a)) {
-                                       SGBucket sgb(a.getLongitude(), a.getLatitude());
+                               const FGAirport *a = fgFindAirportID( f_ident);
+                               if(a){
+                                       SGBucket sgb(a->getLongitude(), a->getLatitude());
                                        int idx = sgb.gen_index();
                                        if(facilities.find(idx) != facilities.end()) {
                                                facilities[idx]->push_back(f_ident);
@@ -159,7 +155,7 @@ void FGAIMgr::init() {
        /*
        // TESTING
        FGATCAlignedProjection ortho;
-       ortho.Init(dclGetAirportPos("KEMT"), 205.0);    // Guess of rwy19 heading
+       ortho.Init(fgGetAirportPos("KEMT"), 205.0);     // Guess of rwy19 heading
        //Point3D ip = ortho.ConvertFromLocal(Point3D(6000, 1000, 1000));       // 90 deg entry
        //Point3D ip = ortho.ConvertFromLocal(Point3D(-7000, 3000, 1000));      // 45 deg entry
        Point3D ip = ortho.ConvertFromLocal(Point3D(1000, -7000, 1000));        // straight-in
@@ -209,21 +205,23 @@ void FGAIMgr::update(double dt) {
                ai_activated_map_iterator apt_itr = activated.begin();
                while(apt_itr != activated.end()) {
                        //cout << "FIRST IS " << (*apt_itr).first << '\n';
-                       if(dclGetHorizontalSeparation(userPos, dclGetAirportPos((*apt_itr).first)) > (35.0 * 1600.0)) {
+                       if(dclGetHorizontalSeparation(userPos, fgGetAirportPos((*apt_itr).first)) > (35.0 * 1600.0)) {
                                // Then get rid of it and make sure the iterator is left pointing to the next one!
                                string s = (*apt_itr).first;
                                if(traffic.find(s) != traffic.end()) {
                                        //cout << "s = " << s << ", traffic[s].size() = " << traffic[s].size() << '\n';
-                                       if(traffic[s].size()) {
+                                       if(!traffic[s].empty()) {
                                                apt_itr++;
                                        } else {
                                                //cout << "Erasing " << (*apt_itr).first << " and traffic" << '\n';
-                                               activated.erase(apt_itr++);
+                                               activated.erase(apt_itr);
+                                               apt_itr = activated.upper_bound(s);
                                                traffic.erase(s);
                                        }
                                } else {
                                                //cout << "Erasing " << (*apt_itr).first << ' ' << (*apt_itr).second << '\n';
-                                               activated.erase(apt_itr++);
+                                               activated.erase(apt_itr);
+                                               apt_itr = activated.upper_bound(s);
                                }
                        } else {
                                apt_itr++;
@@ -237,14 +235,14 @@ void FGAIMgr::update(double dt) {
                        //cout << "s = " << s << " size = " << (*it).second.size() << '\n';
                        // Only generate extra traffic if within a certain distance of the user,
                        // TODO - maybe take users's tuned freq into account as well.
-                       double d = dclGetHorizontalSeparation(userPos, dclGetAirportPos(s)); 
+                       double d = dclGetHorizontalSeparation(userPos, fgGetAirportPos(s)); 
                        if(d < (15.0 * 1600.0)) {
                                double cd = 0.0;
                                bool gen = false;
                                //cout << "Size of list is " << (*it).second.size() << " at " << s << '\n';
                                if((*it).second.size()) {
                                        FGAIEntity* e = *((*it).second.rbegin());       // Get the last airplane currently scheduled to arrive at this airport.
-                                       cd = dclGetHorizontalSeparation(e->GetPos(), dclGetAirportPos(s));
+                                       cd = dclGetHorizontalSeparation(e->GetPos(), fgGetAirportPos(s));
                                        if(cd < (d < 5000 ? 10000 : d + 5000)) {
                                                gen = true;
                                        }
@@ -331,8 +329,8 @@ void FGAIMgr::GenerateSimpleAirportTraffic(const string& ident, double min_dist)
        /*
        // TODO - check for military airports - this should be in the current data.
        // UGGH - there's no point at the moment - everything is labelled civil in basic.dat!
-       FGAirport a;
-       if(dclFindAirportID(ident, &a)) {
+       FGAirport a = fgFindAirportID(ident, &a);
+       if(a) {
                cout << "CODE IS " << a.code << '\n';
        } else {
                // UG - can't find the airport!
@@ -340,7 +338,7 @@ void FGAIMgr::GenerateSimpleAirportTraffic(const string& ident, double min_dist)
        }
        */
        
-       Point3D aptpos = dclGetAirportPos(ident);       // TODO - check for elev of -9999
+       Point3D aptpos = fgGetAirportPos(ident);        // TODO - check for elev of -9999
        //cout << "ident = " << ident << ", elev = " << aptpos.elev() << '\n';
        
        // Operate from airports at 3000ft and below only to avoid the default cloud layers and since we don't degrade AI performance with altitude.
@@ -380,7 +378,10 @@ void FGAIMgr::GenerateSimpleAirportTraffic(const string& ident, double min_dist)
        double d = dclGetHorizontalSeparation(userpos, aptpos); // in meters
        
        int lev = fgGetInt("/sim/ai-traffic/level");
-       if(lev < 1 || lev > 3) lev = 2;
+       if(lev < 1)
+               return;
+       if (lev > 3)
+               lev = 3;
        if(visibility < 6000) lev = 1;
        //cout << "level = " << lev << '\n';
        
@@ -554,7 +555,7 @@ void FGAIMgr::SearchByPos(double range) {
                for(twd_itr = towered.begin(); twd_itr != towered.end(); twd_itr++) {
                        // Only activate the closest airport not already activated each time.
                        if(activated.find(twd_itr->ident) == activated.end()) {
-                               double sep = dclGetHorizontalSeparation(Point3D(lon, lat, elev), dclGetAirportPos(twd_itr->ident));
+                               double sep = dclGetHorizontalSeparation(Point3D(lon, lat, elev), fgGetAirportPos(twd_itr->ident));
                                if(sep < closest) {
                                        closest = sep;
                                        s = twd_itr->ident;