]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/AIMgr.cxx
any wind < 1kt is "calm", not just 0.0
[flightgear.git] / src / ATC / AIMgr.cxx
index 4fdc5eec235366fd6ccf4d81657bacb529629d75..8b38de6639829aa11182c61f7cb1851c6a2368b5 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>
 
@@ -48,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();
@@ -56,8 +59,9 @@ FGAIMgr::FGAIMgr() {
 }
 
 FGAIMgr::~FGAIMgr() {
-        ssgDeRefDelete(_defaultModel);
-       if(_havePiperModel) ssgDeRefDelete(_piperModel);
+    for (ai_list_itr = ai_list.begin(); ai_list_itr != ai_list.end(); ai_list_itr++) {
+        delete (*ai_list_itr);
+    }
 }
 
 void FGAIMgr::init() {
@@ -105,10 +109,6 @@ void FGAIMgr::init() {
                _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/");
@@ -309,7 +309,7 @@ void FGAIMgr::ActivateAirport(const string& ident) {
        ATC->AIRegisterAirport(ident);
        // TODO - need to start the traffic more randomly
        FGAILocalTraffic* local_traffic = new FGAILocalTraffic;
-       local_traffic->SetModel(_defaultModel); // currently hardwired to cessna.
+       local_traffic->SetModel(_defaultModel.get());   // currently hardwired to cessna.
        //local_traffic->Init(ident, IN_PATTERN, TAKEOFF_ROLL);
        local_traffic->Init(GenerateShortForm(GenerateUniqueCallsign()), ident);
        local_traffic->FlyCircuits(1, true);    // Fly 2 circuits with touch & go in between
@@ -381,7 +381,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';
        
@@ -469,7 +472,7 @@ void FGAIMgr::GenerateSimpleAirportTraffic(const string& ident, double min_dist)
                        else cessna = true;
                        string s = GenerateShortForm(GenerateUniqueCallsign(), (cessna ? "Cessna-" : "Piper-"));
                        FGAIGAVFRTraffic* t = new FGAIGAVFRTraffic();
-                       t->SetModel(cessna ? _defaultModel : (_havePiperModel ? _piperModel : _defaultModel));
+                       t->SetModel(cessna ? _defaultModel.get() : (_havePiperModel ? _piperModel.get() : _defaultModel.get()));
                        //cout << "Generating VFR traffic " << s << " inbound to " << ident << " " << ad << " meters out from " << dir << " degrees\n";
                        Point3D tpos = dclUpdatePosition(aptpos, dir, 6.0, ad);
                        if(tpos.elev() > (aptpos.elev() + 3000.0)) tpos.setelev(aptpos.elev() + 3000.0);        // FEET yuk :-(