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