]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIShip.cxx
Improve timing statistics
[flightgear.git] / src / AIModel / AIShip.cxx
index 8fbb4beb5e75fedd9b56cc68c6430282fdf66afc..9b6a0470524e8fc2b017bc4fd3a412875a91abe0 100644 (file)
 
 FGAIShip::FGAIShip(object_type ot) :
 FGAIBase(ot),
-_limit(40),
+
+
+_waiting(false),
+_new_waypoint(true),
+_tunnel(false),
+_initial_tunnel(false),
+_restart(false),
+_hdg_constant(0.01),
+_limit(100),
 _elevation_m(0),
 _elevation_ft(0),
 _tow_angle(0),
+_missed_count(0),
+_wp_range(0),
 _dt_count(0),
 _next_run(0),
+_roll_constant(0.001),
+_roll_factor(-0.0083335),
+_old_range(0),
+_range_rate(0),
+_missed_time_sec(30),
+_day(86400),
 _lead_angle(0),
 _xtrack_error(0),
-_tunnel(false),
 _curr_alt(0),
 _prev_alt(0),
 _until_time(""),
 _fp_init(false),
-_missed(false),
-_waiting(false),
-_new_waypoint(true),
-_missed_count(0),
-_wait_count(0),
-_missed_time_sec(30),
-_day(86400),
-_wp_range(0),
-_old_range(0),
-_range_rate(0),
-_roll_constant(0.001),
-_hdg_constant(0.01),
-_roll_factor(-0.0083335),
-_restart(false)
-
+_missed(false)
 {
         invisible = false;
 }
