contactTower = false;
contactGround = false;
_taxiToGA = false;
+ _removeSelf = false;
descending = false;
targetDescentRate = 0.0;
_savedSlope = 0.0;
_controlled = false;
+
+ _invisible = false;
}
FGAILocalTraffic::~FGAILocalTraffic() {
FGRunway runway;
bool rwyGood = globals->get_runways()->search(id, rwy.rwyID, &runway);
if(rwyGood) {
- double hdg = runway.heading;
+ double hdg = runway._heading;
double other_way = hdg - 180.0;
while(other_way <= 0.0) {
other_way += 360.0;
}
// move to the +l end/center of the runway
- //cout << "Runway center is at " << runway.lon << ", " << runway.lat << '\n';
- Point3D origin = Point3D(runway.lon, runway.lat, aptElev);
+ //cout << "Runway center is at " << runway._lon << ", " << runway._lat << '\n';
+ Point3D origin = Point3D(runway._lon, runway._lat, aptElev);
Point3D ref = origin;
double tshlon, tshlat, tshr;
double tolon, tolat, tor;
- rwy.length = runway.length * SG_FEET_TO_METER;
- rwy.width = runway.width * SG_FEET_TO_METER;
+ rwy.length = runway._length * SG_FEET_TO_METER;
+ rwy.width = runway._width * SG_FEET_TO_METER;
geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), other_way,
rwy.length / 2.0 - 25.0, &tshlat, &tshlon, &tshr );
geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), hdg,
// Run the internal calculations
void FGAILocalTraffic::Update(double dt) {
//cout << "U" << flush;
+
+ // we shouldn't really need this since there's a LOD of 10K on the whole plane anyway I think.
+ // At the moment though I need to to avoid DList overflows - the whole plane LOD obviously isn't getting picked up.
+ if(!_invisible) {
+ if(dclGetHorizontalSeparation(_pos, Point3D(fgGetDouble("/position/longitude-deg"), fgGetDouble("/position/latitude-deg"), 0.0)) > 8000) _aip.setVisible(false);
+ else _aip.setVisible(true);
+ } else {
+ _aip.setVisible(false);
+ }
+
//double responseTime = 10.0; // seconds - this should get more sophisticated at some point
responseCounter += dt;
if((contactTower) && (responseCounter >= 8.0)) {
string trns = "GA Parking, Thank you and Good Day";
//double f = globals->get_ATC_mgr()->GetFrequency(airportID, GROUND) / 100.0;
pending_transmission = trns;
- ConditionalTransmit(5.0);
+ ConditionalTransmit(5.0, 99);
+ _taxiToGA = false;
if(_controlled) {
tower->DeregisterAIPlane(plane.callsign);
}
- _taxiToGA = false;
- // HACK - check if we are at a simple airport or not first
- globals->get_AI_mgr()->ScheduleRemoval(plane.callsign);
- }
+ // NOTE - we can't delete this instance yet since then the frequency won't get release when the message display finishes.
+ }
+
+ if((_removeSelf) && (responseCounter >= 8.0)) {
+ _removeSelf = false;
+ // MEGA HACK - check if we are at a simple airport or not first instead of simply hardwiring KEMT as the only non-simple airport.
+ // TODO FIXME TODO FIXME !!!!!!!
+ if(airportID != "KEMT") globals->get_AI_mgr()->ScheduleRemoval(plane.callsign);
+ }
if((changeFreq) && (responseCounter > 8.0)) {
switch(changeFreqType) {
tower->DeregisterAIPlane(plane.callsign);
tuned_station = ground;
freq = (double)ground->get_freq() / 100.0;
- // HACK - check if we are at a simple airport or not first
- // TODO FIXME TODO FIXME !!!!!!!
- if(airportID != "KEMT") globals->get_AI_mgr()->ScheduleRemoval(plane.callsign);
break;
// And to avoid compiler warnings...
case APPROACH: break;
tower->ReportDownwind(plane.callsign);
} else if(code == 13) {
tower->ReportFinal(plane.callsign);
+ } else if(code == 99) { // Flag this instance for deletion
+ responseCounter = 0;
+ _removeSelf = true;
+ SG_LOG(SG_ATC, SG_INFO, "AI local traffic " << plane.callsign << " delete instance callback called.");
}
}
} else {
// Something must have gone wrong with the ground network file - or there is only a rwy here and no exits defined
SG_LOG(SG_ATC, SG_INFO, "No exits found by FGAILocalTraffic from runway " << rwy.rwyID << " at " << airportID << '\n');
- //cout << "No exits found by " << plane.callsign << " from runway " << rwy.rwyID << " at " << airportID << '\n';
+ //if(airportID == "KRHV") cout << "No exits found by " << plane.callsign << " from runway " << rwy.rwyID << " at " << airportID << '\n';
// What shall we do - just remove the plane from sight?
_aip.setVisible(false);
+ _invisible = true;
//cout << "Setting visible false\n";
//tower->ReportRunwayVacated(plane.callsign);
string trns = "Clear of the runway ";