+ elementValueStack.push_back("");
+ // cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl;
+}
+
+void FGTrafficManager::endElement(const char *name)
+{
+ //cout << "End element " << name << endl;
+ const string & value = elementValueStack.back();
+
+ if (!strcmp(name, "model"))
+ mdl = value;
+ else if (!strcmp(name, "livery"))
+ livery = value;
+ else if (!strcmp(name, "home-port"))
+ homePort = value;
+ else if (!strcmp(name, "registration"))
+ registration = value;
+ else if (!strcmp(name, "airline"))
+ airline = value;
+ else if (!strcmp(name, "actype"))
+ acType = value;
+ else if (!strcmp(name, "required-aircraft"))
+ requiredAircraft = value;
+ else if (!strcmp(name, "flighttype"))
+ flighttype = value;
+ else if (!strcmp(name, "radius"))
+ radius = atoi(value.c_str());
+ else if (!strcmp(name, "offset"))
+ offset = atoi(value.c_str());
+ else if (!strcmp(name, "performance-class"))
+ m_class = value;
+ else if (!strcmp(name, "heavy")) {
+ if (value == string("true"))
+ heavy = true;
+ else
+ heavy = false;
+ } else if (!strcmp(name, "callsign"))
+ callsign = value;
+ else if (!strcmp(name, "fltrules"))
+ fltrules = value;
+ else if (!strcmp(name, "port"))
+ port = value;
+ else if (!strcmp(name, "time"))
+ timeString = value;
+ else if (!strcmp(name, "departure")) {
+ departurePort = port;
+ departureTime = timeString;
+ } else if (!strcmp(name, "cruise-alt"))
+ cruiseAlt = atoi(value.c_str());
+ else if (!strcmp(name, "arrival")) {
+ arrivalPort = port;
+ arrivalTime = timeString;
+ } else if (!strcmp(name, "repeat"))
+ repeat = value;
+ else if (!strcmp(name, "flight")) {
+ // 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;
+
+ //Prioritize aircraft
+ string apt = fgGetString("/sim/presets/airport-id");
+ //cerr << "Airport information: " << apt << " " << departurePort << " " << arrivalPort << endl;
+ //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;
+ }
+ SG_LOG(SG_GENERAL, SG_DEBUG, "Adding flight: " << callsign << " "
+ << fltrules << " "
+ << departurePort << " "
+ << arrivalPort << " "
+ << cruiseAlt << " "
+ << departureTime << " "
+ << arrivalTime << " " << repeat << " " << requiredAircraft);
+ // For database maintainance purposes, it may be convenient to
+ //
+ if (fgGetBool("/sim/traffic-manager/dumpdata") == true) {
+ SG_LOG(SG_GENERAL, SG_ALERT, "Traffic Dump 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 = "";
+ } else if (!strcmp(name, "aircraft")) {
+ string isHeavy;
+ if (heavy) {
+ isHeavy = "true";
+ } else {
+ isHeavy = "false";
+ }
+ /*
+ cerr << "Traffic Dump AC," << homePort << "," << registration << "," << requiredAircraft
+ << "," << acType << "," << livery << ","
+ << airline << "," << offset << "," << radius << "," << flighttype << "," << isHeavy << "," << mdl << endl;*/
+ int proportion =
+ (int) (fgGetDouble("/sim/traffic-manager/proportion") * 100);
+ int randval = rand() & 100;
+ if (randval <= proportion) {
+ if (fgGetBool("/sim/traffic-manager/dumpdata") == true) {
+ SG_LOG(SG_GENERAL, SG_ALERT, "Traffic Dump AC," << homePort << "," << registration << "," << requiredAircraft
+ << "," << acType << "," << livery << ","
+ << airline << "," << m_class << "," << offset << "," << radius << "," << flighttype << "," << isHeavy << "," << mdl);
+ }
+ //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,