]> git.mxchange.org Git - flightgear.git/blob - src/Traffic/Schedule.hxx
Re-apply the Clang/C+11 fix for JSBSim
[flightgear.git] / src / Traffic / Schedule.hxx
1 /* -*- Mode: C++ -*- *****************************************************
2  * Schedule.hxx
3  * Written by Durk Talsma. Started May 5, 2004
4  *
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.
9  *
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.
14  *
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.
18  *
19  *
20  **************************************************************************/
21
22 /**************************************************************************
23  * This file contains the definition of the class Schedule.
24  *
25  * A schedule is basically a number of scheduled flights, which can be
26  * assigned to an AI aircraft. 
27  **************************************************************************/
28
29 #ifndef _FGSCHEDULE_HXX_
30 #define _FGSCHEDULE_HXX_
31
32 #define TRAFFICTOAIDISTTOSTART 150.0
33 #define TRAFFICTOAIDISTTODIE   200.0
34
35 // forward decls
36 class FGAIAircraft;
37
38 class FGAISchedule
39 {
40  private:
41   std::string modelPath;
42   std::string homePort;
43   std::string livery;
44   std::string registration;
45   std::string airline;
46   std::string acType;
47   std::string m_class;
48   std::string flightType;
49   std::string flightIdentifier;
50   std::string currentDestination;
51   bool heavy;
52   FGScheduledFlightVec flights;
53   SGGeod position;
54   double radius;
55   double groundOffset;
56   double distanceToUser;
57   double score;
58   unsigned int runCount;
59   unsigned int hits;
60   unsigned int lastRun;
61   bool firstRun;
62   double courseToDest;
63   bool initialized;
64   bool valid;
65   bool scheduleComplete;
66
67   bool scheduleFlights(time_t now);
68   int groundTimeFromRadius();
69   
70   /**
71    * Transition this schedule from distant mode to AI mode;
72    * create the AIAircraft (and flight plan) and register with the AIManager
73    */
74   bool createAIAircraft(FGScheduledFlight* flight, double speedKnots, time_t deptime);
75   
76   // the aiAircraft associated with us
77   SGSharedPtr<FGAIAircraft> aiAircraft;
78  public:
79   FGAISchedule();                                           // constructor
80   FGAISchedule(const std::string& model,
81                const std::string& livery,
82                const std::string& homePort,
83                const std::string& registration,
84                const std::string& flightId,
85                bool   heavy, 
86                const std::string& acType,
87                const std::string& airline,
88                const std::string& m_class,
89                const std::string& flight_type,
90                double radius, 
91                double offset);                              // construct & init
92   FGAISchedule(const FGAISchedule &other);                  // copy constructor
93
94
95
96   ~FGAISchedule(); //destructor
97
98     static bool validModelPath(const std::string& model);
99     static SGPath resolveModelPath(const std::string& model);
100     
101   bool update(time_t now, const SGVec3d& userCart);
102   bool init();
103
104   double getSpeed         ();
105   //void setClosestDistanceToUser();
106   bool next();   // forces the schedule to move on to the next flight.
107
108   // TODO: rework these four functions
109    time_t      getDepartureTime    () { return (*flights.begin())->getDepartureTime   (); };
110   FGAirport * getDepartureAirport () { return (*flights.begin())->getDepartureAirport(); };
111   FGAirport * getArrivalAirport   () { return (*flights.begin())->getArrivalAirport  (); };
112   int         getCruiseAlt        () { return (*flights.begin())->getCruiseAlt       (); };
113   double      getRadius           () { return radius; };
114   double      getGroundOffset     () { return groundOffset;};
115   const std::string& getFlightType     () { return flightType;};
116   const std::string& getAirline        () { return airline; };
117   const std::string& getAircraft       () { return acType; };
118   const std::string& getCallSign       () { return (*flights.begin())->getCallSign (); };
119   const std::string& getRegistration   () { return registration;};
120   const std::string& getFlightRules    () { return (*flights.begin())->getFlightRules (); };
121   bool getHeavy                   () { return heavy; };
122   double getCourse                () { return courseToDest; };
123   unsigned int getRunCount        () { return runCount; };
124   unsigned int getHits            () { return hits; };
125
126   void         setrunCount(unsigned int count) { runCount = count; };
127   void         setHits    (unsigned int count) { hits     = count; };
128   void         setScore   ();
129   double       getScore   () { return score; };
130   void         setHeading (); 
131   void         assign         (FGScheduledFlight *ref) { flights.push_back(ref); };
132   void         setFlightType  (const std::string& val) { flightType = val; };
133   FGScheduledFlight*findAvailableFlight (const std::string& currentDestination, const std::string &req, time_t min=0, time_t max=0);
134   // used to sort in descending order of score: I've probably found a better way to
135   // descending order sorting, but still need to test that.
136   bool operator< (const FGAISchedule &other) const;
137   int getLastUsed() { return lastRun; };
138   void setLastUsed(unsigned int val) {lastRun = val; };
139   //void * getAiRef                 () { return AIManagerRef; };
140   //FGAISchedule* getAddress        () { return this;};
141
142 };
143
144 typedef std::vector<FGAISchedule*>           ScheduleVector;
145 typedef std::vector<FGAISchedule*>::iterator ScheduleVectorIterator;
146
147 bool compareSchedules(FGAISchedule*a, FGAISchedule*b);
148
149 #endif
150