]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIMultiplayer.cxx
Make the vertical acceleration rate scale with vertical performance. The
[flightgear.git] / src / AIModel / AIMultiplayer.cxx
index 023ba185c5a70067e6af22a59366caf2e9c0b165..e7a3abd47eaad07591e9d7662dc27c75930c00ab 100755 (executable)
@@ -19,7 +19,7 @@
 //
 // 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.
 
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
@@ -44,12 +44,28 @@ FGAIMultiplayer::~FGAIMultiplayer() {
 }
 
 bool FGAIMultiplayer::init() {
+    //refuel_node = fgGetNode("systems/refuel/contact", true);
+    isTanker = false; // do this until this property is
+                      // passed over the net
+
+    string str1 = mCallSign;
+    string str2 = "MOBIL";
+
+    unsigned int loc1= str1.find( str2, 0 );
+    if ( (loc1 != string::npos && str2 != "") ){
+        //        cout << " string found "     << str2 << " in " << str1 << endl;
+        isTanker = true;
+        //        cout << "isTanker " << isTanker << " " << mCallSign <<endl;
+    }
    return FGAIBase::init();
 }
 
 void FGAIMultiplayer::bind() {
     FGAIBase::bind();
 
+    props->tie("refuel/contact", SGRawValuePointer<bool>(&contact));
+    props->setBoolValue("tanker",isTanker);
+
 #define AIMPROProp(type, name) \
 SGRawValueMethods<FGAIMultiplayer, type>(*this, &FGAIMultiplayer::get##name)
 
@@ -64,6 +80,7 @@ SGRawValueMethods<FGAIMultiplayer, type>(*this, \
     props->tie("controls/lag-adjust-system-speed",
                AIMPRWProp(double, LagAdjustSystemSpeed));
 
+
 #undef AIMPROProp
 #undef AIMPRWProp
 }
@@ -74,6 +91,7 @@ void FGAIMultiplayer::unbind() {
     props->untie("callsign");
     props->untie("controls/allow-extrapolation");
     props->untie("controls/lag-adjust-system-speed");
+    props->untie("refuel/contact");
 }
 
 void FGAIMultiplayer::update(double dt)
@@ -154,6 +172,7 @@ void FGAIMultiplayer::update(double dt)
 
   SGVec3d ecPos;
   SGQuatf ecOrient;
+
   if (tInterp <= curentPkgTime) {
     // Ok, we need a time prevous to the last available packet,
     // that is good ...
@@ -166,6 +185,7 @@ void FGAIMultiplayer::update(double dt)
       MotionInfo::iterator firstIt = mMotionInfo.begin();
       ecPos = firstIt->second.position;
       ecOrient = firstIt->second.orientation;
+      speed = norm(firstIt->second.linearVel) * SG_METER_TO_NM * 3600.0;
 
       std::vector<FGFloatPropertyData>::const_iterator firstPropIt;
       std::vector<FGFloatPropertyData>::const_iterator firstPropItEnd;
@@ -199,6 +219,8 @@ void FGAIMultiplayer::update(double dt)
       ecPos = ((1-tau)*prevIt->second.position + tau*nextIt->second.position);
       ecOrient = interpolate((float)tau, prevIt->second.orientation,
                              nextIt->second.orientation);
+      speed = norm((1-tau)*prevIt->second.linearVel
+                   + tau*nextIt->second.linearVel) * SG_METER_TO_NM * 3600.0;
 
       if (prevIt->second.properties.size()
           == nextIt->second.properties.size()) {
@@ -259,6 +281,8 @@ void FGAIMultiplayer::update(double dt)
       t -= h;
     }
 
+    speed = norm(linearVel) * SG_METER_TO_NM * 3600.0;
+
     std::vector<FGFloatPropertyData>::const_iterator firstPropIt;
     std::vector<FGFloatPropertyData>::const_iterator firstPropItEnd;
     firstPropIt = it->second.properties.begin();
@@ -273,15 +297,13 @@ void FGAIMultiplayer::update(double dt)
   }
   
   // extract the position
-  SGGeod geod = ecPos;
-  pos.setlat(geod.getLatitudeDeg());
-  pos.setlon(geod.getLongitudeDeg());
-  pos.setelev(geod.getElevationM());
-  
+  pos = SGGeod::fromCart(ecPos);
+  altitude_ft = pos.getElevationFt();
+
   // The quaternion rotating from the earth centered frame to the
   // horizontal local frame
-  SGQuatf qEc2Hl = SGQuatf::fromLonLat((float)geod.getLongitudeRad(),
-                                       (float)geod.getLatitudeRad());
+  SGQuatf qEc2Hl = SGQuatf::fromLonLatRad((float)pos.getLongitudeRad(),
+                                          (float)pos.getLatitudeRad());
   // The orientation wrt the horizontal local frame
   SGQuatf hlOr = conj(qEc2Hl)*ecOrient;
   float hDeg, pDeg, rDeg;
@@ -291,12 +313,31 @@ void FGAIMultiplayer::update(double dt)
   pitch = pDeg;
 
   SG_LOG(SG_GENERAL, SG_DEBUG, "Multiplayer position and orientation: "
-         << geod << ", " << hlOr);
+         << ecPos << ", " << hlOr);
 
   //###########################//
   // do calculations for radar //
   //###########################//
-  UpdateRadar(manager);
+    double range_ft2 = UpdateRadar(manager);
+
+    //************************************//
+    // Tanker code                        //
+    //************************************//
+
+
+    if ( isTanker) {
+        if ( (range_ft2 < 250.0 * 250.0) &&
+            (y_shift > 0.0)    &&
+            (elevation > 0.0) ){
+                // refuel_node->setBoolValue(true);
+            contact = true;
+        } else {
+            // refuel_node->setBoolValue(false);
+            contact = false;
+        }
+    } else {
+        contact = false;
+    }
 
   Transform();
 }