2004-06-03 17:59:14 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* TrafficMGr.cxx
|
|
|
|
* Written by Durk Talsma, started May 5, 2004.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-06-03 17:59:14 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
2008-11-16 13:45:24 +00:00
|
|
|
/*
|
|
|
|
* Traffic manager parses airlines timetable-like data and uses this to
|
|
|
|
* determine the approximate position of each AI aircraft in its database.
|
|
|
|
* When an AI aircraft is close to the user's position, a more detailed
|
|
|
|
* AIModels based simulation is set up.
|
2004-06-03 17:59:14 +00:00
|
|
|
*
|
|
|
|
* I'm currently assuming the following simplifications:
|
|
|
|
* 1) The earth is a perfect sphere
|
|
|
|
* 2) Each aircraft flies a perfect great circle route.
|
|
|
|
* 3) Each aircraft flies at a constant speed (with infinite accelerations and
|
|
|
|
* decelerations)
|
|
|
|
* 4) Each aircraft leaves at exactly the departure time.
|
|
|
|
* 5) Each aircraft arrives at exactly the specified arrival time.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2006-02-18 13:58:09 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2004-06-03 17:59:14 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
2009-11-08 21:53:02 +01:00
|
|
|
#include <cstring>
|
2004-06-03 17:59:14 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2005-02-18 10:16:30 +00:00
|
|
|
#include <algorithm>
|
2004-06-03 17:59:14 +00:00
|
|
|
|
2006-12-27 11:53:54 +00:00
|
|
|
#include <plib/ul.h>
|
2004-06-03 17:59:14 +00:00
|
|
|
|
|
|
|
#include <simgear/compiler.h>
|
2004-12-27 17:35:22 +00:00
|
|
|
#include <simgear/misc/sg_path.hxx>
|
2004-06-03 17:59:14 +00:00
|
|
|
#include <simgear/props/props.hxx>
|
|
|
|
#include <simgear/route/waypoint.hxx>
|
|
|
|
#include <simgear/structure/subsystem_mgr.hxx>
|
|
|
|
#include <simgear/xml/easyxml.hxx>
|
|
|
|
|
2005-02-10 09:01:51 +00:00
|
|
|
#include <AIModel/AIAircraft.hxx>
|
2004-06-03 17:59:14 +00:00
|
|
|
#include <AIModel/AIFlightPlan.hxx>
|
2004-09-07 09:53:23 +00:00
|
|
|
#include <AIModel/AIBase.hxx>
|
2004-06-03 17:59:14 +00:00
|
|
|
#include <Airports/simple.hxx>
|
2006-07-29 18:17:19 +00:00
|
|
|
#include <Main/fg_init.hxx>
|
2004-06-03 17:59:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "TrafficMgr.hxx"
|
|
|
|
|
2008-07-27 16:25:13 +00:00
|
|
|
using std::sort;
|
2009-11-08 21:53:02 +01:00
|
|
|
using std::strcmp;
|
2004-06-03 17:59:14 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* TrafficManager
|
|
|
|
*****************************************************************************/
|
|
|
|
FGTrafficManager::FGTrafficManager()
|
|
|
|
{
|
2008-11-16 13:45:24 +00:00
|
|
|
//score = 0;
|
|
|
|
//runCount = 0;
|
|
|
|
acCounter = 0;
|
2004-06-03 17:59:14 +00:00
|
|
|
}
|
|
|
|
|
2006-10-06 17:36:31 +00:00
|
|
|
FGTrafficManager:: ~FGTrafficManager()
|
|
|
|
{
|
|
|
|
for (ScheduleVectorIterator sched = scheduledAircraft.begin(); sched != scheduledAircraft.end(); sched++)
|
|
|
|
{
|
|
|
|
delete (*sched);
|
|
|
|
}
|
|
|
|
scheduledAircraft.clear();
|
2008-11-16 13:45:24 +00:00
|
|
|
flights.clear();
|
2006-10-06 17:36:31 +00:00
|
|
|
}
|
|
|
|
|
2004-06-03 17:59:14 +00:00
|
|
|
|
|
|
|
void FGTrafficManager::init()
|
2005-02-10 09:01:51 +00:00
|
|
|
{
|
2006-12-27 11:53:54 +00:00
|
|
|
ulDir* d, *d2;
|
|
|
|
ulDirEnt* dent, *dent2;
|
|
|
|
SGPath aircraftDir = globals->get_fg_root();
|
|
|
|
|
|
|
|
SGPath path = aircraftDir;
|
2008-11-16 13:45:24 +00:00
|
|
|
|
|
|
|
aircraftDir.append("AI/Traffic");
|
2007-08-18 05:09:46 +00:00
|
|
|
if ((d = ulOpenDir(aircraftDir.c_str())) != NULL)
|
2006-12-27 11:53:54 +00:00
|
|
|
{
|
|
|
|
while((dent = ulReadDir(d)) != NULL) {
|
|
|
|
if (string(dent->d_name) != string(".") &&
|
|
|
|
string(dent->d_name) != string("..") &&
|
|
|
|
dent->d_isdir)
|
|
|
|
{
|
|
|
|
SGPath currACDir = aircraftDir;
|
|
|
|
currACDir.append(dent->d_name);
|
|
|
|
if ((d2 = ulOpenDir(currACDir.c_str())) == NULL)
|
|
|
|
return;
|
|
|
|
while ((dent2 = ulReadDir(d2)) != NULL) {
|
|
|
|
SGPath currFile = currACDir;
|
|
|
|
currFile.append(dent2->d_name);
|
|
|
|
if (currFile.extension() == string("xml"))
|
|
|
|
{
|
|
|
|
SGPath currFile = currACDir;
|
|
|
|
currFile.append(dent2->d_name);
|
2009-09-14 12:39:41 +00:00
|
|
|
SG_LOG(SG_GENERAL, SG_DEBUG, "Scanning " << currFile.str() << " for traffic");
|
2006-12-27 11:53:54 +00:00
|
|
|
readXML(currFile.str(),*this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ulCloseDir(d2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ulCloseDir(d);
|
|
|
|
}
|
2009-08-24 17:13:31 +02:00
|
|
|
|
2008-11-16 13:45:24 +00:00
|
|
|
currAircraft = scheduledAircraft.begin();
|
|
|
|
currAircraftClosest = scheduledAircraft.begin();
|
2004-06-03 17:59:14 +00:00
|
|
|
}
|
|
|
|
|
2007-05-10 14:28:17 +00:00
|
|
|
void FGTrafficManager::update(double /*dt*/)
|
2004-06-03 17:59:14 +00:00
|
|
|
{
|
2010-08-29 19:25:34 +02:00
|
|
|
if (fgGetBool("/environment/metar/valid") == false) {
|
|
|
|
return;
|
|
|
|
}
|
2004-06-03 17:59:14 +00:00
|
|
|
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
2006-12-27 11:53:54 +00:00
|
|
|
if (scheduledAircraft.size() == 0) {
|
2006-07-29 18:17:19 +00:00
|
|
|
return;
|
2006-12-27 11:53:54 +00:00
|
|
|
}
|
2010-02-19 00:31:38 +00:00
|
|
|
|
|
|
|
SGVec3d userCart = SGVec3d::fromGeod(SGGeod::fromDeg(
|
|
|
|
fgGetDouble("/position/longitude-deg"),
|
|
|
|
fgGetDouble("/position/latitude-deg")));
|
|
|
|
|
2005-02-10 09:01:51 +00:00
|
|
|
if(currAircraft == scheduledAircraft.end())
|
|
|
|
{
|
2004-06-03 17:59:14 +00:00
|
|
|
currAircraft = scheduledAircraft.begin();
|
2005-02-10 09:01:51 +00:00
|
|
|
}
|
2010-02-19 00:31:38 +00:00
|
|
|
if (!((*currAircraft)->update(now, userCart)))
|
2005-02-10 09:01:51 +00:00
|
|
|
{
|
2008-11-16 13:45:24 +00:00
|
|
|
// NOTE: With traffic manager II, this statement below is no longer true
|
2005-02-10 09:01:51 +00:00
|
|
|
// after proper initialization, we shouldnt get here.
|
|
|
|
// But let's make sure
|
2008-11-16 13:45:24 +00:00
|
|
|
//SG_LOG( SG_GENERAL, SG_ALERT, "Failed to update aircraft schedule in traffic manager");
|
2005-02-10 09:01:51 +00:00
|
|
|
}
|
|
|
|
currAircraft++;
|
2004-06-03 17:59:14 +00:00
|
|
|
}
|
|
|
|
|
2005-10-15 14:55:51 +00:00
|
|
|
void FGTrafficManager::release(int id)
|
2004-11-29 09:41:43 +00:00
|
|
|
{
|
|
|
|
releaseList.push_back(id);
|
|
|
|
}
|
|
|
|
|
2005-10-15 14:55:51 +00:00
|
|
|
bool FGTrafficManager::isReleased(int id)
|
2004-11-29 09:41:43 +00:00
|
|
|
{
|
|
|
|
IdListIterator i = releaseList.begin();
|
|
|
|
while (i != releaseList.end())
|
|
|
|
{
|
|
|
|
if ((*i) == id)
|
|
|
|
{
|
|
|
|
releaseList.erase(i);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2008-11-16 13:45:24 +00:00
|
|
|
/*
|
|
|
|
void FGTrafficManager::readTimeTableFromFile(SGPath infileName)
|
|
|
|
{
|
|
|
|
string model;
|
|
|
|
string livery;
|
|
|
|
string homePort;
|
|
|
|
string registration;
|
|
|
|
string flightReq;
|
|
|
|
bool isHeavy;
|
|
|
|
string acType;
|
|
|
|
string airline;
|
|
|
|
string m_class;
|
|
|
|
string FlightType;
|
|
|
|
double radius;
|
|
|
|
double offset;
|
|
|
|
|
|
|
|
char buffer[256];
|
|
|
|
string buffString;
|
|
|
|
vector <string> tokens, depTime,arrTime;
|
|
|
|
vector <string>::iterator it;
|
|
|
|
ifstream infile(infileName.str().c_str());
|
|
|
|
while (1) {
|
|
|
|
infile.getline(buffer, 256);
|
|
|
|
if (infile.eof()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//cerr << "Read line : " << buffer << endl;
|
|
|
|
buffString = string(buffer);
|
|
|
|
tokens.clear();
|
|
|
|
Tokenize(buffString, tokens, " \t");
|
|
|
|
//for (it = tokens.begin(); it != tokens.end(); it++) {
|
|
|
|
// cerr << "Tokens: " << *(it) << endl;
|
|
|
|
//}
|
|
|
|
//cerr << endl;
|
|
|
|
if (!tokens.empty()) {
|
|
|
|
if (tokens[0] == string("AC")) {
|
|
|
|
if (tokens.size() != 13) {
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "Error parsing traffic file " << infileName.str() << " at " << buffString);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
model = tokens[12];
|
|
|
|
livery = tokens[6];
|
|
|
|
homePort = tokens[1];
|
|
|
|
registration = tokens[2];
|
|
|
|
if (tokens[11] == string("false")) {
|
|
|
|
isHeavy = false;
|
|
|
|
} else {
|
|
|
|
isHeavy = true;
|
|
|
|
}
|
|
|
|
acType = tokens[4];
|
|
|
|
airline = tokens[5];
|
|
|
|
flightReq = tokens[3] + tokens[5];
|
|
|
|
m_class = tokens[10];
|
|
|
|
FlightType = tokens[9];
|
|
|
|
radius = atof(tokens[8].c_str());
|
|
|
|
offset = atof(tokens[7].c_str());;
|
|
|
|
//cerr << "Found AC string " << model << " " << livery << " " << homePort << " "
|
|
|
|
// << registration << " " << flightReq << " " << isHeavy << " " << acType << " " << airline << " " << m_class
|
|
|
|
// << " " << FlightType << " " << radius << " " << offset << endl;
|
|
|
|
scheduledAircraft.push_back(new FGAISchedule(model,
|
|
|
|
livery,
|
|
|
|
homePort,
|
|
|
|
registration,
|
|
|
|
flightReq,
|
|
|
|
isHeavy,
|
|
|
|
acType,
|
|
|
|
airline,
|
|
|
|
m_class,
|
|
|
|
FlightType,
|
|
|
|
radius,
|
|
|
|
offset));
|
|
|
|
}
|
|
|
|
if (tokens[0] == string("FLIGHT")) {
|
|
|
|
//cerr << "Found flight " << buffString << " size is : " << tokens.size() << endl;
|
|
|
|
if (tokens.size() != 10) {
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "Error parsing traffic file " << infileName.str() << " at " << buffString);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
string callsign = tokens[1];
|
|
|
|
string fltrules = tokens[2];
|
|
|
|
string weekdays = tokens[3];
|
|
|
|
string departurePort = tokens[5];
|
|
|
|
string arrivalPort = tokens[7];
|
|
|
|
int cruiseAlt = atoi(tokens[8].c_str());
|
|
|
|
string depTimeGen = tokens[4];
|
|
|
|
string arrTimeGen = tokens[6];
|
|
|
|
string repeat = "WEEK";
|
|
|
|
string requiredAircraft = tokens[9];
|
|
|
|
|
|
|
|
if (weekdays.size() != 7) {
|
|
|
|
cerr << "Found misconfigured weekdays string" << weekdays << endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
depTime.clear();
|
|
|
|
arrTime.clear();
|
|
|
|
Tokenize(depTimeGen, depTime, ":");
|
|
|
|
Tokenize(arrTimeGen, arrTime, ":");
|
|
|
|
double dep = atof(depTime[0].c_str()) + (atof(depTime[1].c_str()) / 60.0);
|
|
|
|
double arr = atof(arrTime[0].c_str()) + (atof(arrTime[1].c_str()) / 60.0);
|
|
|
|
//cerr << "Using " << dep << " " << arr << endl;
|
|
|
|
bool arrivalWeekdayNeedsIncrement = false;
|
|
|
|
if (arr < dep) {
|
|
|
|
arrivalWeekdayNeedsIncrement = true;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 7; i++) {
|
|
|
|
if (weekdays[i] != '.') {
|
|
|
|
char buffer[4];
|
|
|
|
snprintf(buffer, 4, "%d/", i);
|
|
|
|
string departureTime = string(buffer) + depTimeGen + string(":00");
|
|
|
|
string arrivalTime;
|
|
|
|
if (!arrivalWeekdayNeedsIncrement) {
|
|
|
|
arrivalTime = string(buffer) + arrTimeGen + string(":00");
|
|
|
|
}
|
|
|
|
if (arrivalWeekdayNeedsIncrement && i != 6 ) {
|
|
|
|
snprintf(buffer, 4, "%d/", i+1);
|
|
|
|
arrivalTime = string(buffer) + arrTimeGen + string(":00");
|
|
|
|
}
|
|
|
|
if (arrivalWeekdayNeedsIncrement && i == 6 ) {
|
|
|
|
snprintf(buffer, 4, "%d/", 0);
|
|
|
|
arrivalTime = string(buffer) + arrTimeGen + string(":00");
|
|
|
|
}
|
|
|
|
cerr << "Adding flight: " << callsign << " "
|
|
|
|
<< fltrules << " "
|
|
|
|
<< departurePort << " "
|
|
|
|
<< arrivalPort << " "
|
|
|
|
<< cruiseAlt << " "
|
|
|
|
<< departureTime << " "
|
|
|
|
<< arrivalTime << " "
|
|
|
|
<< repeat << " "
|
|
|
|
<< requiredAircraft << endl;
|
|
|
|
|
|
|
|
flights[requiredAircraft].push_back(new FGScheduledFlight(callsign,
|
|
|
|
fltrules,
|
|
|
|
departurePort,
|
|
|
|
arrivalPort,
|
|
|
|
cruiseAlt,
|
|
|
|
departureTime,
|
|
|
|
arrivalTime,
|
|
|
|
repeat,
|
|
|
|
requiredAircraft));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
//exit(1);
|
|
|
|
}*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
void FGTrafficManager::Tokenize(const string& str,
|
|
|
|
vector<string>& tokens,
|
|
|
|
const string& delimiters)
|
|
|
|
{
|
|
|
|
// Skip delimiters at beginning.
|
|
|
|
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
|
|
|
|
// Find first "non-delimiter".
|
|
|
|
string::size_type pos = str.find_first_of(delimiters, lastPos);
|
|
|
|
|
|
|
|
while (string::npos != pos || string::npos != lastPos)
|
|
|
|
{
|
|
|
|
// Found a token, add it to the vector.
|
|
|
|
tokens.push_back(str.substr(lastPos, pos - lastPos));
|
|
|
|
// Skip delimiters. Note the "not_of"
|
|
|
|
lastPos = str.find_first_not_of(delimiters, pos);
|
|
|
|
// Find next "non-delimiter"
|
|
|
|
pos = str.find_first_of(delimiters, lastPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2004-11-29 09:41:43 +00:00
|
|
|
|
2004-06-03 17:59:14 +00:00
|
|
|
void FGTrafficManager::startXML () {
|
|
|
|
//cout << "Start XML" << endl;
|
2008-11-16 13:45:24 +00:00
|
|
|
requiredAircraft = "";
|
|
|
|
homePort = "";
|
2004-06-03 17:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FGTrafficManager::endXML () {
|
|
|
|
//cout << "End XML" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGTrafficManager::startElement (const char * name, const XMLAttributes &atts) {
|
|
|
|
const char * attval;
|
|
|
|
//cout << "Start element " << name << endl;
|
|
|
|
//FGTrafficManager temp;
|
|
|
|
//for (int i = 0; i < atts.size(); i++)
|
|
|
|
// if (string(atts.getName(i)) == string("include"))
|
|
|
|
attval = atts.getValue("include");
|
|
|
|
if (attval != 0)
|
|
|
|
{
|
|
|
|
//cout << "including " << attval << endl;
|
2004-12-27 17:35:22 +00:00
|
|
|
SGPath path =
|
|
|
|
globals->get_fg_root();
|
|
|
|
path.append("/Traffic/");
|
|
|
|
path.append(attval);
|
|
|
|
readXML(path.str(), *this);
|
2004-06-03 17:59:14 +00:00
|
|
|
}
|
2008-06-01 11:56:32 +00:00
|
|
|
elementValueStack.push_back( "" );
|
2004-06-03 17:59:14 +00:00
|
|
|
// cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGTrafficManager::endElement (const char * name) {
|
|
|
|
//cout << "End element " << name << endl;
|
2009-11-08 21:53:02 +01:00
|
|
|
const string& value = elementValueStack.back();
|
2008-06-01 11:56:32 +00:00
|
|
|
|
2009-11-08 21:53:02 +01:00
|
|
|
if (!strcmp(name, "model"))
|
2004-06-03 17:59:14 +00:00
|
|
|
mdl = value;
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "livery"))
|
2004-06-03 17:59:14 +00:00
|
|
|
livery = value;
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "home-port"))
|
2008-11-16 13:45:24 +00:00
|
|
|
homePort = value;
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "registration"))
|
2004-06-03 17:59:14 +00:00
|
|
|
registration = value;
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "airline"))
|
2005-02-10 09:01:51 +00:00
|
|
|
airline = value;
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "actype"))
|
2005-02-10 09:01:51 +00:00
|
|
|
acType = value;
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "required-aircraft"))
|
2008-11-16 13:45:24 +00:00
|
|
|
requiredAircraft = value;
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "flighttype"))
|
2005-02-10 09:01:51 +00:00
|
|
|
flighttype = value;
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "radius"))
|
2005-02-10 09:01:51 +00:00
|
|
|
radius = atoi(value.c_str());
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "offset"))
|
2005-02-10 09:01:51 +00:00
|
|
|
offset = atoi(value.c_str());
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "performance-class"))
|
2005-02-10 09:01:51 +00:00
|
|
|
m_class = value;
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "heavy"))
|
2004-06-03 17:59:14 +00:00
|
|
|
{
|
|
|
|
if(value == string("true"))
|
|
|
|
heavy = true;
|
|
|
|
else
|
|
|
|
heavy = false;
|
|
|
|
}
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "callsign"))
|
2004-06-03 17:59:14 +00:00
|
|
|
callsign = value;
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "fltrules"))
|
2004-06-03 17:59:14 +00:00
|
|
|
fltrules = value;
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "port"))
|
2004-06-03 17:59:14 +00:00
|
|
|
port = value;
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "time"))
|
2004-06-03 17:59:14 +00:00
|
|
|
timeString = value;
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "departure"))
|
2004-06-03 17:59:14 +00:00
|
|
|
{
|
|
|
|
departurePort = port;
|
|
|
|
departureTime = timeString;
|
|
|
|
}
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "cruise-alt"))
|
2004-06-03 17:59:14 +00:00
|
|
|
cruiseAlt = atoi(value.c_str());
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "arrival"))
|
2004-06-03 17:59:14 +00:00
|
|
|
{
|
|
|
|
arrivalPort = port;
|
|
|
|
arrivalTime = timeString;
|
|
|
|
}
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "repeat"))
|
2004-06-03 17:59:14 +00:00
|
|
|
repeat = value;
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "flight"))
|
2004-06-03 17:59:14 +00:00
|
|
|
{
|
|
|
|
// We have loaded and parsed all the information belonging to this flight
|
|
|
|
// so we temporarily store it.
|
|
|
|
//cerr << "Pusing back flight " << callsign << endl;
|
|
|
|
//cerr << callsign << " " << fltrules << " "<< departurePort << " " << arrivalPort << " "
|
|
|
|
// << cruiseAlt << " " << departureTime<< " "<< arrivalTime << " " << repeat << endl;
|
2006-07-29 18:17:19 +00:00
|
|
|
|
|
|
|
//Prioritize aircraft
|
|
|
|
string apt = fgGetString("/sim/presets/airport-id");
|
|
|
|
//cerr << "Airport information: " << apt << " " << departurePort << " " << arrivalPort << endl;
|
2008-11-16 13:45:24 +00:00
|
|
|
//if (departurePort == apt) score++;
|
|
|
|
//flights.push_back(new FGScheduledFlight(callsign,
|
|
|
|
// fltrules,
|
|
|
|
// departurePort,
|
|
|
|
// arrivalPort,
|
|
|
|
// cruiseAlt,
|
|
|
|
// departureTime,
|
|
|
|
// arrivalTime,
|
|
|
|
// repeat));
|
|
|
|
if (requiredAircraft == "") {
|
|
|
|
char buffer[16];
|
|
|
|
snprintf(buffer, 16, "%d", acCounter);
|
|
|
|
requiredAircraft = buffer;
|
2004-06-03 17:59:14 +00:00
|
|
|
}
|
2008-11-16 13:45:24 +00:00
|
|
|
SG_LOG(SG_GENERAL, SG_DEBUG, "Adding flight: " << callsign << " "
|
|
|
|
<< fltrules << " "
|
|
|
|
<< departurePort << " "
|
|
|
|
<< arrivalPort << " "
|
|
|
|
<< cruiseAlt << " "
|
|
|
|
<< departureTime << " "
|
|
|
|
<< arrivalTime << " "
|
|
|
|
<< repeat << " "
|
|
|
|
<< requiredAircraft);
|
|
|
|
|
|
|
|
flights[requiredAircraft].push_back(new FGScheduledFlight(callsign,
|
|
|
|
fltrules,
|
|
|
|
departurePort,
|
|
|
|
arrivalPort,
|
|
|
|
cruiseAlt,
|
|
|
|
departureTime,
|
|
|
|
arrivalTime,
|
|
|
|
repeat,
|
|
|
|
requiredAircraft));
|
|
|
|
requiredAircraft = "";
|
|
|
|
}
|
2009-11-08 21:53:02 +01:00
|
|
|
else if (!strcmp(name, "aircraft"))
|
2004-06-03 17:59:14 +00:00
|
|
|
{
|
2008-05-08 06:11:43 +00:00
|
|
|
int proportion = (int) (fgGetDouble("/sim/traffic-manager/proportion") * 100);
|
|
|
|
int randval = rand() & 100;
|
|
|
|
if (randval < proportion) {
|
2008-11-16 13:45:24 +00:00
|
|
|
//scheduledAircraft.push_back(new FGAISchedule(mdl,
|
|
|
|
// livery,
|
|
|
|
// registration,
|
|
|
|
// heavy,
|
|
|
|
// acType,
|
|
|
|
// airline,
|
|
|
|
// m_class,
|
|
|
|
// flighttype,
|
|
|
|
// radius,
|
|
|
|
// offset,
|
|
|
|
// score,
|
|
|
|
// flights));
|
|
|
|
if (requiredAircraft == "") {
|
|
|
|
char buffer[16];
|
|
|
|
snprintf(buffer, 16, "%d", acCounter);
|
|
|
|
requiredAircraft = buffer;
|
|
|
|
}
|
|
|
|
if (homePort == "") {
|
|
|
|
homePort = departurePort;
|
|
|
|
}
|
|
|
|
scheduledAircraft.push_back(new FGAISchedule(mdl,
|
|
|
|
livery,
|
|
|
|
homePort,
|
|
|
|
registration,
|
|
|
|
requiredAircraft,
|
|
|
|
heavy,
|
|
|
|
acType,
|
|
|
|
airline,
|
|
|
|
m_class,
|
|
|
|
flighttype,
|
|
|
|
radius,
|
|
|
|
offset));
|
|
|
|
|
2006-10-06 17:36:31 +00:00
|
|
|
// while(flights.begin() != flights.end()) {
|
|
|
|
// flights.pop_back();
|
|
|
|
// }
|
2008-11-16 13:45:24 +00:00
|
|
|
}
|
|
|
|
acCounter++;
|
|
|
|
requiredAircraft = "";
|
|
|
|
homePort = "";
|
|
|
|
//for (FGScheduledFlightVecIterator flt = flights.begin(); flt != flights.end(); flt++)
|
|
|
|
// {
|
|
|
|
// delete (*flt);
|
|
|
|
// }
|
|
|
|
//flights.clear();
|
2006-07-29 18:17:19 +00:00
|
|
|
SG_LOG( SG_GENERAL, SG_BULK, "Reading aircraft : "
|
|
|
|
<< registration
|
|
|
|
<< " with prioritization score "
|
|
|
|
<< score);
|
|
|
|
score = 0;
|
2004-06-03 17:59:14 +00:00
|
|
|
}
|
2009-11-08 21:53:02 +01:00
|
|
|
elementValueStack.pop_back();
|
2004-06-03 17:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FGTrafficManager::data (const char * s, int len) {
|
|
|
|
string token = string(s,len);
|
|
|
|
//cout << "Character data " << string(s,len) << endl;
|
2008-06-01 11:56:32 +00:00
|
|
|
elementValueStack.back() += token;
|
2004-06-03 17:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FGTrafficManager::pi (const char * target, const char * data) {
|
|
|
|
//cout << "Processing instruction " << target << ' ' << data << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGTrafficManager::warning (const char * message, int line, int column) {
|
2006-03-31 16:56:14 +00:00
|
|
|
SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')');
|
2004-06-03 17:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FGTrafficManager::error (const char * message, int line, int column) {
|
2006-03-31 16:56:14 +00:00
|
|
|
SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')');
|
2004-06-03 17:59:14 +00:00
|
|
|
}
|
2008-11-16 13:45:24 +00:00
|
|
|
|