]> git.mxchange.org Git - flightgear.git/blob - src/Traffic/Schedule.hxx
Code cleanups, code updates and fix at least on (possible) devide-by-zero
[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 class FGScheduledFlight;
38
39 typedef std::vector<FGScheduledFlight*> FGScheduledFlightVec;
40
41 class FGAISchedule
42 {
43  private:
44   std::string modelPath;
45   std::string homePort;
46   std::string livery;
47   std::string registration;
48   std::string airline;
49   std::string acType;
50   std::string m_class;
51   std::string flightType;
52   std::string flightIdentifier;
53   std::string currentDestination;
54   bool heavy;
55   FGScheduledFlightVec flights;
56   SGGeod position;
57   double radius;
58   double groundOffset;
59   double distanceToUser;
60   double score;
61   unsigned int runCount;
62   unsigned int hits;
63   unsigned int lastRun;
64   bool firstRun;
65   double courseToDest;
66   bool initialized;
67   bool valid;
68   bool scheduleComplete;
69
70   bool scheduleFlights(time_t now);
71   int groundTimeFromRadius();
72   
73   /**
74    * Transition this schedule from distant mode to AI mode;
75    * create the AIAircraft (and flight plan) and register with the AIManager
76    */
77   bool createAIAircraft(FGScheduledFlight* flight, double speedKnots, time_t deptime);
78   
79   // the aiAircraft associated with us
80   SGSharedPtr<FGAIAircraft> aiAircraft;
81  public:
82   FGAISchedule();                                           // constructor
83   FGAISchedule(const std::string& model,
84                const std::string& livery,
85                const std::string& homePort,
86                const std::string& registration,
87                const std::string& flightId,
88                bool   heavy, 
89                const std::string& acType,
90                const std::string& airline,
91                const std::string& m_class,
92                const std::string& flight_type,
93                double radius, 
94                double offset);                              // construct & init
95   FGAISchedule(const FGAISchedule &other);                  // copy constructor
96
97
98
99   ~FGAISchedule(); //destructor
100
101     static bool validModelPath(const std::string& model);
102     static SGPath resolveModelPath(const std::string& model);
103     
104   bool update(time_t now, const SGVec3d& userCart);
105   bool init();
106
107   double getSpeed         ();
108   //void setClosestDistanceToUser();
109   bool next();   // forces the schedule to move on to the next flight.
110
111   // TODO: rework these four functions
112   time_t      getDepartureTime    ();
113   FGAirport * getDepartureAirport ();
114   FGAirport * getArrivalAirport   ();
115   int         getCruiseAlt        ();
116   double      getRadius           () { return radius; };
117   double      getGroundOffset     () { return groundOffset;};
118   const std::string& getFlightType     () { return flightType;};
119   const std::string& getAirline        () { return airline; };
120   const std::string& getAircraft       () { return acType; };
121   std::string getCallSign       ();
122   const std::string& getRegistration   () { return registration;};
123   std::string getFlightRules    ();
124   bool getHeavy                   () { return heavy; };
125   double getCourse                () { return courseToDest; };
126   unsigned int getRunCount        () { return runCount; };
127   unsigned int getHits            () { return hits; };
128
129   void         setrunCount(unsigned int count) { runCount = count; };
130   void         setHits    (unsigned int count) { hits     = count; };
131   void         setScore   ();
132   double       getScore   () { return score; };
133   void         setHeading (); 
134   void         assign         (FGScheduledFlight *ref);
135   void         setFlightType  (const std::string& val) { flightType = val; };
136   FGScheduledFlight*findAvailableFlight (const std::string& currentDestination, const std::string &req, time_t min=0, time_t max=0);
137   // used to sort in descending order of score: I've probably found a better way to
138   // descending order sorting, but still need to test that.
139   bool operator< (const FGAISchedule &other) const;
140   int getLastUsed() { return lastRun; };
141   void setLastUsed(unsigned int val) {lastRun = val; };
142   //void * getAiRef                 () { return AIManagerRef; };
143   //FGAISchedule* getAddress        () { return this;};
144
145 };
146
147 typedef std::vector<FGAISchedule*>           ScheduleVector;
148 typedef std::vector<FGAISchedule*>::iterator ScheduleVectorIterator;
149
150 bool compareSchedules(FGAISchedule*a, FGAISchedule*b);
151
152 #endif
153