]> git.mxchange.org Git - flightgear.git/commitdiff
Enable Ballistic objects to be slaved to any AI Object.
authorVivian Meazza <vivian.meazza@lineone.net>
Wed, 8 Sep 2010 16:34:17 +0000 (17:34 +0100)
committerAnders Gidenstam <anders@gidenstam.org>
Fri, 17 Sep 2010 19:06:35 +0000 (21:06 +0200)
Signed-off-by: Vivian Meazza <vivian.meazza@lineone.net>
src/AIModel/AIBallistic.cxx
src/AIModel/AIBallistic.hxx

index 2f5bb4f6f7db07dd5d1cb364069ebcfc0663c392..1ea0e89b51c243f45c29cda0ffa680c16c732bcc 100644 (file)
@@ -121,6 +121,7 @@ void FGAIBallistic::readFromScenario(SGPropertyNode* scFileNode) {
     setSlaved(scFileNode->getBoolValue("slaved", false));
     setSlavedLoad(scFileNode->getBoolValue("slaved-load", false));
     setContentsPath(scFileNode->getStringValue("contents"));
+    setParentName(scFileNode->getStringValue("parent"));
 }
 
 bool FGAIBallistic::init(bool search_in_AI_path) {
@@ -151,6 +152,11 @@ bool FGAIBallistic::init(bool search_in_AI_path) {
         props->setStringValue("contents/path", _contents_path.c_str());
     }
 
+    if(_parent != ""){
+        setParentNode();
+    }
+
+    setParentNodes(_selected_ac);
     //props->setStringValue("vector/path", _vector_path.c_str());
 
     // start with high value so that animations don't trigger yet
@@ -443,7 +449,8 @@ void FGAIBallistic::setContentsNode(SGPropertyNode_ptr node) {
     }
 }
 
-void FGAIBallistic::setParentNode(SGPropertyNode_ptr node) {
+void FGAIBallistic::setParentNodes(SGPropertyNode_ptr node) {
+
     if (node != 0) {
         _pnode = node;
         _p_pos_node = _pnode->getChild("position", 0, true);
@@ -458,11 +465,12 @@ void FGAIBallistic::setParentNode(SGPropertyNode_ptr node) {
 
         _p_vel_node = _pnode->getChild("velocities", 0, true);
         _p_spd_node = _p_vel_node->getChild("true-airspeed-kt", 0, true);
-
     }
+
 }
 
 void FGAIBallistic::setParentPos() {
+
     if (_pnode != 0) {
         double lat = _p_lat_node->getDoubleValue();
         double lon = _p_lon_node->getDoubleValue();
@@ -471,8 +479,8 @@ void FGAIBallistic::setParentPos() {
         _parentpos.setLongitudeDeg(lon);
         _parentpos.setLatitudeDeg(lat);
         _parentpos.setElevationFt(alt);
-
     }
+
 }
 
 bool FGAIBallistic::getSlaved() const {
@@ -1140,12 +1148,24 @@ void FGAIBallistic::setTgtOffsets(double dt, double coeff){
 
 void FGAIBallistic::formateToAC(double dt){
 
+    double hdg, pch, rll = 0;
+
     setTgtOffsets(dt, 25);
-    setOffsetPos(userpos,
-            manager->get_user_heading(),
-            manager->get_user_pitch(), 
-            manager->get_user_roll()
-            );
+
+    if (_pnode != 0) {
+        setParentPos();
+        hdg = _p_hdg_node->getDoubleValue();
+        pch = _p_pch_node->getDoubleValue();
+        rll = _p_rll_node->getDoubleValue();
+        setOffsetPos(_parentpos, hdg, pch, rll);
+        setSpeed(_p_spd_node->getDoubleValue());
+    }else {
+        hdg = manager->get_user_heading();
+        pch = manager->get_user_pitch();
+        rll = manager->get_user_roll();
+        setOffsetPos(userpos, hdg, pch, rll);
+        setSpeed(manager->get_user_speed());
+    }
 
     // elapsed time has a random initialisation so that each 
     // wingman moves differently
index 91a50acbd17ec298920bf2282ec42eb4e5a8b20d..a9566221fc4620ccfccb4943453aea48b7af591c 100644 (file)
@@ -92,7 +92,7 @@ public:
     void setBnk(double r, double dt, double c);
     void setHt(double h, double dt, double c);
     void setFormate(bool f);
-    void setParentNode(const SGPropertyNode_ptr);
+    void setParentNodes(const SGPropertyNode_ptr);
     void setParentPos();
 
     double _getTime() const;