]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIShip.cxx
properly add librt when clock_gettime is used
[flightgear.git] / src / AIModel / AIShip.cxx
index 8d15fa6d6dccea279ebc18328828f91523f44db7..df0ce649ba8369104c17e83c213cd25a333817a5 100644 (file)
@@ -101,9 +101,10 @@ void FGAIShip::readFromScenario(SGPropertyNode* scFileNode) {
     setFixedTurnRadius(scFileNode->getDoubleValue("fixed-turn-radius-ft", 500));
     setSpeedConstant(scFileNode->getDoubleValue("speed-constant", 0.5));
     setSMPath(scFileNode->getStringValue("submodel-path", ""));
+    setRollFactor(scFileNode->getDoubleValue("roll-factor", 1));
 
     if (!flightplan.empty()) {
-        SG_LOG(SG_GENERAL, SG_ALERT, "getting flightplan: " << _name );
+        SG_LOG(SG_AI, SG_ALERT, "getting flightplan: " << _name );
 
         FGAIFlightPlan* fp = new FGAIFlightPlan(flightplan);
         setFlightPlan(fp);
@@ -112,6 +113,12 @@ void FGAIShip::readFromScenario(SGPropertyNode* scFileNode) {
 }
 
 bool FGAIShip::init(bool search_in_AI_path) {
+    reinit();
+    return FGAIBase::init(search_in_AI_path);
+}
+
+void FGAIShip::reinit()
+{
     prev = 0; // the one behind you
     curr = 0; // the one ahead
     next = 0; // the next plus 1
@@ -133,7 +140,7 @@ bool FGAIShip::init(bool search_in_AI_path) {
     if (fp)
         _fp_init = initFlightPlan();
 
-    return FGAIBase::init(search_in_AI_path);
+    FGAIBase::reinit();
 }
 
 void FGAIShip::bind() {
@@ -245,7 +252,7 @@ void FGAIShip::unbind() {
 
 }
 void FGAIShip::update(double dt) {
-    //SG_LOG(SG_GENERAL, SG_ALERT, "updating Ship: " << _name <<hdg<<pitch<<roll);
+    //SG_LOG(SG_AI, SG_ALERT, "updating Ship: " << _name <<hdg<<pitch<<roll);
     // For computation of rotation speeds we just use finite differences here.
     // That is perfectly valid since this thing is not driven by accelerations
     // but by just apply discrete changes at its velocity variables.
@@ -560,6 +567,10 @@ void FGAIShip::setFixedTurnRadius(double ftr) {
     _fixed_turn_radius = ftr;
 }
 
+void FGAIShip::setRollFactor(double rf) {
+    _roll_factor = rf * -0.0083335;
+}
+
 void FGAIShip::setInitialTunnel(bool t) {
     _initial_tunnel = t;
     setTunnel(_initial_tunnel);
@@ -580,7 +591,7 @@ void FGAIShip::setWPNames() {
         setCurrName(curr->getName());
     else{
         setCurrName("");
-        SG_LOG(SG_GENERAL, SG_ALERT, "AIShip: current wp name error" );
+        SG_LOG(SG_AI, SG_ALERT, "AIShip: current wp name error" );
     }
 
     if (next != 0)
@@ -588,9 +599,9 @@ void FGAIShip::setWPNames() {
     else
         setNextName("");
 
-    SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: prev wp name " << prev->getName());
-    SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: current wp name " << curr->getName());
-    SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: next wp name " << next->getName());
+    SG_LOG(SG_AI, SG_DEBUG, "AIShip: prev wp name " << prev->getName());
+    SG_LOG(SG_AI, SG_DEBUG, "AIShip: current wp name " << curr->getName());
+    SG_LOG(SG_AI, SG_DEBUG, "AIShip: next wp name " << next->getName());
 
 }
 
@@ -612,10 +623,10 @@ double FGAIShip::getCourse(double lat, double lon, double lat2, double lon2) con
     geo_inverse_wgs_84(lat, lon, lat2, lon2, &course, &recip, &distance);
     if (tgt_speed >= 0) {
         return course;
-        SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: course " << course);
+        SG_LOG(SG_AI, SG_DEBUG, "AIShip: course " << course);
     } else {
         return recip;
-        SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: recip " << recip);
+        SG_LOG(SG_AI, SG_DEBUG, "AIShip: recip " << recip);
     }
 }
 
@@ -682,7 +693,7 @@ void FGAIShip::ProcessFlightPlan(double dt) {
         if (_next_name == "TUNNEL"){
             _tunnel = !_tunnel;
 
-            SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " " << sp_turn_radius_nm );
+            SG_LOG(SG_AI, SG_DEBUG, "AIShip: " << _name << " " << sp_turn_radius_nm );
 
             fp->IncrementWaypoint(false);
             next = fp->getNextWaypoint();
@@ -699,7 +710,7 @@ void FGAIShip::ProcessFlightPlan(double dt) {
         }else if(_next_name == "END" || fp->getNextWaypoint() == 0) {
 
             if (_repeat) {
-                SG_LOG(SG_GENERAL, SG_INFO, "AIShip: "<< _name << " Flightplan repeating ");
+                SG_LOG(SG_AI, SG_INFO, "AIShip: "<< _name << " Flightplan repeating ");
                 fp->restart();
                 prev = curr;
                 curr = fp->getCurrentWaypoint();
@@ -713,11 +724,11 @@ void FGAIShip::ProcessFlightPlan(double dt) {
                 _lead_angle = 0;
                 AccelTo(prev->getSpeed());
             } else if (_restart){
-                SG_LOG(SG_GENERAL, SG_INFO, "AIShip: " << _name << " Flightplan restarting ");
+                SG_LOG(SG_AI, SG_INFO, "AIShip: " << _name << " Flightplan restarting ");
                 _missed_count = 0;
                 initFlightPlan();
             } else {
-                SG_LOG(SG_GENERAL, SG_ALERT, "AIShip: " << _name << " Flightplan dying ");
+                SG_LOG(SG_AI, SG_ALERT, "AIShip: " << _name << " Flightplan dying ");
                 setDie(true);
                 _dt_count = 0;
                 return;
@@ -726,7 +737,7 @@ void FGAIShip::ProcessFlightPlan(double dt) {
         } else if (_next_name == "WAIT") {
 
             if (_wait_count < next->getTime_sec()) {
-                SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " waiting ");
+                SG_LOG(SG_AI, SG_DEBUG, "AIShip: " << _name << " waiting ");
                 setSpeed(0);
                 _waiting = true;
                 _wait_count += _dt_count;
@@ -734,7 +745,7 @@ void FGAIShip::ProcessFlightPlan(double dt) {
                 _lead_angle = 0;
                 return;
             } else {
-                SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name
+                SG_LOG(SG_AI, SG_DEBUG, "AIShip: " << _name
                     << " wait done: getting new waypoints ");
                 _waiting = false;
                 _wait_count = 0;
@@ -757,7 +768,7 @@ void FGAIShip::ProcessFlightPlan(double dt) {
             _until_time = next->getTime();
             setUntilTime(next->getTime());
             if (until_time_sec > time_sec) {
-                SG_LOG(SG_GENERAL, SG_INFO, "AIShip: " << _name << " "
+                SG_LOG(SG_AI, SG_INFO, "AIShip: " << _name << " "
                     << curr->getName() << " waiting until: "
                     << _until_time << " " << until_time_sec << " now " << time_sec );
                 setSpeed(0);
@@ -765,7 +776,7 @@ void FGAIShip::ProcessFlightPlan(double dt) {
                 _waiting = true;
                 return;
             } else {
-                SG_LOG(SG_GENERAL, SG_INFO, "AIShip: "
+                SG_LOG(SG_AI, SG_INFO, "AIShip: "
                     << _name << " wait until done: getting new waypoints ");
                 setUntilTime("");
                 fp->IncrementWaypoint(false);
@@ -787,7 +798,7 @@ void FGAIShip::ProcessFlightPlan(double dt) {
 
         } else {
             //now reorganise the waypoints, so that next becomes current and so on
-            SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " getting new waypoints ");
+            SG_LOG(SG_AI, SG_DEBUG, "AIShip: " << _name << " getting new waypoints ");
             fp->IncrementWaypoint(false);
             prev = fp->getPreviousWaypoint(); //first waypoint
             curr = fp->getCurrentWaypoint();  //second waypoint
@@ -820,14 +831,14 @@ void FGAIShip::ProcessFlightPlan(double dt) {
     if (finite(_course))
         TurnTo(_course);
     else
-        SG_LOG(SG_GENERAL, SG_ALERT, "AIShip: Bearing or Range is not a finite number");
+        SG_LOG(SG_AI, SG_ALERT, "AIShip: Bearing or Range is not a finite number");
 
     _dt_count = 0;
 } // end Processing FlightPlan
 
 bool FGAIShip::initFlightPlan() {
 
-    SG_LOG(SG_GENERAL, SG_ALERT, "AIShip: " << _name << " initializing waypoints ");
+    SG_LOG(SG_AI, SG_ALERT, "AIShip: " << _name << " initializing waypoints ");
 
     bool init = false;
     _start_sec = 0;
@@ -841,7 +852,7 @@ bool FGAIShip::initFlightPlan() {
     next = fp->getNextWaypoint();     //third waypoint (might not exist!)
 
     while (curr->getName() == "WAIT" || curr->getName() == "WAITUNTIL") {  // don't wait when initialising
-        SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " re-initializing waypoints ");
+        SG_LOG(SG_AI, SG_DEBUG, "AIShip: " << _name << " re-initializing waypoints ");
         fp->IncrementWaypoint(false);
         curr = fp->getCurrentWaypoint();
         next = fp->getNextWaypoint();
@@ -889,7 +900,7 @@ bool FGAIShip::initFlightPlan() {
     _missed_count = 0;
     _new_waypoint = true;
 
-    SG_LOG(SG_GENERAL, SG_ALERT, "AIShip: " << _name << " done initialising waypoints " << _tunnel);
+    SG_LOG(SG_AI, SG_ALERT, "AIShip: " << _name << " done initialising waypoints " << _tunnel);
     if (prev)
         init = true;