*
* 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 <string>
#include <vector>
+#include <algorithm>
#include <plib/sg.h>
#include <simgear/compiler.h>
#include <simgear/math/polar3d.hxx>
#include <simgear/math/sg_geodesy.hxx>
+#include <simgear/misc/sg_path.hxx>
#include <simgear/props/props.hxx>
#include <simgear/route/waypoint.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/xml/easyxml.hxx>
+#include <AIModel/AIAircraft.hxx>
#include <AIModel/AIFlightPlan.hxx>
#include <AIModel/AIBase.hxx>
#include <Airports/simple.hxx>
#include "TrafficMgr.hxx"
+SG_USING_STD(sort);
/******************************************************************************
* TrafficManager
void FGTrafficManager::init()
-{
+{
+ //cerr << "Initializing Schedules" << endl;
+ time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+ currAircraft = scheduledAircraft.begin();
+ while (currAircraft != scheduledAircraft.end())
+ {
+ if (!(currAircraft->init()))
+ {
+ currAircraft=scheduledAircraft.erase(currAircraft);
+ //cerr << "Erasing " << currAircraft->getRegistration() << endl;
+ }
+ else
+ {
+ currAircraft++;
+ }
+ }
+ //cerr << "Sorting by distance " << endl;
+ sort(scheduledAircraft.begin(), scheduledAircraft.end());
currAircraft = scheduledAircraft.begin();
+ currAircraftClosest = scheduledAircraft.begin();
+ //cerr << "Done initializing schedules" << endl;
}
void FGTrafficManager::update(double something)
{
-
- //static const SGPropertyNode *warp = globals->get_props()->getNode("/sim/time/warp");
-
- //time_t now = time(NULL) + globals->get_warp();
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
- // cerr << "TrafficManager update" << globals->get_warp() << endl;
- if(currAircraft == scheduledAircraft.end())
+ if (scheduledAircraft.size() == 0)
+ return;
+ if(currAircraft == scheduledAircraft.end())
+ {
+ //cerr << "resetting schedule " << endl;
currAircraft = scheduledAircraft.begin();
- currAircraft->update(now);
- currAircraft++;
+ }
+ if (!(currAircraft->update(now)))
+ {
+ // after proper initialization, we shouldnt get here.
+ // But let's make sure
+ cerr << "Failed to update aircraft schedule in traffic manager" << endl;
+ }
+ currAircraft++;
+}
+
+void FGTrafficManager::release(int id)
+{
+ releaseList.push_back(id);
+}
+
+bool FGTrafficManager::isReleased(int id)
+{
+ IdListIterator i = releaseList.begin();
+ while (i != releaseList.end())
+ {
+ if ((*i) == id)
+ {
+ releaseList.erase(i);
+ return true;
+ }
+ i++;
+ }
+ return false;
}
void FGTrafficManager::startXML () {
if (attval != 0)
{
//cout << "including " << attval << endl;
- string path =
- globals->get_fg_root() +
- string("/Traffic/") +
- string(attval);
- readXML(path, *this);
+ SGPath path =
+ globals->get_fg_root();
+ path.append("/Traffic/");
+ path.append(attval);
+ readXML(path.str(), *this);
}
// cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl;
}
livery = value;
else if (element == string("registration"))
registration = value;
+ else if (element == string("airline"))
+ airline = value;
+ else if (element == string("actype"))
+ acType = value;
+ else if (element == string("flighttype"))
+ flighttype = value;
+ else if (element == string("radius"))
+ radius = atoi(value.c_str());
+ else if (element == string("offset"))
+ offset = atoi(value.c_str());
+ else if (element == string("performance-class"))
+ m_class = value;
else if (element == string("heavy"))
{
if(value == string("true"))
{
//cerr << "Pushing back aircraft " << registration << endl;
scheduledAircraft.push_back(FGAISchedule(mdl,
- livery,
- registration,
- heavy,
- flights));
+ livery,
+ registration,
+ heavy,
+ acType,
+ airline,
+ m_class,
+ flighttype,
+ radius,
+ offset,
+ flights));
while(flights.begin() != flights.end())
flights.pop_back();
}