]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIBase.cxx
Improve timing statistics
[flightgear.git] / src / AIModel / AIBase.cxx
index 8681bc1b10ac5d6684701d707d5b104246277d91..33cb073cbd5a3b30c5480fe7d88f8dd5c9e4265c 100644 (file)
@@ -53,11 +53,14 @@ const double FGAIBase::lbs_to_slugs = 0.031080950172;   //conversion factor
 using namespace simgear;
 
 FGAIBase::FGAIBase(object_type ot) :
+    _max_speed(300),
+    _name(""),
+    _parent(""),
     props( NULL ),
     model_removed( fgGetNode("/ai/models/model-removed", true) ),
     manager( NULL ),
+    _installed(false),
     fp( NULL ),
-
     _impact_lat(0),
     _impact_lon(0),
     _impact_elev(0),
@@ -65,11 +68,10 @@ FGAIBase::FGAIBase(object_type ot) :
     _impact_pitch(0),
     _impact_roll(0),
     _impact_speed(0),
-
     _refID( _newAIModelID() ),
     _otype(ot),
-    _initialized(false),
-    _parent("")
+    _initialized(false)
+
 {
     tgt_heading = hdg = tgt_altitude_ft = tgt_speed = 0.0;
     tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0;
@@ -193,20 +195,31 @@ void FGAIBase::Transform() {
 }
 
 bool FGAIBase::init(bool search_in_AI_path) {
-    osg::ref_ptr<osgDB::ReaderWriter::Options> opt=
-        new osgDB::ReaderWriter::Options(*osgDB::Registry::instance()->getOptions());
-
+    
+    string f;
     if(search_in_AI_path)
     {
-        SGPath ai_path(globals->get_fg_root());
-        ai_path.append("AI");
-        opt->getDatabasePathList().push_front(ai_path.str());
+    // setup a modified Options structure, with only the $fg-root/AI defined;
+    // we'll check that first, then give the normal search logic a chance.
+    // this ensures that models in AI/ are preferred to normal models, where
+    // both exist.
+        osg::ref_ptr<osgDB::ReaderWriter::Options> 
+          opt(osg::clone(osgDB::Registry::instance()->getOptions(), osg::CopyOp::SHALLOW_COPY));
+
+        SGPath ai_path(globals->get_fg_root(), "AI");
+        opt->setDatabasePath(ai_path.str());
+        
+        f = osgDB::findDataFile(model_path, opt.get());
     }
 
-    string f = osgDB::findDataFile(model_path, opt.get());
-
+    if (f.empty()) {
+      f = simgear::SGModelLib::findDataFile(model_path);
+    }
+    
     if(f.empty())
         f = fgGetString("/sim/multiplay/default-model", default_model);
+    else
+        _installed = true;
 
     model = load3DModel(f, props);
 
@@ -219,6 +232,8 @@ bool FGAIBase::init(bool search_in_AI_path) {
 
     } else if (!model_path.empty()) {
         SG_LOG(SG_INPUT, SG_WARN, "AIBase: Could not load model " << model_path);
+        // not properly installed...
+        _installed = false;
     }
 
     setDie(false);
@@ -596,7 +611,7 @@ double FGAIBase::_getRdot() const {
 }
 
 double FGAIBase::_getVS_fps() const {
-    return vs*60.0;
+    return vs/60.0;
 }
 
 double FGAIBase::_get_speed_east_fps() const {
@@ -608,13 +623,19 @@ double FGAIBase::_get_speed_north_fps() const {
 }
 
 void FGAIBase::_setVS_fps( double _vs ) {
-    vs = _vs/60.0;
+    vs = _vs*60.0;
 }
 
 double FGAIBase::_getAltitude() const {
     return altitude_ft;
 }
 
+double FGAIBase::_getAltitudeAGL(SGGeod inpos, double start){
+    getGroundElevationM(SGGeod::fromGeodM(inpos, start),
+        _elevation_m, &_material);
+    return inpos.getElevationFt() - _elevation_m * SG_METER_TO_FEET;
+}
+
 bool FGAIBase::_getServiceable() const {
     return serviceable;
 }