]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AICarrier.cxx
Reduce amount of log output at level=debug.
[flightgear.git] / src / AIModel / AICarrier.cxx
index a0dc5effdab0450e86dada91da9b3ff2f5c6a78f..fae5d26bc38b91b76ee9028d99b8d091a117ca78 100644 (file)
 #include <vector>
 
 #include <simgear/sg_inlines.h>
-#include <simgear/math/SGMath.hxx>
 #include <simgear/math/sg_geodesy.hxx>
 
 #include <math.h>
 #include <Main/util.hxx>
-#include <Main/viewer.hxx>
 
 #include "AICarrier.hxx"
 
@@ -57,6 +55,9 @@ void FGAICarrier::readFromScenario(SGPropertyNode* scFileNode) {
   setMaxLong(scFileNode->getDoubleValue("max-long", 0));
   setMinLong(scFileNode->getDoubleValue("min-long", 0));
   setMPControl(scFileNode->getBoolValue("mp-control", false));
+  setAIControl(scFileNode->getBoolValue("ai-control", false));
+  setCallSign(scFileNode->getStringValue("callsign", ""));
+
 
   SGPropertyNode* flols = scFileNode->getChild("flols-pos");
   if (flols) {
@@ -72,7 +73,7 @@ void FGAICarrier::readFromScenario(SGPropertyNode* scFileNode) {
   std::vector<SGPropertyNode_ptr> props = scFileNode->getChildren("parking-pos");
   std::vector<SGPropertyNode_ptr>::const_iterator it;
   for (it = props.begin(); it != props.end(); ++it) {
-    string name = (*it)->getStringValue("name", "unnamed");
+    const string name = (*it)->getStringValue("name", "unnamed");
     // Transform to the right coordinate frame, configuration is done in
     // the usual x-back, y-right, z-up coordinates, computations
     // in the simulation usual body x-forward, y-right, z-down coordinates
@@ -121,21 +122,25 @@ void FGAICarrier::setMPControl(bool c) {
     MPControl = c;
 }
 
+void FGAICarrier::setAIControl(bool c) {
+    AIControl = c;
+}
+
 void FGAICarrier::update(double dt) {
     // Now update the position and heading. This will compute new hdg and
     // roll values required for the rotation speed computation.
     FGAIShip::update(dt);
 
     //automatic turn into wind with a target wind of 25 kts otd
-    //SG_LOG(SG_GENERAL, SG_ALERT, "AICarrier: MPControl " << MPControl );
-    if (!MPControl){
+    //SG_LOG(SG_AI, SG_ALERT, "AICarrier: MPControl " << MPControl << " AIControl " << AIControl);
+    if (!MPControl && AIControl){
 
         if(turn_to_launch_hdg){
             TurnToLaunch();
         } else if(turn_to_recovery_hdg ){
             TurnToRecover();
-        } else if(OutsideBox() || returning ) {// check that the carrier is inside 
-            ReturnToBox();                     // the operating box,  
+        } else if(OutsideBox() || returning ) {// check that the carrier is inside
+            ReturnToBox();                     // the operating box,
         } else {
             TurnToBase();
         }
@@ -160,7 +165,7 @@ void FGAICarrier::update(double dt) {
     SGVec3d cartPos = SGVec3d::fromGeod(pos);
 
     // The position of the eyepoint - at least near that ...
-    SGVec3d eyePos(globals->get_current_view()->get_view_pos());
+    SGVec3d eyePos(globals->get_view_position_cart());
     // Add the position offset of the AIModel to gain the earth
     // centered position
     SGVec3d eyeWrtCarrier = eyePos - cartPos;
@@ -168,10 +173,10 @@ void FGAICarrier::update(double dt) {
     eyeWrtCarrier = ec2body.transform(eyeWrtCarrier);
     // the eyepoints vector wrt the flols position
     SGVec3d eyeWrtFlols = eyeWrtCarrier - flols_off;
-    
+
     // the distance from the eyepoint to the flols
     dist = norm(eyeWrtFlols);
-    
+
     // now the angle, positive angles are upwards
     if (fabs(dist) < SGLimits<float>::min()) {
       angle = 0;
@@ -180,7 +185,7 @@ void FGAICarrier::update(double dt) {
       sAngle = SGMiscd::min(1, SGMiscd::max(-1, sAngle));
       angle = SGMiscd::rad2deg(asin(sAngle));
     }
-    
+
     // set the value of source
     if ( angle <= 4.35 && angle > 4.01 )
       source = 1;
@@ -240,64 +245,63 @@ void FGAICarrier::bind() {
 
     props->untie("velocities/true-airspeed-kt");
 
-    props->tie("controls/flols/source-lights",
-                SGRawValuePointer<int>(&source));
-    props->tie("controls/flols/distance-m",
-                SGRawValuePointer<double>(&dist));
-    props->tie("controls/flols/angle-degs",
-                SGRawValuePointer<double>(&angle));
-    props->tie("controls/turn-to-launch-hdg",
-                SGRawValuePointer<bool>(&turn_to_launch_hdg));
-    props->tie("controls/in-to-wind",
-                SGRawValuePointer<bool>(&turn_to_launch_hdg));
-    props->tie("controls/base-course-deg",
-                SGRawValuePointer<double>(&base_course));
-    props->tie("controls/base-speed-kts",
-                SGRawValuePointer<double>(&base_speed));
-    props->tie("controls/start-pos-lat-deg",
-               SGRawValueMethods<SGGeod,double>(pos, &SGGeod::getLatitudeDeg));
-    props->tie("controls/start-pos-long-deg",
-               SGRawValueMethods<SGGeod,double>(pos, &SGGeod::getLongitudeDeg));
-    props->tie("controls/mp-control",
+    tie("controls/flols/source-lights",
+        SGRawValuePointer<int>(&source));
+    tie("controls/flols/distance-m",
+        SGRawValuePointer<double>(&dist));
+    tie("controls/flols/angle-degs",
+        SGRawValuePointer<double>(&angle));
+    tie("controls/turn-to-launch-hdg",
+        SGRawValuePointer<bool>(&turn_to_launch_hdg));
+    tie("controls/in-to-wind",
+        SGRawValuePointer<bool>(&turn_to_launch_hdg));
+    tie("controls/base-course-deg",
+        SGRawValuePointer<double>(&base_course));
+    tie("controls/base-speed-kts",
+        SGRawValuePointer<double>(&base_speed));
+    tie("controls/start-pos-lat-deg",
+        SGRawValueMethods<SGGeod,double>(pos, &SGGeod::getLatitudeDeg));
+    tie("controls/start-pos-long-deg",
+        SGRawValueMethods<SGGeod,double>(pos, &SGGeod::getLongitudeDeg));
+    tie("controls/mp-control",
         SGRawValuePointer<bool>(&MPControl));
-    props->tie("velocities/speed-kts",
-                SGRawValuePointer<double>(&speed));
-    props->tie("environment/surface-wind-speed-true-kts",
-                SGRawValuePointer<double>(&wind_speed_kts));
-    props->tie("environment/surface-wind-from-true-degs",
-                SGRawValuePointer<double>(&wind_from_deg));
-    props->tie("environment/rel-wind-from-degs",
-                SGRawValuePointer<double>(&rel_wind_from_deg));
-    props->tie("environment/rel-wind-from-carrier-hdg-degs",
-                SGRawValuePointer<double>(&rel_wind));
-    props->tie("environment/rel-wind-speed-kts",
-                SGRawValuePointer<double>(&rel_wind_speed_kts));
-    props->tie("environment/in-to-wind",
+    tie("controls/ai-control",
+        SGRawValuePointer<bool>(&AIControl));
+    tie("environment/surface-wind-speed-true-kts",
+        SGRawValuePointer<double>(&wind_speed_kts));
+    tie("environment/surface-wind-from-true-degs",
+        SGRawValuePointer<double>(&wind_from_deg));
+    tie("environment/rel-wind-from-degs",
+        SGRawValuePointer<double>(&rel_wind_from_deg));
+    tie("environment/rel-wind-from-carrier-hdg-degs",
+        SGRawValuePointer<double>(&rel_wind));
+    tie("environment/rel-wind-speed-kts",
+        SGRawValuePointer<double>(&rel_wind_speed_kts));
+    tie("environment/in-to-wind",
         SGRawValuePointer<bool>(&in_to_wind));
-    //props->tie("controls/flols/wave-off-lights",
-    //            SGRawValuePointer<bool>(&wave_off_lights));
-    props->tie("controls/elevators",
-                SGRawValuePointer<bool>(&elevators));
-    props->tie("surface-positions/elevators-pos-norm",
-                SGRawValuePointer<double>(&pos_norm));
-    props->tie("controls/constants/elevators/trans-time-s",
-                SGRawValuePointer<double>(&transition_time));
-    props->tie("controls/constants/elevators/time-constant",
-                SGRawValuePointer<double>(&time_constant));
-    props->tie("controls/jbd",
+    //tie("controls/flols/wave-off-lights",
+    //    SGRawValuePointer<bool>(&wave_off_lights));
+    tie("controls/elevators",
+        SGRawValuePointer<bool>(&elevators));
+    tie("surface-positions/elevators-pos-norm",
+        SGRawValuePointer<double>(&pos_norm));
+    tie("controls/constants/elevators/trans-time-s",
+        SGRawValuePointer<double>(&transition_time));
+    tie("controls/constants/elevators/time-constant",
+        SGRawValuePointer<double>(&time_constant));
+    tie("controls/jbd",
         SGRawValuePointer<bool>(&jbd));
-    props->tie("surface-positions/jbd-pos-norm",
+    tie("surface-positions/jbd-pos-norm",
         SGRawValuePointer<double>(&jbd_pos_norm));
-    props->tie("controls/constants/jbd/trans-time-s",
+    tie("controls/constants/jbd/trans-time-s",
         SGRawValuePointer<double>(&jbd_transition_time));
-    props->tie("controls/constants/jbd/time-constant",
+    tie("controls/constants/jbd/time-constant",
         SGRawValuePointer<double>(&jbd_time_constant));
-    props->tie("controls/turn-to-recovery-hdg",
+    tie("controls/turn-to-recovery-hdg",
         SGRawValuePointer<bool>(&turn_to_recovery_hdg));
-    props->tie("controls/turn-to-base-course",
+    tie("controls/turn-to-base-course",
         SGRawValuePointer<bool>(&turn_to_base_course));
 
-
     props->setBoolValue("controls/flols/cut-lights", false);
     props->setBoolValue("controls/flols/wave-off-lights", false);
     props->setBoolValue("controls/flols/cond-datum-lights", true);
@@ -308,36 +312,6 @@ void FGAICarrier::bind() {
     props->setDoubleValue("controls/lighting/flood-lights-red-norm", 0);
 }
 
-
-void FGAICarrier::unbind() {
-    FGAIShip::unbind();
-
-    props->untie("velocities/true-airspeed-kt");
-    props->untie("controls/flols/source-lights");
-    props->untie("controls/flols/distance-m");
-    props->untie("controls/flols/angle-degs");
-    props->untie("controls/turn-to-launch-hdg");
-    props->untie("velocities/speed-kts");
-    props->untie("environment/wind-speed-true-kts");
-    props->untie("environment/wind-from-true-degs");
-    props->untie("environment/rel-wind-from-degs");
-    props->untie("environment/rel-wind-speed-kts");
-    props->untie("environment/in-to-wind");
-    //props->untie("controls/flols/wave-off-lights");
-    props->untie("controls/elevators");
-    props->untie("surface-positions/elevators-pos-norm");
-    props->untie("controls/constants/elevators/trans-time-secs");
-    props->untie("controls/constants/elevators/time-constant");
-    props->untie("controls/jbd");
-    props->untie("surface-positions/jbd/pos-norm");
-    props->untie("controls/constants/jbd/trans-time-s");
-    props->untie("controls/jbd-time-constant");
-    props->untie("controls/mp-control");
-    props->untie("controls/turn-to-recovery-hdg");
-    props->untie("controls/turn-to-base-course");
-}
-
-
 bool FGAICarrier::getParkPosition(const string& id, SGGeod& geodPos,
                                   double& hdng, SGVec3d& uvw)
 {
@@ -436,12 +410,12 @@ void FGAICarrier::TurnToRecover(){
     if (wind_speed_kts < 3){
         tgt_heading = base_course + 60;
     } else if (rel_wind < -9 && rel_wind >= -180){
-        tgt_heading = wind_from_deg; 
+        tgt_heading = wind_from_deg;
     } else if (rel_wind > -7 && rel_wind < 45){
         tgt_heading = wind_from_deg + 60;
     } else if (rel_wind >=45 && rel_wind < 180){
         tgt_heading = wind_from_deg + 45;
-    } else 
+    } else
         tgt_heading = hdg;
 
     SG_NORMALIZE_RANGE(tgt_heading, 0.0, 360.0);
@@ -489,7 +463,7 @@ void FGAICarrier::ReturnToBox(){
 bool FGAICarrier::OutsideBox() { //returns true if the carrier is outside operating box
 
     if ( max_lat == 0 && min_lat == 0 && max_long == 0 && min_long == 0) {
-        SG_LOG(SG_GENERAL, SG_DEBUG, "AICarrier: No Operating Box defined" );
+        SG_LOG(SG_AI, SG_DEBUG, "AICarrier: No Operating Box defined" );
         return false;
     }
 
@@ -523,7 +497,6 @@ bool FGAICarrier::OutsideBox() { //returns true if the carrier is outside operat
             return true;
     }
 
-    SG_LOG(SG_GENERAL, SG_DEBUG, "AICarrier: Inside Operating Box" );
     return false;
 
 } // end OutsideBox
@@ -575,7 +548,7 @@ void FGAICarrier::UpdateElevator(double dt, double transition_time) {
 
 void FGAICarrier::UpdateJBD(double dt, double jbd_transition_time) {
 
-    string launchbar_state = _launchbar_state_node->getStringValue();
+    const string launchbar_state = _launchbar_state_node->getStringValue();
     double step = 0;
 
     if (launchbar_state == "Engaged"){