]> git.mxchange.org Git - flightgear.git/commitdiff
David Culp:
authorehofman <ehofman>
Sat, 29 May 2004 11:39:10 +0000 (11:39 +0000)
committerehofman <ehofman>
Sat, 29 May 2004 11:39:10 +0000 (11:39 +0000)
Here's some new AI stuff.

1)  AI objects must now be defined in a scenario file, not in preferences.xml
or a *-set file.  (Of course this doesn't prevent objects from being created
dynamically, as with Durk's traffic manager).

2)  A new demo_scenario file is attached.  It creates 3 aircraft, a sailboat,
and a thunderstorm.

3)  Objects without flightplans live forever.

4)  FGAIShip::ProcessFlightplan() is not yet implemented.

5)  preferences.xml should now define only <enabled> and <scenario>

src/AIModel/AIAircraft.cxx
src/AIModel/AIAircraft.hxx
src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx
src/AIModel/AIManager.cxx
src/AIModel/AIManager.hxx
src/AIModel/AIScenario.cxx
src/AIModel/AIScenario.hxx
src/AIModel/AIShip.cxx
src/AIModel/AIShip.hxx

index e18217a7c92ad146d89717824eab85ba9218a68c..9ec2c8be77de8e264bb5b8178b8921e3bcd75a0b 100644 (file)
@@ -64,7 +64,6 @@ FGAIAircraft::FGAIAircraft(FGAIManager* mgr) {
 
 
 FGAIAircraft::~FGAIAircraft() {
-    if (fp) delete fp;
 }
 
 
index 0b8739fda50f63734832bbc2d4e0b77bb15cab45..97227ab1b5fcf26badd3f494e18ace9891696581 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "AIManager.hxx"
 #include "AIBase.hxx"
-#include "AIFlightPlan.hxx"
 
 #include <string>
 SG_USING_STD(string);
@@ -67,13 +66,11 @@ public:
         void ClimbTo(double altitude);
         void TurnTo(double heading);
         void ProcessFlightPlan( double dt );
-        //double getHeading(double lat1, double lon1, double lat2, double lon2);
 
 private:
 
         bool hdg_lock;
         bool alt_lock;
-        FGAIFlightPlan *fp;
         double dt_count;  
         double dt; 
 
index d1f0ca336e0eca60288e82a763a4a8242e5e73a6..f27067ad62cf154e408754e1ef79125c8fb3d9ee 100644 (file)
@@ -61,6 +61,7 @@ FGAIBase::~FGAIBase() {
     // unbind();
     SGPropertyNode *root = globals->get_props()->getNode("ai/models", true);
     root->removeChild(_type_str.c_str(), index);
+    if (fp) delete fp;
 }
 
 void FGAIBase::update(double dt) {
index 990760433eda4145165182f67947c20a40f70ca5..b9db98c6c889665aa7781cdd2571b894d907eaf9 100644 (file)
@@ -27,6 +27,7 @@
 #include <simgear/scene/model/placement.hxx>
 
 #include <Main/fg_props.hxx>
+#include "AIFlightPlan.hxx"
 
 SG_USING_STD(string);
 
@@ -103,6 +104,7 @@ protected:
     int id;
     bool invisible;
     bool no_roll;
+    FGAIFlightPlan *fp;
 
     void Transform();
 
index b53ac439b3686443dfcff2a3bd6ba7e9d62dde15..1aed8f732f923735d1ff07615e07d50ebff3eff5 100644 (file)
@@ -54,75 +54,15 @@ FGAIManager::~FGAIManager() {
 
 
 void FGAIManager::init() {
-  int rval;
   root = fgGetNode("sim/ai", true);
 
   enabled = root->getNode("enabled", true)->getBoolValue();
   if (!enabled)
       return;
 
-
   wind_from_down = fgGetNode("/environment/wind-from-down-fps", true);
-
-  for (int i = 0; i < root->nChildren(); i++) {
-    const SGPropertyNode * entry = root->getChild(i);
-
-    if (!strcmp(entry->getName(), "scenario")){
-      scenario_filename = entry->getStringValue();
-    }
-
-    if (!strcmp(entry->getName(), "entry")) {
-      if (!strcmp(entry->getStringValue("type", ""), "aircraft")) { 
-
-        rval = createAircraft( entry->getStringValue("class", ""),
-                               entry->getStringValue("path"),
-                               entry->getDoubleValue("latitude"),
-                               entry->getDoubleValue("longitude"),
-                               entry->getDoubleValue("altitude-ft"),
-                               entry->getDoubleValue("heading"),
-                               entry->getDoubleValue("speed-KTAS"),
-                               0.0, 
-                               entry->getDoubleValue("bank") );
-
-      } else if (!strcmp(entry->getStringValue("type", ""), "ship")) {
-
-        rval = createShip( entry->getStringValue("path"),
-                           entry->getDoubleValue("latitude"),
-                           entry->getDoubleValue("longitude"),
-                           entry->getDoubleValue("altitude-ft"),
-                           entry->getDoubleValue("heading"),
-                           entry->getDoubleValue("speed-KTAS"),
-                           entry->getDoubleValue("rudder") );
-
-      } else if (!strcmp(entry->getStringValue("type", ""), "ballistic")) {
-
-        rval = createBallistic( entry->getStringValue("path"),
-                                entry->getDoubleValue("latitude"),
-                                entry->getDoubleValue("longitude"),
-                                entry->getDoubleValue("altitude-ft"),
-                                entry->getDoubleValue("azimuth"),
-                                entry->getDoubleValue("elevation"),
-                                entry->getDoubleValue("speed") );
-
-      } else if (!strcmp(entry->getStringValue("type", ""), "storm")) {
-
-        rval = createStorm( entry->getStringValue("path"),
-                            entry->getDoubleValue("latitude"),
-                            entry->getDoubleValue("longitude"),
-                            entry->getDoubleValue("altitude-ft"),
-                            entry->getDoubleValue("heading"),
-                            entry->getDoubleValue("speed-KTAS") );
-
-      } else if (!strcmp(entry->getStringValue("type", ""), "thermal")) {
-
-        rval = createThermal( entry->getDoubleValue("latitude"),
-                              entry->getDoubleValue("longitude"),
-                              entry->getDoubleValue("strength-fps"),
-                              entry->getDoubleValue("diameter-ft") );
-
-      }       
-    }
-  }
+  scenario_filename = root->getNode("scenario", true)->getStringValue();
 
   if (scenario_filename != "") processScenario( scenario_filename );
   initDone = true;
@@ -214,7 +154,7 @@ void FGAIManager::freeID( int ID ) {
 
 int FGAIManager::createAircraft( string model_class, string path,
               double latitude, double longitude, double altitude,
-              double heading, double speed, double pitch, double roll ) {
+              double heading, double speed, double roll ) {
      
         FGAIAircraft* ai_plane = new FGAIAircraft(this);
         ai_list.push_back(ai_plane);
@@ -290,6 +230,19 @@ int FGAIManager::createShip( string path, double latitude, double longitude,
         return ai_ship->getID();
 }
 
+int FGAIManager::createShip( string path, FGAIFlightPlan* flightplan ) {
+
+        FGAIShip* ai_ship = new FGAIShip(this);
+        ai_list.push_back(ai_ship);
+        ai_ship->setID( assignID() );
+        ++numObjects;
+        ai_ship->setPath(path.c_str());
+        ai_ship->setFlightPlan(flightplan); 
+        ai_ship->init();
+        ai_ship->bind();
+        return ai_ship->getID();
+}
+
 
 int FGAIManager::createBallistic( string path, double latitude, double longitude,
                                   double altitude, double azimuth, double elevation,
@@ -387,17 +340,46 @@ void FGAIManager::processThermal( FGAIThermal* thermal ) {
 
 
 void FGAIManager::processScenario( string filename ) {
-  //cout << "AIManager: creating a scenario." << endl;
   FGAIScenario* s = new FGAIScenario( filename );
+  FGAIFlightPlan* f;
+
   for (int i=0;i<s->nEntries();i++) {
     FGAIScenario::entry* en = s->getNextEntry();
+    f = 0;
     if (en) {
-      FGAIFlightPlan* f = new FGAIFlightPlan( en->flightplan );
+      if (en->flightplan != ""){
+        f = new FGAIFlightPlan( en->flightplan );
+      }  
       if (en->aitype == "aircraft"){
-        createAircraft( en->aircraft_class, en->model_path, f);
-      }
+         if (f){
+           createAircraft( en->aircraft_class, en->model_path, f );
+         } else {
+           createAircraft( en->aircraft_class, en->model_path, en->latitude,
+                           en->longitude, en->altitude, en->heading,
+                           en->speed, en->roll );
+         } 
+      } else if (en->aitype == "ship"){
+         if (f){
+           createShip( en->model_path, f );
+         } else {
+           createShip( en->model_path, en->latitude,
+                           en->longitude, en->altitude, en->heading,
+                           en->speed, en->rudder );
+         } 
+
+      } else if (en->aitype == "storm"){
+        createStorm( en->model_path, en->latitude, en->longitude,
+                     en->altitude, en->heading, en->speed ); 
+      } else if (en->aitype == "thermal"){
+        createThermal( en->latitude, en->longitude, en->strength, 
+                       en->diameter );
+      } else if (en->aitype == "ballistic"){
+        createBallistic( en->model_path, en->latitude, en->longitude,
+                         en->altitude, en->azimuth, en->elevation, en->speed );
+      }      
     }
   }
+
   delete s;
 }
 
index 2e154fd6a434428ce7c019848a62e79bf27c223e..1766c8a8cb8485900e9329769422dffc3d5c8c00 100644 (file)
@@ -74,7 +74,6 @@ public:
                         double altitude,    // in feet
                         double heading,     // true heading in degrees
                         double speed,       // in knots true airspeed (KTAS)    
-                        double pitch = 0,   // in degrees
                         double roll = 0 );  // in degrees
 
     int createAircraft( string model_class, // see FGAIAircraft.hxx for possible classes
@@ -87,8 +86,10 @@ public:
                         double altitude,    // in feet  (ex. for a lake!)
                         double heading,     // true heading in degrees
                         double speed,       // in knots true
-                        double rudder );    // in degrees (between 0 and 5 works best)
+                        double rudder );    // in degrees (right is positive)(0 to 5 works best)
 
+    int createShip(     string path,        // path to exterior model
+                        FGAIFlightPlan *flightplan );
 
     int createBallistic( string path,       // path to exterior model
                          double latitude,   // in degrees -90 to 90
index 07013c9aff59e30a9acf2af23f374cc4cd7465ee..dcd87360f32f8f7871181f02fc3455c3a1b247cc 100644 (file)
@@ -58,6 +58,17 @@ FGAIScenario::FGAIScenario(string filename)
      en->model_path     = entry_node->getStringValue("model", "Models/Geometry/glider.ac");
      en->flightplan     = entry_node->getStringValue("flightplan", "");
      en->repeat         = entry_node->getDoubleValue("repeat", 0.0); 
+     en->latitude       = entry_node->getDoubleValue("latitude", 0.0); 
+     en->longitude      = entry_node->getDoubleValue("longitude", 0.0); 
+     en->altitude       = entry_node->getDoubleValue("altitude", 0.0); 
+     en->speed          = entry_node->getDoubleValue("speed", 0.0); 
+     en->heading        = entry_node->getDoubleValue("heading", 0.0); 
+     en->roll           = entry_node->getDoubleValue("roll", 0.0); 
+     en->azimuth        = entry_node->getDoubleValue("azimuth", 0.0); 
+     en->elevation      = entry_node->getDoubleValue("elevation", 0.0); 
+     en->rudder         = entry_node->getDoubleValue("rudder", 0.0);
+     en->strength       = entry_node->getDoubleValue("strength", 0.0);
+     en->diameter       = entry_node->getDoubleValue("diameter", 0.0);
    }
 
   entry_iterator = entries.begin();
index 949c72768e3a3a92133091f83fc6906cff342ea0..39a8644cb3845af2ac9fc0333ce4dd26ad88126d 100644 (file)
@@ -37,6 +37,17 @@ public:
    string model_path;
    string flightplan;
    double repeat;       // in seconds
+   double latitude;     // used if no flightplan defined
+   double longitude;    // used if no flightplan defined
+   double altitude;     // used if no flightplan defined
+   double speed;        // used if no flightplan defined
+   double heading;      // used if no flightplan defined
+   double roll;         // used if no flightplan defined
+   double azimuth;      // used by ballistic objects
+   double elevation;    // used by ballistic objects
+   double rudder;       // used by ship objects 
+   double strength;     // used by thermal objects
+   double diameter;     // used by thermal objects
   } entry;
 
    FGAIScenario(string filename);
index c1d4ce809a3c081241964f7818e87187df6f7236..890ab0b49e5705d837a7c382015f27e2f1dc4259 100644 (file)
@@ -66,6 +66,8 @@ void FGAIShip::update(double dt) {
 
 void FGAIShip::Run(double dt) {
 
+   if (fp) ProcessFlightPlan(dt);
+
    double turn_radius_ft;
    double turn_circum_ft;
    double speed_north_deg_sec;
@@ -167,3 +169,12 @@ double FGAIShip::sign(double x) {
   if ( x < 0.0 ) { return -1.0; }
   else { return 1.0; }
 }
+
+void FGAIShip::setFlightPlan(FGAIFlightPlan* f) {
+  fp = f;
+}
+
+void FGAIShip::ProcessFlightPlan(double dt) {
+  // not implemented yet
+}
+
index 1fc583ca06321195c8f785a7de56fb75e54dbff2..25d8b449581c447652b8a744abc235dc171fbd5a 100644 (file)
@@ -35,6 +35,8 @@ public:
         virtual void bind();
         virtual void unbind();
        void update(double dt);
+        void setFlightPlan(FGAIFlightPlan* f);
+        void ProcessFlightPlan( double dt );
 
         void AccelTo(double speed);
         void PitchTo(double angle);