1 /* -*- Mode: C++ -*- *****************************************************
3 * Written by Durk Talsma. Started May 5, 2004
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 **************************************************************************/
22 /**************************************************************************
23 * This file contains the class definitions for a (Top Level) traffic
24 * manager for FlightGear.
26 * This is traffic manager version II. The major difference from version
27 * I is that the Flight Schedules are decoupled from the AIAircraft
28 * entities. This allows for a much greater flexibility in setting up
29 * Irregular schedules. Traffic Manager II also makes no longer use of .xml
30 * based configuration files.
32 * Here is a step plan to achieve the goal of creating Traffic Manager II
34 * 1) Read aircraft data from a simple text file, like the one provided by
36 * 2) Create a new database structure of SchedFlights. This new database
37 * should not be part of the Schedule class, but of TrafficManager itself
38 * 3) Each aircraft should have a list of possible Flights it can operate
39 * (i.e. airline and AC type match).
40 * 4) Aircraft processing proceeds as current. During initialization, we seek
41 * the most urgent flight that needs to be operated
42 * 5) Modify the getNextLeg function so that the next flight is loaded smoothly.
44 **************************************************************************/
46 #ifndef _TRAFFICMGR_HXX_
47 #define _TRAFFICMGR_HXX_
50 #include <simgear/structure/subsystem_mgr.hxx>
51 #include <simgear/props/propertyObject.hxx>
52 #include <simgear/xml/easyxml.hxx>
53 #include <simgear/misc/sg_path.hxx>
54 #include <simgear/misc/sg_dir.hxx>
56 #include "SchedFlight.hxx"
57 #include "Schedule.hxx"
60 typedef std::vector<int> IdList;
61 typedef std::vector<int>::iterator IdListIterator;
66 std::string registration;
67 unsigned int runCount;
72 typedef std::vector<Heuristic> heuristicsVector;
73 typedef std::vector<Heuristic>::iterator heuristicsVectorIterator;
75 typedef std::map < std::string, Heuristic> HeuristicMap;
76 typedef HeuristicMap::iterator HeuristicMapIterator;
81 class FGTrafficManager : public SGSubsystem, public XMLVisitor
87 ScheduleVector scheduledAircraft;
88 ScheduleVectorIterator currAircraft, currAircraftClosest;
89 vector<string> elementValueStack;
91 // record model paths which are missing, to avoid duplicate
92 // warnings when parsing traffic schedules.
93 std::set<std::string> missingModels;
95 std::string mdl, livery, registration, callsign, fltrules,
96 port, timeString, departurePort, departureTime, arrivalPort, arrivalTime,
97 repeat, acType, airline, m_class, flighttype, requiredAircraft, homePort;
99 int score, runCount, acCounter;
100 double radius, offset;
105 FGScheduledFlightMap flights;
107 void readTimeTableFromFile(SGPath infilename);
108 void Tokenize(const string& str, vector<string>& tokens, const string& delimiters = " ");
110 simgear::PropertyObject<bool> enabled, aiEnabled, realWxEnabled, metarValid;
112 void loadHeuristics();
118 // during incremental init, contains the XML files still be read in
119 simgear::PathList schedulesToRead;
124 void update(double time);
125 void release(int ref);
126 bool isReleased(int id);
128 FGScheduledFlightVecIterator getFirstFlight(const string &ref) { return flights[ref].begin(); }
129 FGScheduledFlightVecIterator getLastFlight(const string &ref) { return flights[ref].end(); }
133 // Some overloaded virtual XMLVisitor members
134 virtual void startXML ();
135 virtual void endXML ();
136 virtual void startElement (const char * name, const XMLAttributes &atts);
137 virtual void endElement (const char * name);
138 virtual void data (const char * s, int len);
139 virtual void pi (const char * target, const char * data);
140 virtual void warning (const char * message, int line, int column);
141 virtual void error (const char * message, int line, int column);