# include <config.h>
#endif
-#include <simgear/math/point3d.hxx>
#include <simgear/route/waypoint.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
updateSecondaryTargetValues(); // target roll, vertical speed, pitch
updateActualState();
UpdateRadar(manager);
+ checkVisibility();
}
+void FGAIAircraft::checkVisibility()
+{
+ double visibility_meters = fgGetDouble("/environment/visibility-m");
+
+ FGViewer* vw = globals->get_current_view();
+ double course, distance;
+
+ SGWayPoint current(pos.getLongitudeDeg(), pos.getLatitudeDeg(), 0);
+ SGWayPoint view (vw->getLongitude_deg(), vw->getLatitude_deg(), 0);
+ view.CourseAndDistance(current, &course, &distance);
+ if (distance > visibility_meters) {
+ //aip.getSGLocation()->set_cur_elev_m(aptElev);
+ //return;
+ invisible = true;
+ } else {
+ invisible = false;
+ }
+}
+
void FGAIAircraft::AccelTo(double speed) {
//TODO let the fp handle this (loading of next leg)
fp->IncrementWaypoint((bool) trafficRef);
if (!(fp->getNextWaypoint()) && trafficRef)
- loadNextLeg();
+ if (!loadNextLeg()) {
+ setDie(true);
+ return;
+ }
prev = fp->getPreviousWaypoint();
curr = fp->getCurrentWaypoint();
}
-void FGAIAircraft::loadNextLeg() {
+bool FGAIAircraft::loadNextLeg() {
int leg;
if ((leg = fp->getLeg()) == 10) {
- trafficRef->next();
+ if (!trafficRef->next()) {
+ return false;
+ }
setCallSign(trafficRef->getCallSign());
- //props->setStringValue("callsign", callsign.c_str());
leg = 1;
fp->setLeg(leg);
}
} else {
double cruiseAlt = trafficRef->getCruiseAlt() * 100;
- fp->create (dep,
+ fp->create (this,
+ dep,
arr,
leg,
- cruiseAlt, //(trafficRef->getCruiseAlt() * 100), // convert from FL to feet
+ cruiseAlt,
trafficRef->getSpeed(),
_getLatitude(),
_getLongitude(),
trafficRef->getFlightType(),
acType,
company);
+ //cerr << "created leg " << leg << " for " << trafficRef->getCallSign() << endl;
}
+ return true;
}
//TODO fp should handle this
fp->IncrementWaypoint(eraseWaypoints);
if (!(fp->getNextWaypoint()) && trafficRef)
- loadNextLeg();
+ if (!loadNextLeg()) {
+ setDie(true);
+ return;
+ }
prev = fp->getPreviousWaypoint(); //first waypoint
curr = fp->getCurrentWaypoint(); //second waypoint
//prev_dist_to_go = dist_to_go;
//if (dist_to_go < lead_dist)
- // cerr << trafficRef->getCallSign() << " Distance : " << dist_to_go << ": Lead distance " << lead_dist << " " << curr->name << endl;
+ // cerr << trafficRef->getCallSign() << " Distance : "
+ // << dist_to_go << ": Lead distance "
+ // << lead_dist << " " << curr->name
+ // << " Ground target speed " << groundTargetSpeed << endl;
+
return dist_to_go < lead_dist;
}
user.CourseAndDistance(current, &course, &distance);
- return ((distance * SG_METER_TO_NM) <= TRAFFICTOAIDIST);
+ return ((distance * SG_METER_TO_NM) <= TRAFFICTOAIDISTTODIE);
}
// This waypoint marks the fact that the aircraft has passed the initial taxi
// departure waypoint, so it can release the parking.
+ //cerr << trafficRef->getCallSign() << " has passed waypoint " << prev->name << " at speed " << speed << endl;
if (prev->name == "PushBackPoint") {
dep->getDynamics()->releaseParking(fp->getGate());
time_t holdUntil = now + 120;