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