*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*
****************************************************************************
*
*****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <AIModel/AIFlightPlan.hxx>
#include <AIModel/AIManager.hxx>
+#include <AIModel/AIAircraft.hxx>
#include <Airports/simple.hxx>
#include <Main/fg_init.hxx> // That's pretty ugly, but I need fgFindAirportID
// alt = dep->_elevation+19;
// }
- FGAIModelEntity entity;
-
- entity.m_class = m_class; //"jet_transport";
- entity.company = airline; //i->getAirline();
- entity.acType = acType; //i->getAcType();
- entity.path = modelPath.c_str();
- entity.flightplan = flightPlanName.c_str();
- entity.latitude = lat;
- entity.longitude = lon;
- entity.altitude = i->getCruiseAlt() *100; // convert from FL to feet
- entity.speed = speed;
- entity.roll = 0.0;
- entity.fp = new FGAIFlightPlan(&entity, courseToDest, i->getDepartureTime(), dep,
- arr,true, radius, flightType, acType, airline);
-
- // Fixme: A non-existent model path results in an
- // abort, due to an unhandled exeption, in fg main loop.
- FGAIBase *aircraft = (FGAIBase*)aimgr->createAircraft( &entity, this);
- AIManagerRef = aircraft->getID();
- //cerr << "Class: " << m_class << ". acType: " << acType << ". Airline: " << airline << ". Speed = " << speed << ". From " << dep->getId() << " to " << arr->getId() << ". Time Fraction = " << (remainingTimeEnroute/(double) totalTimeEnroute) << endl;
- //cerr << "Latitude : " << lat << ". Longitude : " << lon << endl;
- //cerr << "Dep : " << dep->getLatitude()<< ", "<< dep->getLongitude() << endl;
- //cerr << "Arr : " << arr->getLatitude()<< ", "<< arr->getLongitude() << endl;
- //cerr << "Time remaining = " << (remainingTimeEnroute/3600.0) << endl;
- //cerr << "Total time = " << (totalTimeEnroute/3600.0) << endl;
- //cerr << "Distance remaining = " << distanceToDest*SG_METER_TO_NM << endl;
-
+ // Only allow traffic to be created when the model path exists
+ SGPath mp(globals->get_fg_root());
+ mp.append(modelPath);
+ if (mp.exists())
+ {
+ FGAIAircraft *aircraft = new FGAIAircraft(this);
+ aircraft->setPerformance(m_class); //"jet_transport";
+ aircraft->setCompany(airline); //i->getAirline();
+ aircraft->setAcType(acType); //i->getAcType();
+ aircraft->setPath(modelPath.c_str());
+ //aircraft->setFlightPlan(flightPlanName);
+ aircraft->setLatitude(lat);
+ aircraft->setLongitude(lon);
+ aircraft->setAltitude(i->getCruiseAlt()*100); // convert from FL to feet
+ aircraft->setSpeed(speed);
+ aircraft->setBank(0);
+ aircraft->SetFlightPlan(new FGAIFlightPlan(flightPlanName, courseToDest, i->getDepartureTime(), dep,
+ arr,true, radius, i->getCruiseAlt()*100, lat, lon, speed, flightType, acType, airline));
+ aimgr->attach(aircraft);
+
+
+ AIManagerRef = aircraft->getID();
+ //cerr << "Class: " << m_class << ". acType: " << acType << ". Airline: " << airline << ". Speed = " << speed << ". From " << dep->getId() << " to " << arr->getId() << ". Time Fraction = " << (remainingTimeEnroute/(double) totalTimeEnroute) << endl;
+ //cerr << "Latitude : " << lat << ". Longitude : " << lon << endl;
+ //cerr << "Dep : " << dep->getLatitude()<< ", "<< dep->getLongitude() << endl;
+ //cerr << "Arr : " << arr->getLatitude()<< ", "<< arr->getLongitude() << endl;
+ //cerr << "Time remaining = " << (remainingTimeEnroute/3600.0) << endl;
+ //cerr << "Total time = " << (totalTimeEnroute/3600.0) << endl;
+ //cerr << "Distance remaining = " << distanceToDest*SG_METER_TO_NM << endl;
+ }
+ else
+ {
+ SG_LOG(SG_INPUT, SG_WARN, "TrafficManager: Could not load model " << mp.str());
+ }
}
return true;
}