]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIBase.cxx
fix a segmentation fault situation that is exposed at least on IRIX (but not Linux).
[flightgear.git] / src / AIModel / AIBase.cxx
index dc48ca2b9f8ecabfe6d6051a635e015adccf10fb..057f3bc84791f022a6502c3a0b232ebe40074ad5 100644 (file)
 #include "AIBase.hxx"
 #include "AIManager.hxx"
 
-FGAIBase::FGAIBase() {
+
+const double FGAIBase::rho = 0.023780;  // sea level air density slugs/ft3
+const double FGAIBase::lbs_to_slugs = 0.031080950172;   //conversion factor
+
+
+FGAIBase::FGAIBase()
+ :  fp( NULL ),
+    model( NULL ),
+    props( NULL ),
+    manager( NULL )
+{
     _type_str = "model";
     tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0;
     bearing = elevation = range = rdot = 0.0;
@@ -51,11 +61,11 @@ FGAIBase::FGAIBase() {
     in_range = false;
     invisible = true;
     no_roll = true;
+    life = 900;
     model_path = "";
-    model = 0;
     _otype = otNull;
     index = 0;
-    fp = (FGAIFlightPlan*)0;
+    delete_me = false;
 }
 
 FGAIBase::~FGAIBase() {
@@ -64,6 +74,7 @@ FGAIBase::~FGAIBase() {
     SGPropertyNode *root = globals->get_props()->getNode("ai/models", true);
     root->removeChild(_type_str.c_str(), index);
     if (fp) delete fp;
+    fp = NULL;
 }
 
 void FGAIBase::update(double dt) {
@@ -88,8 +99,10 @@ void FGAIBase::Transform() {
 bool FGAIBase::init() {
 
    SGPropertyNode *root = globals->get_props()->getNode("ai/models", true);
+
    index = manager->getNum(_otype) - 1;
    props = root->getNode(_type_str.c_str(), index, true);
+
    if (model_path != "") {
       model = sgLoad3DModel( globals->get_fg_root(),
                             model_path.c_str(),
@@ -119,7 +132,8 @@ bool FGAIBase::isa( object_type otype ) {
 
 
 void FGAIBase::bind() {
-   props->tie("id", SGRawValuePointer<int>(&id));
+   props->tie("id", SGRawValueMethods<FGAIBase,int>(*this,
+                                         &FGAIBase::_getID));
    props->tie("velocities/true-airspeed-kt",  SGRawValuePointer<double>(&speed));
    props->tie("velocities/vertical-speed-fps",
                SGRawValueMethods<FGAIBase,double>(*this,
@@ -308,3 +322,6 @@ bool FGAIBase::_isNight() {
     return (fgGetFloat("/sim/time/sun-angle-rad") > 1.57);
 }
 
+int FGAIBase::_getID() const {
+    return (int)(this);
+}