- SGPropertyNode* root = fgGetNode("sim/ai", true);
- if (!root->getNode("enabled", true)->getBoolValue())
- return 0;
-
- bool found = false;
- string filename = root->getNode("scenario", true)->getStringValue();
- FGAIScenario* s = new FGAIScenario( filename );
- for (int i=0; i<s->nEntries(); i++) {
- FGAIModelEntity* en = s->getNextEntry();
- if (en && en->m_type == "carrier" &&
- (en->pennant_number == id || en->name == id)) {
- FGAICarrier* ai_carrier = new FGAICarrier(0);
- ai_carrier->setHeading(en->heading);
- ai_carrier->setSpeed(en->speed);
- ai_carrier->setAltitude(en->altitude);
- ai_carrier->setLongitude(en->longitude);
- ai_carrier->setLatitude(en->latitude);
- ai_carrier->setBank(en->rudder);
- ai_carrier->setParkingPositions(en->ppositions);
-
- if (ai_carrier->getParkPosition(pid, geodPos, heading, uvw)) {
- delete ai_carrier;
- found = true;
- break;
- }
-
- delete ai_carrier;
+ // we specify tgt extent (ft) according to the AIObject type
+ double tgt_ht[] = {0, 50 ,100, 250, 0, 100, 0, 0, 50, 50};
+ double tgt_length[] = {0, 100, 200, 750, 0, 50, 0, 0, 200, 100};
+
+ ai_list_iterator ai_list_itr = ai_list.begin();
+ ai_list_iterator end = ai_list.end();
+
+ while (ai_list_itr != end) {
+ double tgt_alt = (*ai_list_itr)->_getAltitude();
+ int type = (*ai_list_itr)->getType();
+ tgt_ht[type] += fuse_range;
+
+ if (fabs(tgt_alt - alt) > tgt_ht[type] || type == FGAIBase::otBallistic
+ || type == FGAIBase::otStorm || type == FGAIBase::otThermal) {
+ SG_LOG(SG_GENERAL, SG_DEBUG, "AIManager: skipping "
+ << fabs(tgt_alt - alt)
+ << " "
+ << type
+ );
+ ++ai_list_itr;
+ continue;
+ }
+
+ double tgt_lat = (*ai_list_itr)->_getLatitude();
+ double tgt_lon = (*ai_list_itr)->_getLongitude();
+ int id = (*ai_list_itr)->getID();
+
+ double range = calcRange(lat, lon, tgt_lat, tgt_lon);
+
+ SG_LOG(SG_GENERAL, SG_DEBUG, "AIManager: AI list size "
+ << ai_list.size()
+ << " type " << type
+ << " ID " << id
+ << " range " << range
+ //<< " bearing " << bearing
+ << " alt " << tgt_alt
+ );
+
+ tgt_length[type] += fuse_range;
+
+ if (range < tgt_length[type]){
+ SG_LOG(SG_GENERAL, SG_DEBUG, "AIManager: HIT! "
+ << " type " << type
+ << " ID " << id
+ << " range " << range
+ << " alt " << tgt_alt
+ );
+ return (*ai_list_itr).get();
+ }
+ ++ai_list_itr;