*
* 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
{
firstRun = true;
AIManagerRef = 0;
+
+ heavy = false;
+ lat = 0;
+ lon = 0;
+ radius = 0;
+ groundOffset = 0;
+ distanceToUser = 0;
}
FGAISchedule::FGAISchedule(string mdl,
airline = arln;
m_class = mclass;
flightType = fltpe;
+ lat = 0;
+ lon = 0;
radius = rad;
groundOffset = grnd;
+ distanceToUser = 0;
heavy = hvy;
for (FGScheduledFlightVecIterator i = flt.begin();
i != flt.end();
// 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.
- AIManagerRef = aimgr->createAircraft( &entity, this);
- //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;
}
return true;
}
}
+ //cerr << "Traffic schedule got to beyond last clause" << endl;
+ // EMH: prevent a warning, should this be 'true' instead?
+ // DT: YES. Originally, this code couldn't be reached, but
+ // when the "if(!(AIManagerManager))" clause is false we
+ // fall through right to the end. This is a valid flow.
+ // the actual value is pretty innocent, only it triggers
+ // warning in TrafficManager::update().
+ // (which was added as a sanity check for myself in the first place. :-)
+ return true;
}
FGAirport *dep;
-#ifdef __CYGWIN__
+#if defined( __CYGWIN__) || defined( __MINGW32__)
#define HUGE HUGE_VAL
#endif
distanceToUser = HUGE;