Make use of a pointer to a structure to pass multiple parameters around.
This commit is contained in:
parent
fed4a2c25a
commit
d158c8168d
12 changed files with 190 additions and 274 deletions
|
@ -57,6 +57,8 @@ FGAIBase::FGAIBase() {
|
|||
_otype = otNull;
|
||||
index = 0;
|
||||
fp = (FGAIFlightPlan*)0;
|
||||
delete_me = false;
|
||||
manager = NULL;
|
||||
}
|
||||
|
||||
FGAIBase::~FGAIBase() {
|
||||
|
@ -89,8 +91,10 @@ void FGAIBase::Transform() {
|
|||
bool FGAIBase::init() {
|
||||
|
||||
SGPropertyNode *root = globals->get_props()->getNode("ai/models", true);
|
||||
|
||||
index = manager->getNum(_otype) - 1;
|
||||
props = root->getNode(_type_str.c_str(), index, true);
|
||||
|
||||
if (model_path != "") {
|
||||
model = sgLoad3DModel( globals->get_fg_root(),
|
||||
model_path.c_str(),
|
||||
|
|
|
@ -27,11 +27,44 @@
|
|||
#include <simgear/scene/model/placement.hxx>
|
||||
|
||||
#include <Main/fg_props.hxx>
|
||||
#include "AIFlightPlan.hxx"
|
||||
|
||||
SG_USING_STD(string);
|
||||
|
||||
class FGAIManager;
|
||||
class FGAIFlightPlan;
|
||||
|
||||
|
||||
typedef struct {
|
||||
string callsign;
|
||||
|
||||
// can be aircraft, ship, storm, thermal or ballistic
|
||||
const char* m_type;
|
||||
const char* m_class;
|
||||
const char* path;
|
||||
const char* flightplan;
|
||||
|
||||
FGAIFlightPlan *fp;
|
||||
|
||||
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
|
||||
double eda; // used by ballistic objects
|
||||
double life; // life span in seconds
|
||||
double buoyancy; // acceleration in ft per sec2
|
||||
double wind_from_east; // in feet per second
|
||||
double wind_from_north; // in feet per second
|
||||
bool wind;
|
||||
} FGAIModelEntity;
|
||||
|
||||
|
||||
class FGAIBase {
|
||||
|
||||
|
|
|
@ -89,11 +89,7 @@ FGAIFlightPlan::FGAIFlightPlan(string filename)
|
|||
// Position computed by the traffic manager, as well
|
||||
// as setting speeds and altitude computed by the
|
||||
// traffic manager.
|
||||
FGAIFlightPlan::FGAIFlightPlan(string filename,
|
||||
double lat,
|
||||
double lon,
|
||||
double alt,
|
||||
double speed,
|
||||
FGAIFlightPlan::FGAIFlightPlan(FGAIModelEntity *entity,
|
||||
double course,
|
||||
FGAirport *dep,
|
||||
FGAirport *arr)
|
||||
|
@ -101,7 +97,8 @@ FGAIFlightPlan::FGAIFlightPlan(string filename,
|
|||
bool useInitialWayPoint = true;
|
||||
bool useCurrentWayPoint = false;
|
||||
SGPath path( globals->get_fg_root() );
|
||||
path.append( ("/Data/AI/FlightPlans/" + filename).c_str() );
|
||||
path.append( "/Data/AI/FlightPlans" );
|
||||
path.append( entity->path );
|
||||
SGPropertyNode root;
|
||||
|
||||
try {
|
||||
|
@ -135,17 +132,17 @@ FGAIFlightPlan::FGAIFlightPlan(string filename,
|
|||
// cout << path.str() << endl;
|
||||
// cout << "Trying to create this plan dynamically" << endl;
|
||||
// cout << "Route from " << dep->id << " to " << arr->id << endl;
|
||||
create(dep,arr, alt, speed);
|
||||
create(dep,arr, entity->altitude, entity->speed);
|
||||
// Now that we have dynamically created a flight plan,
|
||||
// we need to add some code that pops any waypoints already past.
|
||||
//return;
|
||||
}
|
||||
waypoint* init_waypoint = new waypoint;
|
||||
init_waypoint->name = string("initial position");
|
||||
init_waypoint->latitude = lat;
|
||||
init_waypoint->longitude = lon;
|
||||
init_waypoint->altitude = alt;
|
||||
init_waypoint->speed = speed;
|
||||
init_waypoint->latitude = entity->latitude;
|
||||
init_waypoint->longitude = entity->longitude;
|
||||
init_waypoint->altitude = entity->altitude;
|
||||
init_waypoint->speed = entity->speed;
|
||||
init_waypoint->crossat = - 10000;
|
||||
init_waypoint->gear_down = false;
|
||||
init_waypoint->flaps_down = false;
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
#include <Airports/simple.hxx>
|
||||
|
||||
#include "AIBase.hxx"
|
||||
|
||||
SG_USING_STD(vector);
|
||||
SG_USING_STD(string);
|
||||
|
||||
|
@ -47,11 +49,7 @@ public:
|
|||
} waypoint;
|
||||
|
||||
FGAIFlightPlan(string filename);
|
||||
FGAIFlightPlan(string filename,
|
||||
double lat,
|
||||
double lon,
|
||||
double alt,
|
||||
double speed,
|
||||
FGAIFlightPlan(FGAIModelEntity *entity,
|
||||
double course,
|
||||
FGAirport *dep,
|
||||
FGAirport *arr);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// AIManager.cxx Based on David Luff's AIMgr:
|
||||
// - a global management class for AI objects
|
||||
// - a global management type for AI objects
|
||||
//
|
||||
// Written by David Culp, started October 2003.
|
||||
// - davidculp2@comcast.net
|
||||
|
@ -40,6 +40,8 @@ FGAIManager::FGAIManager() {
|
|||
_dt = 0.0;
|
||||
dt_count = 9;
|
||||
scenario_filename = "";
|
||||
ai_list.clear();
|
||||
ids.clear();
|
||||
}
|
||||
|
||||
FGAIManager::~FGAIManager() {
|
||||
|
@ -60,7 +62,7 @@ void FGAIManager::init() {
|
|||
if (!enabled)
|
||||
return;
|
||||
|
||||
wind_from_down = fgGetNode("/environment/wind-from-down-fps", true);
|
||||
wind_from_down_node = fgGetNode("/environment/wind-from-down-fps", true);
|
||||
|
||||
scenario_filename = root->getNode("scenario", true)->getStringValue();
|
||||
|
||||
|
@ -114,7 +116,7 @@ void FGAIManager::update(double dt) {
|
|||
}
|
||||
++ai_list_itr;
|
||||
}
|
||||
wind_from_down->setDoubleValue( strength );
|
||||
wind_from_down_node->setDoubleValue( strength );
|
||||
|
||||
}
|
||||
|
||||
|
@ -153,160 +155,117 @@ void FGAIManager::freeID( int ID ) {
|
|||
}
|
||||
}
|
||||
|
||||
int FGAIManager::createAircraft( string model_class, string path,
|
||||
double latitude, double longitude, double altitude,
|
||||
double heading, double speed, double roll ) {
|
||||
int FGAIManager::createAircraft( FGAIModelEntity *entity ) {
|
||||
|
||||
FGAIAircraft* ai_plane = new FGAIAircraft(this);
|
||||
ai_list.push_back(ai_plane);
|
||||
ai_plane->setID( assignID() );
|
||||
++numObjects;
|
||||
if (model_class == "light") {
|
||||
if (entity->m_class == "light") {
|
||||
ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::LIGHT]);
|
||||
} else if (model_class == "ww2_fighter") {
|
||||
} else if (entity->m_class == "ww2_fighter") {
|
||||
ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::WW2_FIGHTER]);
|
||||
} else if (model_class == "jet_transport") {
|
||||
} else if (entity->m_class == "jet_transport") {
|
||||
ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]);
|
||||
} else if (model_class == "jet_fighter") {
|
||||
} else if (entity->m_class == "jet_fighter") {
|
||||
ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_FIGHTER]);
|
||||
} else if (model_class == "tanker") {
|
||||
} else if (entity->m_class == "tanker") {
|
||||
ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]);
|
||||
ai_plane->SetTanker(true);
|
||||
} else {
|
||||
ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]);
|
||||
}
|
||||
ai_plane->setHeading(heading);
|
||||
ai_plane->setSpeed(speed);
|
||||
ai_plane->setPath(path.c_str());
|
||||
ai_plane->setAltitude(altitude);
|
||||
ai_plane->setLongitude(longitude);
|
||||
ai_plane->setLatitude(latitude);
|
||||
ai_plane->setBank(roll);
|
||||
ai_plane->init();
|
||||
ai_plane->bind();
|
||||
return ai_plane->getID();
|
||||
}
|
||||
ai_plane->setHeading(entity->heading);
|
||||
ai_plane->setSpeed(entity->speed);
|
||||
ai_plane->setPath(entity->path);
|
||||
ai_plane->setAltitude(entity->altitude);
|
||||
ai_plane->setLongitude(entity->longitude);
|
||||
ai_plane->setLatitude(entity->latitude);
|
||||
ai_plane->setBank(entity->roll);
|
||||
|
||||
|
||||
int FGAIManager::createAircraft( string model_class, string path,
|
||||
FGAIFlightPlan* flightplan ) {
|
||||
|
||||
FGAIAircraft* ai_plane = new FGAIAircraft(this);
|
||||
ai_list.push_back(ai_plane);
|
||||
ai_plane->setID( assignID() );
|
||||
++numObjects;
|
||||
if (model_class == "light") {
|
||||
ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::LIGHT]);
|
||||
} else if (model_class == "ww2_fighter") {
|
||||
ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::WW2_FIGHTER]);
|
||||
} else if (model_class == "jet_transport") {
|
||||
ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]);
|
||||
} else if (model_class == "jet_fighter") {
|
||||
ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_FIGHTER]);
|
||||
} else if (model_class == "tanker") {
|
||||
ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]);
|
||||
ai_plane->SetTanker(true);
|
||||
} else {
|
||||
ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]);
|
||||
if ( entity->fp ) {
|
||||
ai_plane->SetFlightPlan(entity->fp);
|
||||
}
|
||||
ai_plane->setPath(path.c_str());
|
||||
ai_plane->SetFlightPlan(flightplan);
|
||||
|
||||
ai_plane->init();
|
||||
ai_plane->bind();
|
||||
return ai_plane->getID();
|
||||
}
|
||||
|
||||
|
||||
int FGAIManager::createShip( string path, double latitude, double longitude,
|
||||
double altitude, double heading, double speed,
|
||||
double rudder ) {
|
||||
int FGAIManager::createShip( FGAIModelEntity *entity ) {
|
||||
|
||||
FGAIShip* ai_ship = new FGAIShip(this);
|
||||
ai_list.push_back(ai_ship);
|
||||
ai_ship->setID( assignID() );
|
||||
++numObjects;
|
||||
ai_ship->setHeading(heading);
|
||||
ai_ship->setSpeed(speed);
|
||||
ai_ship->setPath(path.c_str());
|
||||
ai_ship->setAltitude(altitude);
|
||||
ai_ship->setLongitude(longitude);
|
||||
ai_ship->setLatitude(latitude);
|
||||
ai_ship->setBank(rudder);
|
||||
ai_ship->setHeading(entity->heading);
|
||||
ai_ship->setSpeed(entity->speed);
|
||||
ai_ship->setPath(entity->path);
|
||||
ai_ship->setAltitude(entity->altitude);
|
||||
ai_ship->setLongitude(entity->longitude);
|
||||
ai_ship->setLatitude(entity->latitude);
|
||||
ai_ship->setBank(entity->rudder);
|
||||
|
||||
if ( entity->fp ) {
|
||||
ai_ship->setFlightPlan(entity->fp);
|
||||
}
|
||||
|
||||
ai_ship->init();
|
||||
ai_ship->bind();
|
||||
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,
|
||||
double speed, double eda, double life, double buoyancy,
|
||||
double wind_from_east, double wind_from_north, bool wind ) {
|
||||
int FGAIManager::createBallistic( FGAIModelEntity *entity ) {
|
||||
|
||||
FGAIBallistic* ai_ballistic = new FGAIBallistic(this);
|
||||
ai_list.push_back(ai_ballistic);
|
||||
ai_ballistic->setID( assignID() );
|
||||
++numObjects;
|
||||
ai_ballistic->setAzimuth(azimuth);
|
||||
ai_ballistic->setElevation(elevation);
|
||||
ai_ballistic->setSpeed(speed);
|
||||
ai_ballistic->setPath(path.c_str());
|
||||
ai_ballistic->setAltitude(altitude);
|
||||
ai_ballistic->setLongitude(longitude);
|
||||
ai_ballistic->setLatitude(latitude);
|
||||
ai_ballistic->setDragArea(eda);
|
||||
ai_ballistic->setLife(life);
|
||||
ai_ballistic->setBuoyancy(buoyancy);
|
||||
ai_ballistic->setWind_from_east(wind_from_east);
|
||||
ai_ballistic->setWind_from_north(wind_from_north);
|
||||
ai_ballistic->setWind(wind);
|
||||
ai_ballistic->setAzimuth(entity->azimuth);
|
||||
ai_ballistic->setElevation(entity->elevation);
|
||||
ai_ballistic->setSpeed(entity->speed);
|
||||
ai_ballistic->setPath(entity->path);
|
||||
ai_ballistic->setAltitude(entity->altitude);
|
||||
ai_ballistic->setLongitude(entity->longitude);
|
||||
ai_ballistic->setLatitude(entity->latitude);
|
||||
ai_ballistic->setDragArea(entity->eda);
|
||||
ai_ballistic->setLife(entity->life);
|
||||
ai_ballistic->setBuoyancy(entity->buoyancy);
|
||||
ai_ballistic->setWind_from_east(entity->wind_from_east);
|
||||
ai_ballistic->setWind_from_north(entity->wind_from_north);
|
||||
ai_ballistic->setWind(entity->wind);
|
||||
ai_ballistic->init();
|
||||
ai_ballistic->bind();
|
||||
return ai_ballistic->getID();
|
||||
}
|
||||
|
||||
int FGAIManager::createStorm( string path, double latitude, double longitude,
|
||||
double altitude, double heading, double speed ) {
|
||||
int FGAIManager::createStorm( FGAIModelEntity *entity ) {
|
||||
|
||||
FGAIStorm* ai_storm = new FGAIStorm(this);
|
||||
ai_list.push_back(ai_storm);
|
||||
ai_storm->setID( assignID() );
|
||||
++numObjects;
|
||||
ai_storm->setHeading(heading);
|
||||
ai_storm->setSpeed(speed);
|
||||
ai_storm->setPath(path.c_str());
|
||||
ai_storm->setAltitude(altitude);
|
||||
ai_storm->setLongitude(longitude);
|
||||
ai_storm->setLatitude(latitude);
|
||||
ai_storm->setHeading(entity->heading);
|
||||
ai_storm->setSpeed(entity->speed);
|
||||
ai_storm->setPath(entity->path);
|
||||
ai_storm->setAltitude(entity->altitude);
|
||||
ai_storm->setLongitude(entity->longitude);
|
||||
ai_storm->setLatitude(entity->latitude);
|
||||
ai_storm->init();
|
||||
ai_storm->bind();
|
||||
return ai_storm->getID();
|
||||
}
|
||||
|
||||
int FGAIManager::createThermal( double latitude, double longitude,
|
||||
double strength, double diameter ) {
|
||||
int FGAIManager::createThermal( FGAIModelEntity *entity ) {
|
||||
|
||||
FGAIThermal* ai_thermal = new FGAIThermal(this);
|
||||
ai_list.push_back(ai_thermal);
|
||||
ai_thermal->setID( assignID() );
|
||||
++numObjects;
|
||||
ai_thermal->setLongitude(longitude);
|
||||
ai_thermal->setLatitude(latitude);
|
||||
ai_thermal->setMaxStrength(strength);
|
||||
ai_thermal->setDiameter(diameter / 6076.11549);
|
||||
ai_thermal->setLongitude(entity->longitude);
|
||||
ai_thermal->setLatitude(entity->latitude);
|
||||
ai_thermal->setMaxStrength(entity->strength);
|
||||
ai_thermal->setDiameter(entity->diameter / 6076.11549);
|
||||
ai_thermal->init();
|
||||
ai_thermal->bind();
|
||||
return ai_thermal->getID();
|
||||
|
@ -355,43 +314,30 @@ void FGAIManager::processThermal( FGAIThermal* thermal ) {
|
|||
|
||||
void FGAIManager::processScenario( string filename ) {
|
||||
FGAIScenario* s = new FGAIScenario( filename );
|
||||
FGAIFlightPlan* f;
|
||||
|
||||
for (int i=0;i<s->nEntries();i++) {
|
||||
FGAIScenario::entry* en = s->getNextEntry();
|
||||
f = 0;
|
||||
if (en) {
|
||||
if (en->flightplan != ""){
|
||||
f = new FGAIFlightPlan( en->flightplan );
|
||||
}
|
||||
if (en->aitype == "aircraft"){
|
||||
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 );
|
||||
}
|
||||
FGAIModelEntity* en = s->getNextEntry();
|
||||
|
||||
} 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,
|
||||
en->eda, en->life, en->buoyancy, en->wind_from_east,
|
||||
en-> wind_from_north, en->wind);
|
||||
if (en) {
|
||||
en->fp = NULL;
|
||||
if (en->flightplan != ""){
|
||||
en->fp = new FGAIFlightPlan( en->flightplan );
|
||||
}
|
||||
|
||||
if (en->m_class == "aircraft") {
|
||||
createAircraft( en );
|
||||
|
||||
} else if (en->m_class == "ship") {
|
||||
createShip( en );
|
||||
|
||||
} else if (en->m_class == "storm") {
|
||||
createStorm( en );
|
||||
|
||||
} else if (en->m_class == "thermal") {
|
||||
createThermal( en );
|
||||
|
||||
} else if (en->m_class == "ballistic") {
|
||||
createBallistic( en );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,12 +23,15 @@
|
|||
#ifndef _FG_AIMANAGER_HXX
|
||||
#define _FG_AIMANAGER_HXX
|
||||
|
||||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
#include <list>
|
||||
#include "AIBase.hxx"
|
||||
#include "AIScenario.hxx"
|
||||
#include "AIFlightPlan.hxx"
|
||||
|
||||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
|
||||
#include <Main/fg_props.hxx>
|
||||
|
||||
#include <AIModel/AIBase.hxx>
|
||||
#include <AIModel/AIScenario.hxx>
|
||||
#include <AIModel/AIFlightPlan.hxx>
|
||||
|
||||
SG_USING_STD(list);
|
||||
class FGAIThermal;
|
||||
|
@ -67,70 +70,12 @@ public:
|
|||
int assignID();
|
||||
void freeID(int ID);
|
||||
|
||||
int createAircraft( string model_class, // see FGAIAircraft.hxx for possible classes
|
||||
string path, // path to exterior model
|
||||
double latitude, // in degrees -90 to 90
|
||||
double longitude, // in degrees -180 to 180
|
||||
double altitude, // in feet
|
||||
double heading, // true heading in degrees
|
||||
double speed, // in knots true airspeed (KTAS)
|
||||
double roll = 0 ); // in degrees
|
||||
int createBallistic( FGAIModelEntity *entity );
|
||||
int createAircraft( FGAIModelEntity *entity );
|
||||
int createThermal( FGAIModelEntity *entity );
|
||||
int createStorm( FGAIModelEntity *entity );
|
||||
int createShip( FGAIModelEntity *entity );
|
||||
|
||||
int createAircraft( string model_class, // see FGAIAircraft.hxx for possible classes
|
||||
string path, // path to exterior model
|
||||
FGAIFlightPlan *flightplan );
|
||||
|
||||
int createShip( string path, // path to exterior model
|
||||
double latitude, // in degrees -90 to 90
|
||||
double longitude, // in degrees -180 to 180
|
||||
double altitude, // in feet (ex. for a lake!)
|
||||
double heading, // true heading in degrees
|
||||
double speed, // in knots true
|
||||
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
|
||||
double longitude, // in degrees -180 to 180
|
||||
double altitude, // in feet
|
||||
double azimuth, // in degrees (same as heading)
|
||||
double elevation, // in degrees (same as pitch)
|
||||
double speed, // in feet per second
|
||||
double eda, // equivalent drag area, ft2
|
||||
double life, // life span in seconds
|
||||
double buoyancy, // acceleration due to buoyancy feet per second2
|
||||
double wind_from_east, // in feet per second
|
||||
double wind_from_north, // in feet per second
|
||||
bool wind // val
|
||||
);
|
||||
|
||||
int createStorm( string path, // path to exterior model
|
||||
double latitude, // in degrees -90 to 90
|
||||
double longitude, // in degrees -180 to 180
|
||||
double altitude, // in feet
|
||||
double heading, // true heading in degrees
|
||||
double speed ); // in knots true airspeed (KTAS)
|
||||
|
||||
int createThermal( double latitude, // in degrees -90 to 90
|
||||
double longitude, // in degrees -180 to 180
|
||||
double strength, // in feet per second
|
||||
double diameter ); // in feet
|
||||
|
||||
int createSmoke ( string path, // path to exterior model
|
||||
double latitude, // in degrees -90 to 90
|
||||
double longitude, // in degrees -180 to 180
|
||||
double altitude, // in feet
|
||||
double azimuth, // in degrees (same as heading)
|
||||
double elevation, // in degrees (same as pitch)
|
||||
double speed, // in feet per second
|
||||
double eda, // equivalent drag area, ft2
|
||||
double life, // life span in seconds
|
||||
double buoyancy // acceleration due to buoyancy feet per second2
|
||||
);
|
||||
|
||||
|
||||
void destroyObject( int ID );
|
||||
|
||||
inline double get_user_latitude() { return user_latitude; }
|
||||
|
@ -150,7 +95,7 @@ private:
|
|||
bool enabled;
|
||||
int numObjects;
|
||||
SGPropertyNode* root;
|
||||
SGPropertyNode* wind_from_down;
|
||||
SGPropertyNode* wind_from_down_node;
|
||||
string scenario_filename;
|
||||
|
||||
double user_latitude;
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
|
||||
#include "AIScenario.hxx"
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/structure/exception.hxx>
|
||||
|
@ -26,9 +25,13 @@
|
|||
# define exception c_exception
|
||||
#endif
|
||||
#include <simgear/props/props.hxx>
|
||||
|
||||
#include <Main/globals.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
|
||||
#include "AIScenario.hxx"
|
||||
|
||||
|
||||
|
||||
FGAIScenario::FGAIScenario(string filename)
|
||||
{
|
||||
|
@ -49,13 +52,13 @@ FGAIScenario::FGAIScenario(string filename)
|
|||
SGPropertyNode * node = root.getNode("scenario");
|
||||
for (i = 0; i < node->nChildren(); i++) {
|
||||
//cout << "Reading entry " << i << endl;
|
||||
entry* en = new entry;
|
||||
FGAIModelEntity* en = new FGAIModelEntity;
|
||||
entries.push_back( en );
|
||||
SGPropertyNode * entry_node = node->getChild(i);
|
||||
en->callsign = entry_node->getStringValue("callsign", "none");
|
||||
en->aitype = entry_node->getStringValue("type", "aircraft");
|
||||
en->aircraft_class = entry_node->getStringValue("class", "jet_transport");
|
||||
en->model_path = entry_node->getStringValue("model", "Models/Geometry/glider.ac");
|
||||
en->m_type = entry_node->getStringValue("type", "aircraft");
|
||||
en->m_class = entry_node->getStringValue("class", "jet_transport");
|
||||
en->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);
|
||||
|
@ -88,7 +91,7 @@ FGAIScenario::~FGAIScenario()
|
|||
}
|
||||
|
||||
|
||||
FGAIScenario::entry*
|
||||
FGAIModelEntity*
|
||||
FGAIScenario::getNextEntry( void )
|
||||
{
|
||||
if (entries.size() == 0) return 0;
|
||||
|
|
|
@ -20,8 +20,12 @@
|
|||
#define _FG_AISCENARIO_HXX
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "AIBase.hxx"
|
||||
|
||||
SG_USING_STD(vector);
|
||||
SG_USING_STD(string);
|
||||
|
||||
|
@ -30,41 +34,15 @@ class FGAIScenario {
|
|||
|
||||
public:
|
||||
|
||||
typedef struct {
|
||||
string callsign;
|
||||
string aitype; // can be aircraft, ship, storm, thermal, ballistic, smoke
|
||||
string aircraft_class;
|
||||
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
|
||||
double eda; // used by ballistic objects
|
||||
double life; // life span in seconds
|
||||
double buoyancy; // acceleration in ft per sec2
|
||||
double wind_from_east; // in feet per second
|
||||
double wind_from_north; // in feet per second
|
||||
bool wind;
|
||||
} entry;
|
||||
|
||||
FGAIScenario(string filename);
|
||||
~FGAIScenario();
|
||||
|
||||
entry* getNextEntry( void );
|
||||
FGAIModelEntity* getNextEntry( void );
|
||||
int nEntries( void );
|
||||
|
||||
private:
|
||||
|
||||
typedef vector <entry*> entry_vector_type;
|
||||
typedef vector <FGAIModelEntity*> entry_vector_type;
|
||||
typedef entry_vector_type::iterator entry_vector_iterator;
|
||||
|
||||
entry_vector_type entries;
|
||||
|
|
|
@ -92,11 +92,23 @@ SubmodelSystem::release (submodel* sm, double dt)
|
|||
transform(sm);
|
||||
|
||||
//cout << "Creating a submodel." << endl;
|
||||
int rval = ai->createBallistic( sm->model, IC.lat, IC.lon, IC.alt, IC.azimuth,
|
||||
IC.elevation, IC.speed,
|
||||
sm->drag_area, sm->life,
|
||||
sm->buoyancy,
|
||||
IC.wind_from_east, IC.wind_from_north, sm->wind);
|
||||
FGAIModelEntity entity;
|
||||
|
||||
entity.path = sm->model.c_str();
|
||||
entity.latitude = IC.lat;
|
||||
entity.longitude = IC.lon;
|
||||
entity.altitude = IC.alt;
|
||||
entity.azimuth = IC.azimuth;
|
||||
entity.elevation = IC.elevation;
|
||||
entity.speed = IC.speed;
|
||||
entity.eda = sm->drag_area;
|
||||
entity.life = sm->life;
|
||||
entity.buoyancy = sm->buoyancy;
|
||||
entity.wind_from_east = IC.wind_from_east;
|
||||
entity.wind_from_north = IC.wind_from_north;
|
||||
entity.wind = sm->wind;
|
||||
int rval = ai->createBallistic( &entity );
|
||||
|
||||
//cout << "Submodel created." << endl;
|
||||
if (sm->count > 0) (sm->count)--;
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
#include <simgear/props/props.hxx>
|
||||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
#include <AIModel/AIManager.hxx>
|
||||
#include <AIModel/AIBase.hxx>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
SG_USING_STD(vector);
|
||||
|
|
|
@ -258,20 +258,20 @@ void FGAISchedule::update(time_t now)
|
|||
string flightPlanName = dep->id + string("-") + arr->id +
|
||||
string(".xml");
|
||||
|
||||
FGAIFlightPlan* f;
|
||||
f = new FGAIFlightPlan(flightPlanName,
|
||||
lat,
|
||||
lon,
|
||||
i->getCruiseAlt() * 100, // convert from FL to feet
|
||||
//speed,
|
||||
450,
|
||||
courseToDest,
|
||||
dep,
|
||||
arr);
|
||||
FGAIModelEntity entity;
|
||||
|
||||
entity.m_class = "jet_transport";
|
||||
entity.path = modelPath.c_str();
|
||||
entity.flightplan = flightPlanName.c_str();
|
||||
entity.latitude = lat;
|
||||
entity.longitude = lon;
|
||||
entity.altitude = i->getCruiseAlt() * 100; // convert from FL to feet
|
||||
entity.speed = 450;
|
||||
entity.fp = new FGAIFlightPlan(&entity, courseToDest, dep, arr);
|
||||
|
||||
// Fixme: A non-existent model path results in an
|
||||
// abort, due to an unhandled exeption, in fg main loop.
|
||||
AIManagerRef = aimgr->createAircraft("jet_transport",
|
||||
modelPath, f);
|
||||
AIManagerRef = aimgr->createAircraft( &entity );
|
||||
//cerr << "Created: " << AIManagerRef << endl;
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
#include <simgear/xml/easyxml.hxx>
|
||||
|
||||
#include <AIModel/AIFlightPlan.hxx>
|
||||
#include <AIModel/AIManager.hxx>
|
||||
#include <AIModel/AIBase.hxx>
|
||||
#include <Airports/simple.hxx>
|
||||
#include <Main/fg_init.hxx> // That's pretty ugly, but I need fgFindAirportID
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue