#endif
#include <cstdlib>
+#include <cstdio>
#include "AIFlightPlan.hxx"
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/props/props.hxx>
#include <simgear/props/props_io.hxx>
-#include <Airports/simple.hxx>
+#include <Airports/airport.hxx>
#include <Airports/runways.hxx>
#include <Airports/dynamics.hxx>
+#include <Airports/groundnetwork.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;
/* FGAIFlightPlan::create()
* dynamically create a flight plan for AI traffic, based on data provided by the
SG_LOG(SG_AI, SG_ALERT,
"AIFlightPlan::create() attempting to create unknown leg"
" this is probably an internal program error");
+ break;
}
wpt_iterator = waypoints.begin() + currWpt;
//don't increment leg right away, but only once we pass the actual last waypoint that was created.
const string & acType,
const string & airline)
{
-
+ int route;
// If this function is called during initialization,
// make sure we obtain a valid gate ID first
// and place the model at the location of the gate.
}
}
- string rwyClass = getRunwayClassFromTrafficType(fltType);
+ const string& rwyClass = getRunwayClassFromTrafficType(fltType);
// Only set this if it hasn't been set by ATC already.
if (activeRunway.empty()) {
return true;
}
- intVec ids;
- PositionedID runwayId = 0;
+ FGTaxiNodeRef runwayNode;
if (gn->getVersion() > 0) {
- runwayId = gn->findNearestNodeOnRunway(runwayTakeoff);
+ FGTaxiNodeRef runwayNode = gn->findNearestNodeOnRunway(runwayTakeoff);
} else {
- runwayId = gn->findNearestNode(runwayTakeoff);
+ FGTaxiNodeRef runwayNode = gn->findNearestNode(runwayTakeoff);
}
// A negative gateId indicates an overflow parking, use a
// taxiRoute = new FGTaxiRoute;
// Determine which node to start from.
- PositionedID node = 0;
+ FGTaxiNodeRef node;
// Find out which node to start from
FGParking *park = gate.parking();
if (park) {
node = park->getPushBackPoint();
- if (node == -1) {
- node = park->guid();
- } else if (node == 0) {
- // HAndle case where parking doens't have a node
+ if (node == 0) {
+ // Handle case where parking doesn't have a node
if (firstFlight) {
- node = park->guid();
+ node = park;
} else {
node = lastNodeVisited;
}
}
}
- FGTaxiRoute taxiRoute = gn->findShortestRoute(node, runwayId);
- intVecIterator i;
+ FGTaxiRoute taxiRoute;
+ if ( runwayNode )
+ taxiRoute = gn->findShortestRoute(node, runwayNode);
if (taxiRoute.empty()) {
createDefaultTakeoffTaxi(ac, apt, rwy);
}
taxiRoute.first();
+ FGTaxiNodeRef skipNode;
+
//bool isPushBackPoint = false;
if (firstFlight) {
// If this is called during initialization, randomly
// but make sure we always keep two active waypoints
// to prevent a segmentation fault
for (int i = 0; i < nrWaypointsToSkip - 3; i++) {
- taxiRoute.next(&node);
+ taxiRoute.next(skipNode, &route);
}
gate.release(); // free up our gate as required
} else {
if (taxiRoute.size() > 1) {
- taxiRoute.next(&node); // chop off the first waypoint, because that is already the last of the pushback route
+ taxiRoute.next(skipNode, &route); // chop off the first waypoint, because that is already the last of the pushback route
}
}
// push each node on the taxi route as a waypoint
- // int route;
+
//cerr << "Building taxi route" << endl;
- while (taxiRoute.next(&node)) {
+
+ // Note that the line wpt->setRouteIndex was commented out by revision [afcdbd] 2012-01-01,
+ // which breaks the rendering functions.
+ // These can probably be generated on the fly however.
+ while (taxiRoute.next(node, &route)) {
char buffer[10];
- snprintf(buffer, 10, "%ld", node);
- FGTaxiNode *tn =
- apt->getDynamics()->getGroundNetwork()->findNode(node);
+ snprintf(buffer, 10, "%d", node->getIndex());
FGAIWaypoint *wpt =
- createOnGround(ac, buffer, tn->geod(), apt->getElevation(),
+ createOnGround(ac, buffer, node->geod(), apt->getElevation(),
ac->getPerformance()->vTaxi());
- // wpt->setRouteIndex(route);
+ wpt->setRouteIndex(route);
//cerr << "Nodes left " << taxiRoute->nodesLeft() << " ";
if (taxiRoute.nodesLeft() == 1) {
// Note that we actually have hold points in the ground network, but this is just an initial test.
const string & acType,
const string & airline)
{
+ int route;
gate = apt->getDynamics()->getAvailableParking(radius, fltType,
acType, airline);
return true;
}
- intVec ids;
- PositionedID runwayId = 0;
+ FGTaxiNodeRef runwayNode;
if (gn->getVersion() == 1) {
- runwayId = gn->findNearestNodeOnRunway(lastWptPos);
+ runwayNode = gn->findNearestNodeOnRunway(lastWptPos);
} else {
- runwayId = gn->findNearestNode(lastWptPos);
+ runwayNode = gn->findNearestNode(lastWptPos);
}
//cerr << "Using network node " << runwayId << endl;
// A negative gateId indicates an overflow parking, use a
// fallback mechanism for this.
- // Starting from gate 0 is a bit of a hack...
- //FGTaxiRoute route;
- // delete taxiRoute;
- // taxiRoute = new FGTaxiRoute;
+ // Starting from gate 0 doesn't work, so don't try it
FGTaxiRoute taxiRoute;
if (gate.isValid())
- taxiRoute = gn->findShortestRoute(runwayId, gate.parking()->guid());
- else
- taxiRoute = gn->findShortestRoute(runwayId, 0);
- intVecIterator i;
+ taxiRoute = gn->findShortestRoute(runwayNode, gate.parking());
if (taxiRoute.empty()) {
createDefaultLandingTaxi(ac, apt);
return true;
}
- PositionedID node;
+ FGTaxiNodeRef node;
taxiRoute.first();
int size = taxiRoute.size();
// Omit the last two waypoints, as
// those are created by createParking()
// int route;
for (int i = 0; i < size - 2; i++) {
- taxiRoute.next(&node);
+ taxiRoute.next(node, &route);
char buffer[10];
- snprintf(buffer, 10, "%ld", node);
- FGTaxiNode *tn = gn->findNode(node);
+ snprintf(buffer, 10, "%d", node->getIndex());
FGAIWaypoint *wpt =
- createOnGround(ac, buffer, tn->geod(), apt->getElevation(),
+ createOnGround(ac, buffer, node->geod(), apt->getElevation(),
ac->getPerformance()->vTaxi());
- // wpt->setRouteIndex(route);
+
+ wpt->setRouteIndex(route);
pushBackWaypoint(wpt);
}
return true;
// NOTE: DT (2009-01-18: IIRC, this is currently already the case,
// because the getActive runway function takes care of that.
if (firstFlight) {
- string rwyClass = getRunwayClassFromTrafficType(fltType);
+ const string& rwyClass = getRunwayClassFromTrafficType(fltType);
double heading = ac->getTrafficRef()->getCourse();
apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway,
heading);
double vClimb = ac->getPerformance()->vClimb();
if (firstFlight) {
- string rwyClass = getRunwayClassFromTrafficType(fltType);
+ const string& rwyClass = getRunwayClassFromTrafficType(fltType);
double heading = ac->getTrafficRef()->getCourse();
apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway,
heading);
double vApproach = ac->getPerformance()->vApproach();
//Beginning of Descent
- string rwyClass = getRunwayClassFromTrafficType(fltType);
+ const string& rwyClass = getRunwayClassFromTrafficType(fltType);
double heading = ac->getTrafficRef()->getCourse();
apt->getDynamics()->getActiveRunway(rwyClass, 2, activeRunway,
heading);
}
double dAlt = 0; // = alt - (apt->getElevation() + 2000);
- FGTaxiNode * tn = 0;
+ FGTaxiNodeRef tn;
if (apt->getDynamics()->getGroundNetwork()) {
- int node = apt->getDynamics()->getGroundNetwork()->findNearestNode(refPoint);
- tn = apt->getDynamics()->getGroundNetwork()->findNode(node);
+ tn = apt->getDynamics()->getGroundNetwork()->findNearestNode(refPoint);
}
if (tn) {
if (reposition) {
double tempDistance;
//double minDistance = HUGE_VAL;
- string wptName;
+ //string wptName;
tempDistance = SGGeodesy::distanceM(current, initialTarget);
time_t eta =
tempDistance / ((vDescent * SG_NM_TO_METER) / 3600.0) + now;
}
coord = rwy->pointOnCenterline(mindist);
- int nodeId = 0;
+ FGTaxiNodeRef tn;
if (gn->getVersion() > 0) {
- nodeId = gn->findNearestNodeOnRunway(coord, rwy);
+ tn = gn->findNearestNodeOnRunway(coord, rwy);
} else {
- nodeId = gn->findNearestNode(coord);
+ tn = gn->findNearestNode(coord);
}
- FGTaxiNode* tn = gn->findNode(nodeId);
if (tn) {
wpt = createOnGround(ac, buffer, tn->geod(), currElev, vTaxi);
pushBackWaypoint(wpt);
* - ul (ultralight: I can imagine that these may share a runway with ga on some airports)
* - mil (all military traffic)
*/
-string FGAIFlightPlan::getRunwayClassFromTrafficType(string fltType)
+const char* FGAIFlightPlan::getRunwayClassFromTrafficType(const string& fltType)
{
if ((fltType == "gate") || (fltType == "cargo")) {
- return string("com");
+ return "com";
}
if (fltType == "ga") {
- return string("gen");
+ return "gen";
}
if (fltType == "ul") {
- return string("ul");
+ return "ul";
}
if ((fltType == "mil-fighter") || (fltType == "mil-transport")) {
- return string("mil");
+ return "mil";
}
- return string("com");
+ return "com";
}