#include <Airports/dynamics.hxx>
#include <Airports/airport.hxx>
#include <Main/util.hxx>
+#include <Traffic/Schedule.hxx>
#include <simgear/structure/exception.hxx>
// defined in AIShip.cxx
extern double fgIsFinite(double x);
+#include "AIManager.hxx"
#include "AIAircraft.hxx"
+#include "AIFlightPlan.hxx"
#include "performancedata.hxx"
#include "performancedb.hxx"
#include <signal.h>
Transform();
}
+void FGAIAircraft::unbind()
+{
+ FGAIBase::unbind();
+ clearATCController();
+}
+
void FGAIAircraft::setPerformance(const std::string& acType, const std::string& acclass)
{
static PerformanceDB perfdb; //TODO make it a global service
return vs;
}
+void FGAIAircraft::clearATCController()
+{
+ controller = 0;
+ prevController = 0;
+ towerController = 0;
+}
+
void FGAIAircraft::assertSpeed(double speed)
{
if ((speed < -50) || (speed > 1000)) {
#ifndef _FG_AIAircraft_HXX
#define _FG_AIAircraft_HXX
-#include "AIManager.hxx"
#include "AIBase.hxx"
-#include <Traffic/SchedFlight.hxx>
-#include <Traffic/Schedule.hxx>
-#include <ATC/trafficcontrol.hxx>
-
#include <string>
class PerformanceData;
+class FGAISchedule;
+class FGAIFlightPlan;
+class FGATCController;
+class FGATCInstruction;
+class FGAIWaypoint;
class FGAIAircraft : public FGAIBase {
// virtual bool init(bool search_in_AI_path=false);
virtual void bind();
virtual void update(double dt);
+ virtual void unbind();
void setPerformance(const std::string& acType, const std::string& perfString);
// void setPerformance(PerformanceData *ps);
FGATCController * getATCController() { return controller; };
+ void clearATCController();
protected:
void Run(double dt);
private:
FGAISchedule *trafficRef;
- FGATCController *controller,
+ FGATCController *controller,
*prevController,
*towerController; // Only needed to make a pre-announcement
#include <Main/util.hxx>
#include <Environment/gravity.hxx>
+#include <Main/fg_props.hxx>
using namespace simgear;
using std::string;
#include <simgear/props/props.hxx>
#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
#include <Scenery/scenery.hxx>
#include <Scripting/NasalSys.hxx>
#include <Scripting/NasalModelData.hxx>
#include <Sound/fg_fx.hxx>
+#include "AIFlightPlan.hxx"
#include "AIBase.hxx"
#include "AIManager.hxx"
return;
FGScenery* pSceneryManager = globals->get_scenery();
- if (pSceneryManager)
+ if (pSceneryManager && pSceneryManager->get_models_branch())
{
osg::ref_ptr<osg::Object> temp = _model.get();
pSceneryManager->get_models_branch()->removeChild(aip.getSceneGraph());
#include <simgear/math/sg_geodesy.hxx>
-#include <Main/fg_props.hxx>
-
namespace osg { class PagedLOD; }
namespace simgear {
std::string & getCallSign();
};
+typedef SGSharedPtr<FGAIBase> FGAIBasePtr;
+
inline void FGAIBase::setManager(FGAIManager* mgr, SGPropertyNode* p) {
manager = mgr;
props = p;
#include <cmath>
#include <Main/util.hxx>
+#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
#include "AICarrier.hxx"
#include <cmath>
#include <Main/util.hxx>
+#include <Main/globals.hxx>
#include <Viewer/viewer.hxx>
#include <Scenery/scenery.hxx>
#include <Environment/environment_mgr.hxx>
#include <Environment/environment.hxx>
+#include <Traffic/Schedule.hxx>
+
#include "AIFlightPlan.hxx"
#include "AIAircraft.hxx"
#include "AIAircraft.hxx"
#include "performancedata.hxx"
+#include <Main/fg_props.hxx>
#include <Environment/environment_mgr.hxx>
#include <Environment/environment.hxx>
#include <FDM/LaRCsim/basic_aero.h>
#include <Navaids/navrecord.hxx>
+#include <Traffic/Schedule.hxx>
using std::string;
#include <Environment/environment_mgr.hxx>
#include <Environment/environment.hxx>
+#include <Traffic/Schedule.hxx>
+
#include "AIFlightPlan.hxx"
#include "AIAircraft.hxx"
#include "performancedata.hxx"
#include <Viewer/viewer.hxx>
#include <Scenery/scenery.hxx>
#include <Airports/dynamics.hxx>
+#include <Main/globals.hxx>
#include "AIGroundVehicle.hxx"
#include <boost/foreach.hpp>
#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
#include <Airports/airport.hxx>
#include <Scripting/NasalSys.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
-#include <simgear/props/props_io.hxx>
-
-#include <Main/fg_props.hxx>
-
-#include <AIModel/AIBase.hxx>
-#include <AIModel/AIFlightPlan.hxx>
-
-#include <Traffic/SchedFlight.hxx>
-#include <Traffic/Schedule.hxx>
+class FGAIBase;
class FGAIThermal;
typedef SGSharedPtr<FGAIBase> FGAIBasePtr;
* corresponding AIObject implementation, or NULL.
*/
FGAIBasePtr getObjectFromProperty(const SGPropertyNode* aProp) const;
+
+ static const char* subsystemName() { return "ai-model"; }
private:
// FGSubmodelMgr is a friend for access to the AI_list
friend class FGSubmodelMgr;
#include <string>
#include <stdio.h>
+#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
+
#include "AIMultiplayer.hxx"
using std::string;
#include <simgear/scene/util/SGNodeMasks.hxx>
#include <Scenery/scenery.hxx>
+#include <Main/globals.hxx>
#include "AIShip.hxx"
#include <simgear/sg_inlines.h>
+#include <Main/fg_props.hxx>
#include "AIWingman.hxx"
#include <Airports/runways.hxx>
#include <Airports/groundnetwork.hxx>
+#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
#include <AIModel/AIAircraft.hxx>
#include <AIModel/performancedata.hxx>
#include <AIModel/AIFlightPlan.hxx>
#include <Airports/airportdynamicsmanager.hxx>
#include <Airports/airport.hxx>
#include <Scenery/scenery.hxx>
+#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
+#include <AIModel/AIAircraft.hxx>
+#include <Traffic/Schedule.hxx>
+#include <Traffic/SchedFlight.hxx>
+#include <AIModel/AIFlightPlan.hxx>
+
#include "atc_mgr.hxx"
double speed = fgGetDouble("/velocities/groundspeed-kt");
double aircraftRadius = 40; // note that this is currently hardcoded to a one-size-fits all JumboJet value. Should change later;
-
- ai_ac.setCallSign ( callsign );
- ai_ac.setLongitude( longitude );
- ai_ac.setLatitude ( latitude );
- ai_ac.setAltitude ( altitude );
- ai_ac.setPerformance("", "jet_transport");
+ ai_ac = new FGAIAircraft;
+ ai_ac->setCallSign ( callsign );
+ ai_ac->setLongitude( longitude );
+ ai_ac->setLatitude ( latitude );
+ ai_ac->setAltitude ( altitude );
+ ai_ac->setPerformance("", "jet_transport");
// NEXT UP: Create a traffic Schedule and fill that with appropriate information. This we can use to flight planning.
// Note that these are currently only defaults.
trafficRef->assign(flight);
FGAIFlightPlan *fp = 0;
- ai_ac.setTrafficRef(trafficRef);
+ ai_ac->setTrafficRef(trafficRef);
string flightPlanName = airport + "-" + airport + ".xml";
//double cruiseAlt = 100; // Doesn't really matter right now.
string aircraftType; // Unused.
string airline; // Currently used for gate selection, but a fallback mechanism will apply when not specified.
fp->setGate(pk);
- if (!(fp->createPushBack(&ai_ac,
+ if (!(fp->createPushBack(ai_ac,
false,
dcs->parent(),
aircraftRadius,
leg = 3;
string fltType = "ga";
fp->setRunway(runway);
- fp->createTakeOff(&ai_ac, false, dcs->parent(), 0, fltType);
- ai_ac.setTakeOffStatus(2);
+ fp->createTakeOff(ai_ac, false, dcs->parent(), 0, fltType);
+ ai_ac->setTakeOffStatus(2);
} else {
// We're on the ground somewhere. Handle this case later.
}
if (fp) {
fp->restart();
fp->setLeg(leg);
- ai_ac.SetFlightPlan(fp);
+ ai_ac->SetFlightPlan(fp);
}
if (controller) {
- controller->announcePosition(ai_ac.getID(), fp, fp->getCurrentWaypoint()->getRouteIndex(),
- ai_ac._getLatitude(), ai_ac._getLongitude(), heading, speed, altitude,
- aircraftRadius, leg, &ai_ac);
+ controller->announcePosition(ai_ac->getID(), fp, fp->getCurrentWaypoint()->getRouteIndex(),
+ ai_ac->_getLatitude(), ai_ac->_getLongitude(), heading, speed, altitude,
+ aircraftRadius, leg, ai_ac);
//dialog.init();
//cerr << "Adding groundnetWork to the scenegraph::init" << endl;
//globals->get_scenery()->get_scene_graph()->addChild(node);
}
- initSucceeded = true;
+ initSucceeded = true;
+}
+
+void FGATCManager::shutdown()
+{
+ delete ai_ac;
+ ai_ac = NULL;
+ activeStations.clear();
}
void FGATCManager::addController(FGATCController *controller) {
- FGAIFlightPlan *fp = ai_ac.GetFlightPlan();
+ FGAIFlightPlan *fp = ai_ac->GetFlightPlan();
/* test code : find out how the routing develops */
if (fp) {
cerr << "Bearing to nearest waypoint : " << course1 << " " << dist1 << ". (course " << course2 << ")." << endl;
*/
- ai_ac.setLatitude(latitude);
- ai_ac.setLongitude(longitude);
- ai_ac.setAltitude(altitude);
- ai_ac.setHeading(heading);
- ai_ac.setSpeed(speed);
- ai_ac.update(time);
- controller = ai_ac.getATCController();
+ ai_ac->setLatitude(latitude);
+ ai_ac->setLongitude(longitude);
+ ai_ac->setAltitude(altitude);
+ ai_ac->setHeading(heading);
+ ai_ac->setSpeed(speed);
+ ai_ac->update(time);
+ controller = ai_ac->getATCController();
FGATCDialogNew::instance()->update(time);
if (controller) {
//cerr << "name of previous waypoint : " << fp->getPreviousWaypoint()->getName() << endl;
//cerr << "Running FGATCManager::update()" << endl;
//cerr << "Currently under control of " << controller->getName() << endl;
- controller->updateAircraftInformation(ai_ac.getID(),
+ controller->updateAircraftInformation(ai_ac->getID(),
latitude,
longitude,
heading,
#ifndef _ATC_MGR_HXX_
#define _ATC_MGR_HXX_
-//#include <simgear/structure/SGReferenced.hxx>
-//#include <simgear/structure/SGSharedPtr.hxx>
+
#include <simgear/structure/subsystem_mgr.hxx>
#include <ATC/trafficcontrol.hxx>
#include <ATC/atcdialog.hxx>
-#include <AIModel/AIAircraft.hxx>
-//class FGATCController;
+class FGAIAircraft;
typedef std::vector<FGATCController*> AtcVec;
{
private:
AtcVec activeStations;
- FGAIAircraft ai_ac;
+ FGAIAircraft* ai_ac;
FGATCController *controller, *prevController; // The ATC controller that is responsible for the user's aircraft.
bool networkVisible;
bool initSucceeded;
FGATCManager();
~FGATCManager();
void init();
+ virtual void shutdown();
+
void addController(FGATCController *controller);
void removeController(FGATCController* controller);
void update(double time);
#include <Navaids/routePath.hxx>
#include <Aircraft/FlightHistory.hxx>
#include <AIModel/AIAircraft.hxx>
+#include <AIModel/AIManager.hxx>
#include <AIModel/AIFlightPlan.hxx>
const char* RULER_LEGEND_KEY = "ruler-legend";
// try to access the flight-plan of the aircraft. There are several layers
// of potential NULL-ness here, so we have to be defensive at each stage.
std::string originICAO, destinationICAO;
- FGAIManager* aiManager = static_cast<FGAIManager*>(globals->get_subsystem("ai-model"));
+ FGAIManager* aiManager = globals->get_subsystem<FGAIManager>();
FGAIBasePtr aircraft = aiManager ? aiManager->getObjectFromProperty(model) : NULL;
if (aircraft) {
FGAIAircraft* p = static_cast<FGAIAircraft*>(aircraft.get());
string_list::const_iterator it;
for (it = names.begin(); it != names.end(); ++it) {
if ((*it == "time") || (*it == "terrasync") || (*it == "events")
- || (*it == "lighting"))
+ || (*it == "lighting") || (*it == FGTileMgr::subsystemName()) || (*it == FGScenery::subsystemName()))
{
continue;
}
#ifndef REMOTEXMLREQUEST_HXXH
#define REMOTEXMLREQUEST_HXXH
+
#include <simgear/structure/exception.hxx>
#include <simgear/io/HTTPMemoryRequest.hxx>
+#include <simgear/props/props_io.hxx>
+
class RemoteXMLRequest:
public simgear::HTTP::MemoryRequest
{
FGTileMgr::~FGTileMgr()
{
- delete _listener;
-
- // remove all nodes we might have left behind
- osg::Group* group = globals->get_scenery()->get_terrain_branch();
- group->removeChildren(0, group->getNumChildren());
- // clear OSG cache
- osgDB::Registry::instance()->clearObjectCache();
-}
+ }
// Initialize the Tile Manager subsystem
reinit();
}
+void FGTileMgr::shutdown()
+{
+ delete _listener;
+ _listener = NULL;
+
+ FGScenery* scenery = globals->get_scenery();
+ if (scenery && scenery->get_terrain_branch()) {
+ osg::Group* group = scenery->get_terrain_branch();
+ group->removeChildren(0, group->getNumChildren());
+ }
+ // clear OSG cache
+ osgDB::Registry::instance()->clearObjectCache();
+ state = Start; // need to init again
+}
+
void FGTileMgr::reinit()
{
SG_LOG( SG_TERRAIN, SG_INFO, "Initializing Tile Manager subsystem." );
// Initialize the Tile Manager
virtual void init();
virtual void reinit();
+ virtual void shutdown();
+
virtual void update(double dt);
const SGBucket& get_current_bucket () const { return current_bucket; }
#include <AIModel/AIFlightPlan.hxx>
#include <AIModel/AIManager.hxx>
#include <Airports/airport.hxx>
-#include <Main/fg_init.hxx> // That's pretty ugly, but I need fgFindAirportID
#include <AIModel/AIManager.hxx>
#include <AIModel/AIAircraft.hxx>
#include <Airports/airport.hxx>
-#include <Main/fg_init.hxx> // That's pretty ugly, but I need fgFindAirportID
-
+#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
#include "SchedFlight.hxx"
#include "TrafficMgr.hxx"
courseToDest = SGGeodesy::courseDeg((*flights.begin())->getDepartureAirport()->geod(), (*flights.begin())->getArrivalAirport()->geod());
}
+void FGAISchedule::assign(FGScheduledFlight *ref) { flights.push_back(ref); }
+
bool FGAISchedule::scheduleFlights(time_t now)
{
- //string startingPort;
- const string& userPort = fgGetString("/sim/presets/airport-id");
+ //string startingPort;
+ const string& userPort = fgGetString("/sim/presets/airport-id");
SG_LOG(SG_AI, SG_BULK, "Scheduling Flights for : " << modelPath << " " << registration << " " << homePort);
FGScheduledFlight *flight = NULL;
SGTimeStamp start;
return true;
}
+time_t FGAISchedule::getDepartureTime() { return (*flights.begin())->getDepartureTime (); }
+
+FGAirport *FGAISchedule::getDepartureAirport() { return (*flights.begin())->getDepartureAirport(); }
+
+FGAirport *FGAISchedule::getArrivalAirport() { return (*flights.begin())->getArrivalAirport (); }
+
+int FGAISchedule::getCruiseAlt() { return (*flights.begin())->getCruiseAlt (); }
+
+const std::string &FGAISchedule::getCallSign() { return (*flights.begin())->getCallSign (); }
+
+const std::string &FGAISchedule::getFlightRules() { return (*flights.begin())->getFlightRules (); }
+
FGScheduledFlight* FGAISchedule::findAvailableFlight (const string ¤tDestination,
const string &req,
time_t min, time_t max)
// forward decls
class FGAIAircraft;
+class FGScheduledFlight;
+
+typedef std::vector<FGScheduledFlight*> FGScheduledFlightVec;
class FGAISchedule
{
bool next(); // forces the schedule to move on to the next flight.
// TODO: rework these four functions
- time_t getDepartureTime () { return (*flights.begin())->getDepartureTime (); };
- FGAirport * getDepartureAirport () { return (*flights.begin())->getDepartureAirport(); };
- FGAirport * getArrivalAirport () { return (*flights.begin())->getArrivalAirport (); };
- int getCruiseAlt () { return (*flights.begin())->getCruiseAlt (); };
+ time_t getDepartureTime ();
+ FGAirport * getDepartureAirport ();
+ FGAirport * getArrivalAirport ();
+ int getCruiseAlt ();
double getRadius () { return radius; };
double getGroundOffset () { return groundOffset;};
const std::string& getFlightType () { return flightType;};
const std::string& getAirline () { return airline; };
const std::string& getAircraft () { return acType; };
- const std::string& getCallSign () { return (*flights.begin())->getCallSign (); };
+ const std::string& getCallSign ();
const std::string& getRegistration () { return registration;};
- const std::string& getFlightRules () { return (*flights.begin())->getFlightRules (); };
+ const std::string& getFlightRules ();
bool getHeavy () { return heavy; };
double getCourse () { return courseToDest; };
unsigned int getRunCount () { return runCount; };
void setScore ();
double getScore () { return score; };
void setHeading ();
- void assign (FGScheduledFlight *ref) { flights.push_back(ref); };
+ void assign (FGScheduledFlight *ref);
void setFlightType (const std::string& val) { flightType = val; };
FGScheduledFlight*findAvailableFlight (const std::string& currentDestination, const std::string &req, time_t min=0, time_t max=0);
// used to sort in descending order of score: I've probably found a better way to
#include <AIModel/AIBase.hxx>
#include <Airports/airport.hxx>
#include <Main/fg_init.hxx>
+#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
#include "TrafficMgr.hxx"
mutable SGMutex _lock;
bool _isFinished;
bool _cancelThread;
- PathList _trafficDirPaths;
+ simgear::PathList _trafficDirPaths;
// parser state
doingInit = true;
if (string(fgGetString("/sim/traffic-manager/datafile")).empty()) {
- PathList dirs = globals->get_data_paths("AI/Traffic");
+ simgear::PathList dirs = globals->get_data_paths("AI/Traffic");
// temporary flag to restrict loading while traffic data is found
// through terrasync /and/ fgdata. Ultimatley we *do* want to be able to