]> git.mxchange.org Git - flightgear.git/commitdiff
David Culp:
authorehofman <ehofman>
Sat, 4 Jun 2005 09:38:52 +0000 (09:38 +0000)
committerehofman <ehofman>
Sat, 4 Jun 2005 09:38:52 +0000 (09:38 +0000)
I added an AIStatic object to my OV-10 sim for use in putting city signs,
vehicles, or anything else that will be static, but that I don't want to put
in the scenery files.  It's inexpensive.  Before, I was making such things
from AIShip.

I also added the ability to set flight plans to repeat, so that when an
airplane reaches the end it just starts over at the beginning.  This is
useful for my OV-10 sim.  I have C-141 and KC-135 traffic flying approaches
to Ramstein, and I only have to define two AI objects to do this.

Also, I found an inefficiency in AIBase, where every AI object was calculating
Mach number at every dt.  Now only AIBallistic objects do this.

src/AIModel/AIAircraft.cxx
src/AIModel/AIAircraft.hxx
src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx
src/AIModel/AIFlightPlan.cxx
src/AIModel/AIFlightPlan.hxx
src/AIModel/AIManager.cxx
src/AIModel/AIManager.hxx
src/AIModel/AIStatic.cxx [new file with mode: 0644]
src/AIModel/AIStatic.hxx [new file with mode: 0644]
src/AIModel/Makefile.am

