static string tempReg;
- class AI_OutOfSight{};
- class FP_Inactive{};
-
FGAIAircraft::FGAIAircraft(FGAISchedule *ref) : FGAIBase(otAircraft) {
trafficRef = ref;
if (trafficRef) {
void FGAIAircraft::Run(double dt) {
FGAIAircraft::dt = dt;
-
- try {
- updatePrimaryTargetValues(); // target hdg, alt, speed
- }
- catch (AI_OutOfSight) {
- return;
+
+ bool outOfSight = false,
+ flightplanActive = true;
+ updatePrimaryTargetValues(flightplanActive, outOfSight); // target hdg, alt, speed
+ if (outOfSight) {
+ return;
}
- catch (FP_Inactive) {
- //return;
- groundTargetSpeed = 0;
+
+ if (!flightplanActive) {
+ groundTargetSpeed = 0;
}
handleATCRequests(); // ATC also has a word to say
case 4: //Take off tower controller
if (trafficRef->getDepartureAirport()->getDynamics()) {
controller = trafficRef->getDepartureAirport()->getDynamics()->getTowerController();
- //if (trafficRef->getDepartureAirport()->getId() == "EHAM") {
- //string trns = trafficRef->getCallSign() + " at runway " + fp->getRunway() +
- // ". Ready for departure. " + trafficRef->getFlightType() + " to " +
- // trafficRef->getArrivalAirport()->getId();
- //fgSetString("/sim/messages/atc", trns.c_str());
- // if (controller == 0) {
- //cerr << "Error in assigning controller at " << trafficRef->getDepartureAirport()->getId() << endl;
- //}
- //}
} else {
cerr << "Error: Could not find Dynamics at airport : " << trafficRef->getDepartureAirport()->getId() << endl;
}
/**
* Update target values (heading, alt, speed) depending on flight plan or control properties
*/
- void FGAIAircraft::updatePrimaryTargetValues() {
+ void FGAIAircraft::updatePrimaryTargetValues(bool& flightplanActive, bool& aiOutOfSight) {
if (fp) // AI object has a flightplan
{
//TODO make this a function of AIBase
}
if (trafficRef) {
//cerr << trafficRef->getRegistration() << " Setting altitude to " << altitude_ft;
- if (! aiTrafficVisible()) {
+ aiOutOfSight = !aiTrafficVisible();
+ if (aiOutOfSight) {
setDie(true);
//cerr << trafficRef->getRegistration() << " is set to die " << endl;
- throw AI_OutOfSight();
+ aiOutOfSight = true;
+ return;
}
}
timeElapsed = now - fp->getStartTime();
- if (! fp->isActive(now)) {
- throw FP_Inactive();
- }
+ flightplanActive = fp->isActive(now);
} else {
// no flight plan, update target heading, speed, and altitude
// from control properties. These default to the initial