]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIBase.cxx
Interpret environment variables and hostname on Windows
[flightgear.git] / src / AIModel / AIBase.cxx
index 69c69d8902403de9d6524c8e7f0ae868b7bfafae..d143296a18f04b8f931701721924fb4bf5634fd8 100644 (file)
 #include <osg/Node>
 #include <osgDB/FileUtils>
 
-#include <simgear/math/point3d.hxx>
-#include <simgear/math/polar3d.hxx>
-#include <simgear/math/sg_geodesy.hxx>
+#include <simgear/math/SGMath.hxx>
 #include <simgear/misc/sg_path.hxx>
-#include <simgear/scene/model/location.hxx>
 #include <simgear/scene/model/modellib.hxx>
 #include <simgear/scene/util/SGNodeMasks.hxx>
 #include <simgear/debug/logstream.hxx>
@@ -47,9 +44,9 @@
 #include <Scripting/NasalSys.hxx>
 
 #include "AIBase.hxx"
-#include "AIModelData.hxx"
 #include "AIManager.hxx"
 
+const char *default_model = "Models/Geometry/glider.ac";
 const double FGAIBase::e = 2.71828183;
 const double FGAIBase::lbs_to_slugs = 0.031080950172;   //conversion factor
 
@@ -70,7 +67,8 @@ FGAIBase::FGAIBase(object_type ot) :
     _impact_speed(0),
 
     _refID( _newAIModelID() ),
-    _otype(ot)
+    _otype(ot),
+    _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;
@@ -83,7 +81,43 @@ FGAIBase::FGAIBase(object_type ot) :
     delete_me = false;
     _impact_reported = false;
     _collision_reported = false;
+       _expiry_reported = false;
+
     _subID = 0;
+
+    _x_offset = 0;
+    _y_offset = 0;
+    _z_offset = 0;
+
+    _pitch_offset = 0;
+    _roll_offset = 0;
+    _yaw_offset = 0;
+
+    userpos = SGGeod::fromDeg(0, 0);
+
+    pos = SGGeod::fromDeg(0, 0);
+    speed = 0;
+    altitude_ft = 0;
+    speed_north_deg_sec = 0;
+    speed_east_deg_sec = 0;
+    turn_radius_ft = 0;
+
+    ft_per_deg_lon = 0;
+    ft_per_deg_lat = 0;
+
+    horiz_offset = 0;
+    vert_offset = 0;
+    ht_diff = 0;
+
+    serviceable = false;
+
+    fp = 0;
+
+    rho = 1;
+    T = 280;
+    p = 1e5;
+    a = 340;
+    Mach = 0;
 }
 
 FGAIBase::~FGAIBase() {
@@ -107,7 +141,8 @@ void FGAIBase::readFromScenario(SGPropertyNode* scFileNode)
     if (!scFileNode)
         return;
 
-    setPath(scFileNode->getStringValue("model", "Models/Geometry/glider.ac"));
+    setPath(scFileNode->getStringValue("model",
+            fgGetString("/sim/multiplay/default-model", default_model)));
 
     setHeading(scFileNode->getDoubleValue("heading", 0.0));
     setSpeed(scFileNode->getDoubleValue("speed", 0.0));
@@ -170,16 +205,16 @@ bool FGAIBase::init(bool search_in_AI_path) {
     string f = osgDB::findDataFile(model_path, opt.get());
 
     if(f.empty())
-        f="Models/Geometry/glider.ac";
+        f = fgGetString("/sim/multiplay/default-model", default_model);
 
     model = load3DModel(f, props);
 
-    if (model.valid()) {
-        model->setNodeMask(model->getNodeMask() & ~SG_NODEMASK_TERRAIN_BIT);
+    if (model.valid() && _initialized == false) {
         aip.init( model.get() );
         aip.setVisible(true);
         invisible = false;
         globals->get_scenery()->get_scene_graph()->addChild(aip.getSceneGraph());
+        _initialized = true;
 
     } else if (!model_path.empty()) {
         SG_LOG(SG_INPUT, SG_WARN, "AIBase: Could not load model " << model_path);
@@ -192,7 +227,8 @@ bool FGAIBase::init(bool search_in_AI_path) {
 void FGAIBase::initModel(osg::Node *node)
 {
     if (model.valid()) {
-        fgSetString("/ai/models/model-added", props->getPath());
+
+        fgSetString("/ai/models/model-added", props->getPath().c_str());
 
     } else if (!model_path.empty()) {
         SG_LOG(SG_INPUT, SG_WARN, "AIBase: Could not load model " << model_path);
@@ -205,7 +241,8 @@ void FGAIBase::initModel(osg::Node *node)
 
 osg::Node* FGAIBase::load3DModel(const string &path, SGPropertyNode *prop_root)
 {
-  model = SGModelLib::loadPagedModel(path, prop_root, new FGAIModelData(this, prop_root));
+  model = SGModelLib::loadPagedModel(path, prop_root, new FGNasalModelData(prop_root));
+  initModel(model.get());
   return model.get();
 }
 
@@ -315,9 +352,16 @@ void FGAIBase::unbind() {
     props->untie("radar/ht-diff-ft");
 
     props->untie("controls/lighting/nav-lights");
+
+    props->setBoolValue("/sim/controls/radar/", true);
+
 }
 
 double FGAIBase::UpdateRadar(FGAIManager* manager) {
+    bool control = fgGetBool("/sim/controls/radar", true);
+
+    if(!control) return 0;
+
     double radar_range_ft2 = fgGetDouble("/instrumentation/radar/range");
     bool force_on = fgGetBool("/instrumentation/radar/debug-mode", false);
     radar_range_ft2 *= SG_NM_TO_METER * SG_METER_TO_FEET * 1.1; // + 10%
@@ -442,6 +486,12 @@ SGVec3d FGAIBase::getCartPos() const {
     return cartPos;
 }
 
+bool FGAIBase::getGroundElevationM(const SGGeod& pos, double& elev,
+                                   const SGMaterial** material) const {
+    return globals->get_scenery()->get_elevation_m(pos, elev, material,
+                                                   model.get());
+}
+
 double FGAIBase::_getCartPosX() const {
     SGVec3d cartPos = getCartPos();
     return cartPos.x();
@@ -531,6 +581,10 @@ bool FGAIBase::_getCollisionData() {
     return _collision_reported;
 }
 
+bool FGAIBase::_getExpiryData() {
+    return _expiry_reported;
+}
+
 bool FGAIBase::_getImpactData() {
     return _impact_reported;
 }