// 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;
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);
}
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() {
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;
+}
+
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;
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();
FGAIFlightPlan *fp;
void Transform();
-
+ void CalculateMach();
double UpdateRadar(FGAIManager* manager);
string _type_str;
SGPath path( globals->get_fg_root() );
path.append( ("/Data/AI/FlightPlans/" + filename).c_str() );
SGPropertyNode root;
+ repeat = false;
try {
readProperties(path.str(), &root);
waypoints.push_back(wpt);
}
}
+
+// Start flightplan over from the beginning
+void FGAIFlightPlan::restart()
+{
+ wpt_iterator = waypoints.begin();
+}
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;
#include "AIStorm.hxx"
#include "AIThermal.hxx"
#include "AICarrier.hxx"
+#include "AIStatic.hxx"
SG_USING_STD(list);
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;
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()) {
} else if ( en->m_type == "ballistic") {
createBallistic( en );
- }
+
+ } else if ( en->m_type == "static") {
+ createStatic( en );
+ }
}
}
-// 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
//
void* createStorm( FGAIModelEntity *entity );
void* createShip( FGAIModelEntity *entity );
void* createCarrier( FGAIModelEntity *entity );
+ void* createStatic( FGAIModelEntity *entity );
void destroyObject( void* ID );
--- /dev/null
+// 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();
+}
+
--- /dev/null
+// 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
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