@@ -98,6 +99,7 @@ void FGAIShip::readFromScenario(SGPropertyNode* scFileNode) {
     setRudderConstant(scFileNode->getDoubleValue("rudder-constant", 0.5));
     setFixedTurnRadius(scFileNode->getDoubleValue("fixed-turn-radius-ft", 500));
     setSpeedConstant(scFileNode->getDoubleValue("speed-constant", 0.5));
+    setSMPath(scFileNode->getStringValue("submodel-path", ""));
 
     if (!flightplan.empty()) {
         SG_LOG(SG_GENERAL, SG_ALERT, "getting flightplan: " << _name );
@@ -200,6 +202,8 @@ void FGAIShip::bind() {
         SGRawValuePointer<double>(&_fixed_turn_radius));
     props->tie("controls/restart",
         SGRawValuePointer<bool>(&_restart));
+    props->tie("velocities/speed-kts",
+                SGRawValuePointer<double>(&speed));
 }
 
 void FGAIShip::unbind() {
@@ -236,6 +240,7 @@ void FGAIShip::unbind() {
     props->untie("controls/fixed-turn-radius-ft");
     props->untie("controls/constants/speed");
     props->untie("controls/restart");
+    props->untie("velocities/speed-kts");
 
 }
 void FGAIShip::update(double dt) {
@@ -246,12 +251,12 @@ void FGAIShip::update(double dt) {
     // Update the velocity information stored in those nodes.
     // Transform that one to the horizontal local coordinate system.
     SGQuatd ec2hl = SGQuatd::fromLonLat(pos);
-    // The orientation of the carrier wrt the horizontal local frame
+    // The orientation of the ship wrt the horizontal local frame
     SGQuatd hl2body = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
     // and postrotate the orientation of the AIModel wrt the horizontal
     // local frame
     SGQuatd ec2body = ec2hl*hl2body;
-    // The cartesian position of the carrier in the wgs84 world
+    // The cartesian position of the ship in the wgs84 world
     SGVec3d cartPos = SGVec3d::fromGeod(pos);
 
     // The simulation time this transform is meant for
@@ -309,8 +314,7 @@ void FGAIShip::Run(double dt) {
     }
 
     // do not allow unreasonable speeds
-    if (speed > _limit)
-        speed = _limit;
+    SG_CLAMP_RANGE(speed, -_limit * 0.75, _limit);
 
     // convert speed to degrees per second
     speed_north_deg_sec = cos(hdg / SGD_RADIANS_TO_DEGREES)
@@ -337,7 +341,7 @@ void FGAIShip::Run(double dt) {
 
 
     //we assume that at slow speed ships will manoeuvre using engines/bow thruster
-       if(type == "ship" || type == "carrier"){
+       if(type == "ship" || type == "carrier" || type == "escort"){
 
                if (fabs(speed)<=5)
                        _sp_turn_radius_ft = _fixed_turn_radius;
@@ -418,7 +422,7 @@ void FGAIShip::Run(double dt) {
     }
 
     // set the _rudder limit by speed
-    if (type == "ship" || type == "carrier"){
+    if (type == "ship" || type == "carrier" || type == "escort"){
 
         if (speed <= 40)
             rudder_limit = (-0.825 * speed) + 35;
@@ -486,10 +490,6 @@ void FGAIShip::setFlightPlan(FGAIFlightPlan* f) {
     fp = f;
 }
 
-void FGAIShip::setName(const string& n) {
-    _name = n;
-}
-
 void FGAIShip::setStartTime(const string& st) {
     _start_time = st;
 }
@@ -620,6 +620,10 @@ double FGAIShip::getCourse(double lat, double lon, double lat2, double lon2) con
 
 void FGAIShip::ProcessFlightPlan(double dt) {
 
+    if ( dt < 0.00001 ) {
+       return;
+    }
+
     double time_sec = getDaySeconds();
 
     _dt_count += dt;
@@ -677,7 +681,7 @@ void FGAIShip::ProcessFlightPlan(double dt) {
         if (_next_name == "TUNNEL"){
             _tunnel = !_tunnel;
 
-            SG_LOG(SG_GENERAL, SG_ALERT, "AIShip: " << _name << " " << sp_turn_radius_nm );
+            SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " " << sp_turn_radius_nm );
 
             fp->IncrementWaypoint(false);
             next = fp->getNextWaypoint();
@@ -694,7 +698,7 @@ void FGAIShip::ProcessFlightPlan(double dt) {
         }else if(_next_name == "END" || fp->getNextWaypoint() == 0) {
 
             if (_repeat) {
-                SG_LOG(SG_GENERAL, SG_ALERT, "AIShip: "<< _name << " Flightplan repeating ");
+                SG_LOG(SG_GENERAL, SG_INFO, "AIShip: "<< _name << " Flightplan repeating ");
                 fp->restart();
                 prev = curr;
                 curr = fp->getCurrentWaypoint();
@@ -708,7 +712,7 @@ void FGAIShip::ProcessFlightPlan(double dt) {
                 _lead_angle = 0;
                 AccelTo(prev->speed);
             } else if (_restart){
-                SG_LOG(SG_GENERAL, SG_ALERT, "AIShip: " << _name << " Flightplan restarting ");
+                SG_LOG(SG_GENERAL, SG_INFO, "AIShip: " << _name << " Flightplan restarting ");
                 _missed_count = 0;
                 initFlightPlan();
             } else {
@@ -752,7 +756,7 @@ void FGAIShip::ProcessFlightPlan(double dt) {
             _until_time = next->time;
             setUntilTime(next->time);
             if (until_time_sec > time_sec) {
-                SG_LOG(SG_GENERAL, SG_ALERT, "AIShip: " << _name << " "
+                SG_LOG(SG_GENERAL, SG_INFO, "AIShip: " << _name << " "
                     << curr->name << " waiting until: "
                     << _until_time << " " << until_time_sec << " now " << time_sec );
                 setSpeed(0);
@@ -760,7 +764,7 @@ void FGAIShip::ProcessFlightPlan(double dt) {
                 _waiting = true;
                 return;
             } else {
-                SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: "
+                SG_LOG(SG_GENERAL, SG_INFO, "AIShip: "
                     << _name << " wait until done: getting new waypoints ");
                 setUntilTime("");
                 fp->IncrementWaypoint(false);