index 3c73b78258e4064496b99eb020ff80aa5a626738..efe563057f06e9b1ad57d2bbca2e8f1cdf23b267 100644 (file)
@@ -584,7 +584,12 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now )
     // Current waypoint's elevation according to Terrain Elevation
     if (curr->finished) {  //end of the flight plan
       {
-       setDie(true);
+         if (fp->getRepeat()) {
+           fp->restart();
+         } else {   
+         setDie(true);
+         } 
+
        //cerr << "Done die end of fp" << endl;
       }
       return;
index ad1c7dae1002504f270c163800911e8e50c58bd9..022572563bdc9fc641b989e1880ee225c92ae738 100644 (file)
@@ -61,6 +61,7 @@ public:
 
         void SetPerformance(const PERF_STRUCT *ps);
         void SetFlightPlan(FGAIFlightPlan *f);
+        FGAIFlightPlan* GetFlightPlan() { return fp; };
         void AccelTo(double speed);
         void PitchTo(double angle);
         void RollTo(double angle);
index 8a618ab2def98ddfe6057b6f10a3c516ac87db0d..d66de0300d9ef08bec26c5719f66012ea7496798 100644 (file)
@@ -81,41 +81,11 @@ FGAIBase::~FGAIBase() {
 }
 
 void FGAIBase::update(double dt) {
+    if (_otype == otStatic) return;
+    if (_otype == otBallistic) CalculateMach();
+
     ft_per_deg_lat = 366468.96 - 3717.12 * cos(pos.lat()*SGD_DEGREES_TO_RADIANS);
     ft_per_deg_lon = 365228.16 * cos(pos.lat()*SGD_DEGREES_TO_RADIANS);
-
-    // Calculate rho at altitude, using standard atmosphere
-    // For the temperature T and the pressure p,
-
-    if (altitude < 36152) {            // curve fits for the troposphere
-      T = 59 - 0.00356 * altitude;
-      p = 2116 * pow( ((T + 459.7) / 518.6) , 5.256);
-
-    } else if ( 36152 < altitude && altitude < 82345 ) {    // lower stratosphere
-      T = -70;
-      p = 473.1 * pow( e , 1.73 - (0.000048 * altitude) );
-
-    } else {                                    //  upper stratosphere
-      T = -205.05 + (0.00164 * altitude);
-      p = 51.97 * pow( ((T + 459.7) / 389.98) , -11.388);
-    }
-
-    rho = p / (1718 * (T + 459.7));
-       
-       // calculate the speed of sound at altitude
-       // a = sqrt ( g * R * (T + 459.7))
-       // where:
-       // a = speed of sound [ft/s]
-       // g = specific heat ratio, which is usually equal to 1.4  
-       // R = specific gas constant, which equals 1716 ft-lb/slug/°R 
-       
-       a = sqrt ( 1.4 * 1716 * (T + 459.7));
-       
-       // calculate Mach number
-       
-       Mach = speed/a;
-       
-//     cout  << "Speed(ft/s) "<< speed <<" Altitude(ft) "<< altitude << " Mach " << Mach;
 }
 
 void FGAIBase::Transform() {
@@ -393,3 +363,39 @@ bool FGAIBase::_isNight() {
 int FGAIBase::_getID() const {
     return (int)(this);
 }
+
+void FGAIBase::CalculateMach() {
+     // Calculate rho at altitude, using standard atmosphere
+     // For the temperature T and the pressure p,
+     if (altitude < 36152) {           // curve fits for the troposphere
+       T = 59 - 0.00356 * altitude;
+       p = 2116 * pow( ((T + 459.7) / 518.6) , 5.256);
+     } else if ( 36152 < altitude && altitude < 82345 ) {    // lower stratosphere
+       T = -70;
+       p = 473.1 * pow( e , 1.73 - (0.000048 * altitude) );
+     } else {                                    //  upper stratosphere
+       T = -205.05 + (0.00164 * altitude);
+       p = 51.97 * pow( ((T + 459.7) / 389.98) , -11.388);
+     }
+     rho = p / (1718 * (T + 459.7));
+       
+       // calculate the speed of sound at altitude
+       // a = sqrt ( g * R * (T + 459.7))
+       // where:
+       // a = speed of sound [ft/s]
+       // g = specific heat ratio, which is usually equal to 1.4  
+       // R = specific gas constant, which equals 1716 ft-lb/slug/°R 
+       
+       a = sqrt ( 1.4 * 1716 * (T + 459.7));
+       
+       // calculate Mach number
+       
+       Mach = speed/a;
+       
+ //    cout  << "Speed(ft/s) "<< speed <<" Altitude(ft) "<< altitude << " Mach " << Mach;
+}
+
index 88c6bde7c4d9b1068153878c05ee7f234a84d493..14467a2366066af68bb26a26df87867e0a9f5305 100644 (file)
@@ -40,7 +40,7 @@ class FGAIFlightPlan;
 typedef struct {
    string callsign;
 
-   // can be aircraft, ship, storm, thermal or ballistic
+   // can be aircraft, ship, storm, thermal, static or ballistic
    string m_type;
    string m_class;
    string path;
@@ -93,7 +93,7 @@ public:
     inline Point3D GetPos() { return(pos); }
 
     enum object_type { otNull = 0, otAircraft, otShip, otCarrier, otBallistic,
-                       otRocket, otStorm, otThermal, 
+                       otRocket, otStorm, otThermal, otStatic,
                        MAX_OBJECTS };  // Needs to be last!!!
 
     virtual bool init();
@@ -167,7 +167,7 @@ protected:
     FGAIFlightPlan *fp;
 
     void Transform();
-
+    void CalculateMach();
     double UpdateRadar(FGAIManager* manager);
 
     string _type_str;
index 19321f2bfd7c24746601ffb1624bc2b4bb929d53..025f03e2141429211b372fa530605e300cb44a08 100644 (file)
@@ -50,6 +50,7 @@ FGAIFlightPlan::FGAIFlightPlan(string filename)
   SGPath path( globals->get_fg_root() );
   path.append( ("/Data/AI/FlightPlans/" + filename).c_str() );
   SGPropertyNode root;
+  repeat = false;
 
   try {
       readProperties(path.str(), &root);
@@ -472,3 +473,9 @@ void FGAIFlightPlan::resetWaypoints()
       waypoints.push_back(wpt);
     }
 }
+
+// Start flightplan over from the beginning
+void FGAIFlightPlan::restart()
+{
+  wpt_iterator = waypoints.begin();
+}
index c527a57824189b69d1041bbceef817d346e544e9..a6ae1182e2f137e1f85654d8ff0451d4c7a6f978 100644 (file)
@@ -85,18 +85,23 @@ public:
   double getLeadInAngle() { return leadInAngle; };
   string getRunway() { return rwy._rwy_no; };
   string getRunwayId() { return rwy._id; };
+  void setRepeat(bool r) { repeat = r; };
+  bool getRepeat(void) { return repeat; };
+  void restart(void);
+
 private:
   FGRunway rwy;
-    typedef vector <waypoint*> wpt_vector_type;
-    typedef wpt_vector_type::iterator wpt_vector_iterator;
+  typedef vector <waypoint*> wpt_vector_type;
+  typedef wpt_vector_type::iterator wpt_vector_iterator;
 
-    wpt_vector_type       waypoints;
-    wpt_vector_iterator   wpt_iterator;
+  wpt_vector_type       waypoints;
+  wpt_vector_iterator   wpt_iterator;
 
-    double distance_to_go;
-    double lead_distance;
+  bool repeat;
+  double distance_to_go;
+  double lead_distance;
   double leadInAngle;
-    time_t start_time;
+   time_t start_time;
   int leg;
   int gateId;
 
index d5d6392920f6a03ce062aa2b5f8bbeca25963620..fd121ed28d73b11f66b5a7a59ae2f62a540f1749 100644 (file)
@@ -36,6 +36,7 @@
 #include "AIStorm.hxx"
 #include "AIThermal.hxx"
 #include "AICarrier.hxx"
+#include "AIStatic.hxx"
 
 SG_USING_STD(list);
 
@@ -176,7 +177,9 @@ FGAIManager::createAircraft( FGAIModelEntity *entity,   FGAISchedule *ref) {
         if ( entity->fp ) {
           ai_plane->SetFlightPlan(entity->fp);
         }
-
+        if (entity->repeat) {
+          ai_plane->GetFlightPlan()->setRepeat(true);
+        }
         ai_plane->init();
         ai_plane->bind();
         return ai_plane;
@@ -310,6 +313,25 @@ FGAIManager::createThermal( FGAIModelEntity *entity ) {
         return ai_thermal;
 }
 
+void*
+FGAIManager::createStatic( FGAIModelEntity *entity ) {
+     
+     // cout << "creating static object" << endl;    
+
+        FGAIStatic* ai_static = new FGAIStatic(this);
+        ai_list.push_back(ai_static);
+        ++numObjects[0];
+        ++numObjects[FGAIBase::otStatic];
+        ai_static->setHeading(entity->heading);
+        ai_static->setPath(entity->path.c_str());
+        ai_static->setAltitude(entity->altitude);
+        ai_static->setLongitude(entity->longitude);
+        ai_static->setLatitude(entity->latitude);
+        ai_static->init();
+        ai_static->bind();
+        return ai_static;
+}
+
 void FGAIManager::destroyObject( void* ID ) {
         ai_list_iterator ai_list_itr = ai_list.begin();
         while(ai_list_itr != ai_list.end()) {
@@ -371,7 +393,10 @@ void FGAIManager::processScenario( string &filename ) {
 
       } else if ( en->m_type == "ballistic") {
         createBallistic( en );
-      }      
+
+      } else if ( en->m_type == "static") {
+        createStatic( en );
+      }            
     }
   }
 
index cc18831abe8e5c0523b2f1428ceeaa3a43459caf..25c3b3d9b48cf4f7dd3caaa0861d7b84d15b8519 100644 (file)
@@ -1,4 +1,4 @@
-// AIManager.hxx - experimental! - David Culp - based on:
+// AIManager.hxx - David Culp - based on:
 // AIMgr.hxx - definition of FGAIMgr 
 // - a global management class for FlightGear generated AI traffic
 //
@@ -87,6 +87,7 @@ public:
     void* createStorm( FGAIModelEntity *entity );
     void* createShip( FGAIModelEntity *entity );
     void* createCarrier( FGAIModelEntity *entity );
+    void* createStatic( FGAIModelEntity *entity );
 
     void destroyObject( void* ID );
 
diff --git a/src/AIModel/AIStatic.cxx b/src/AIModel/AIStatic.cxx
new file mode 100644 (file)
index 0000000..148aaac
--- /dev/null
@@ -0,0 +1,65 @@
+// FGAIStatic - FGAIBase-derived class creates an AI static object
+//
+// Written by David Culp, started Jun 2005.
+//
+// Copyright (C) 2005  David P. Culp - davidculp2@comcast.net
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// 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.
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <simgear/math/point3d.hxx>
+#include <Main/fg_props.hxx>
+#include <Main/globals.hxx>
+#include <Scenery/scenery.hxx>
+#include <string>
+#include <math.h>
+
+SG_USING_STD(string);
+
+#include "AIStatic.hxx"
+
+
+FGAIStatic::FGAIStatic(FGAIManager* mgr) {
+   manager = mgr;   
+   _type_str = "static";
+   _otype = otStatic;
+}
+
+
+FGAIStatic::~FGAIStatic() {
+}
+
+
+bool FGAIStatic::init() {
+   return FGAIBase::init();
+}
+
+void FGAIStatic::bind() {
+    FGAIBase::bind();
+}
+
+void FGAIStatic::unbind() {
+    FGAIBase::unbind();
+}
+
+
+void FGAIStatic::update(double dt) {
+   FGAIBase::update(dt);
+   Transform();
+}
+
diff --git a/src/AIModel/AIStatic.hxx b/src/AIModel/AIStatic.hxx
new file mode 100644 (file)
index 0000000..25c9b01
--- /dev/null
@@ -0,0 +1,51 @@
+// FGAIStatic - AIBase derived class creates AI static object
+//
+// Written by David Culp, started Jun 2005.
+//
+// Copyright (C) 2005  David P. Culp - davidculp2@comcast.net
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// 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.
+
+#ifndef _FG_AIStatic_HXX
+#define _FG_AIStatic_HXX
+
+#include "AIManager.hxx"
+#include "AIBase.hxx"
+
+#include <string>
+SG_USING_STD(string);
+
+
+class FGAIStatic : public FGAIBase {
+
+public:
+
+       FGAIStatic(FGAIManager* mgr);
+       ~FGAIStatic();
+       
+       bool init();
+        virtual void bind();
+        virtual void unbind();
+       void update(double dt);
+
+private:
+
+        double dt; 
+       
+};
+
+
+
+#endif  // _FG_AISTATIC_HXX
index fc2aafeec10d88e8c0beafbd154a0f29b8ee6f38..e02adc4f0bf52555cf4ce9cdb3eb5b1b90d27bd1 100644 (file)
@@ -11,6 +11,7 @@ libAIModel_a_SOURCES = \
        AIThermal.hxx AIThermal.cxx \
        AIFlightPlan.hxx AIFlightPlan.cxx AIFlightPlanCreate.cxx \
        AIScenario.hxx AIScenario.cxx \
-        AICarrier.hxx AICarrier.cxx
+        AICarrier.hxx AICarrier.cxx \
+        AIStatic.hxx AIStatic.cxx
 
 INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src