FlightGear next
Schedule.hxx
Go to the documentation of this file.
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#pragma once
30
31constexpr double TRAFFIC_TO_AI_DIST_TO_START = 150.0;
32constexpr double TRAFFIC_TO_AI_DIST_TO_DIE = 200.0;
33
34// forward decls
35class FGAIAircraft;
37
38typedef std::vector<FGScheduledFlight*> FGScheduledFlightVec;
39
40
42{
43private:
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;
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
77 bool createAIAircraft(FGScheduledFlight* flight, double speedKnots, time_t deptime, time_t remainingTime);
78
79 // the aiAircraft associated with us
80 SGSharedPtr<FGAIAircraft> aiAircraft;
81
82public:
83 FGAISchedule(); // constructor
84 FGAISchedule(const std::string& model,
85 const std::string& livery,
86 const std::string& homePort,
87 const std::string& registration,
88 const std::string& flightId,
89 bool heavy,
90 const std::string& acType,
91 const std::string& airline,
92 const std::string& m_class,
93 const std::string& flight_type,
94 double radius,
95 double offset); // construct & init
96 FGAISchedule(const FGAISchedule& other); // copy constructor
97
98 ~FGAISchedule(); //destructor
99
100 static bool validModelPath(const std::string& model);
101 static SGPath resolveModelPath(const std::string& model);
102
103 bool update(time_t now, const SGVec3d& userCart);
104 bool init();
105
106 double getSpeed();
107 //void setClosestDistanceToUser();
108 bool next(); // forces the schedule to move on to the next flight.
109
110 // TODO: rework these four functions
111 time_t getDepartureTime();
114 int getCruiseAlt();
115 double getRadius() { return radius; };
116 double getGroundOffset() { return groundOffset; };
117 const std::string& getFlightType() { return flightType; };
118 const std::string& getAirline() { return airline; };
119 const std::string& getAircraft() { return acType; };
120 std::string getCallSign();
121 const std::string& getRegistration() { return registration; };
122 std::string getFlightRules();
123 bool getHeavy() { return heavy; };
124 double getCourse() { return courseToDest; };
125 unsigned int getRunCount() { return runCount; };
126 unsigned int getHits() { return hits; };
127
128 void setrunCount(unsigned int count) { runCount = count; };
129 void setHits(unsigned int count) { hits = count; };
130 void setScore();
131 double getScore() { return score; };
133 void setHeading();
134 void assign(FGScheduledFlight* ref);
135 void clearAllFlights();
136 void setFlightType(const std::string& val) { flightType = val; };
137 FGScheduledFlight* findAvailableFlight(const std::string& currentDestination, const std::string& req, time_t min = 0, time_t max = 0);
138 // used to sort in descending order of score: I've probably found a better way to
139 // descending order sorting, but still need to test that.
140 bool operator<(const FGAISchedule& other) const;
141 int getLastUsed() { return lastRun; };
142 void setLastUsed(unsigned int val) { lastRun = val; };
143 //void * getAiRef () { return AIManagerRef; };
144 //FGAISchedule* getAddress () { return this;};
145
146 static bool compareSchedules(const FGAISchedule* a, const FGAISchedule* b);
147};
148
149typedef std::vector<FGAISchedule*> ScheduleVector;
150typedef std::vector<FGAISchedule*>::iterator ScheduleVectorIterator;
#define min(X, Y)
std::vector< FGScheduledFlight * > FGScheduledFlightVec
std::vector< FGAISchedule * > ScheduleVector
Definition Schedule.hxx:149
std::vector< FGScheduledFlight * > FGScheduledFlightVec
Definition Schedule.hxx:38
constexpr double TRAFFIC_TO_AI_DIST_TO_DIE
Definition Schedule.hxx:32
constexpr double TRAFFIC_TO_AI_DIST_TO_START
Definition Schedule.hxx:31
std::vector< FGAISchedule * >::iterator ScheduleVectorIterator
Definition Schedule.hxx:150
double getCourse()
Definition Schedule.hxx:124
FGScheduledFlight * findAvailableFlight(const std::string &currentDestination, const std::string &req, time_t min=0, time_t max=0)
Definition Schedule.cxx:568
void setScore()
Definition Schedule.cxx:681
const std::string & getAircraft()
Definition Schedule.hxx:119
bool getHeavy()
Definition Schedule.hxx:123
static bool validModelPath(const std::string &model)
Definition Schedule.cxx:322
bool operator<(const FGAISchedule &other) const
Definition Schedule.cxx:700
std::string getCallSign()
Definition Schedule.cxx:552
void setLastUsed(unsigned int val)
Definition Schedule.hxx:142
time_t getDepartureTime()
Definition Schedule.cxx:520
const std::string & getFlightType()
Definition Schedule.hxx:117
std::string getFlightRules()
Definition Schedule.cxx:560
int getLastUsed()
Definition Schedule.hxx:141
double getGroundOffset()
Definition Schedule.hxx:116
static SGPath resolveModelPath(const std::string &model)
Definition Schedule.cxx:327
static bool compareSchedules(const FGAISchedule *a, const FGAISchedule *b)
Definition Schedule.cxx:695
void clearAllFlights()
Warning - will empty the flights vector no matter what.
Definition Schedule.cxx:421
bool update(time_t now, const SGVec3d &userCart)
Returns true when processing is complete.
Definition Schedule.cxx:190
void setHeading()
Create an initial heading for user controlled aircraft.
Definition Schedule.cxx:411
void setrunCount(unsigned int count)
Definition Schedule.hxx:128
double getScore()
Definition Schedule.hxx:131
const std::string & getAirline()
Definition Schedule.hxx:118
double getRadius()
Definition Schedule.hxx:115
void assign(FGScheduledFlight *ref)
Definition Schedule.cxx:416
FGAirport * getDepartureAirport()
Definition Schedule.cxx:528
const std::string & getRegistration()
Definition Schedule.hxx:121
unsigned int getRunCount()
Definition Schedule.hxx:125
unsigned int getHits()
Definition Schedule.hxx:126
double getSpeed()
Definition Schedule.cxx:664
int getCruiseAlt()
Definition Schedule.cxx:544
void setFlightType(const std::string &val)
Definition Schedule.hxx:136
FGAirport * getArrivalAirport()
Definition Schedule.cxx:536
void setHits(unsigned int count)
Definition Schedule.hxx:129
FGAISchedule(const std::string &model, const std::string &livery, const std::string &homePort, const std::string &registration, const std::string &flightId, bool heavy, const std::string &acType, const std::string &airline, const std::string &m_class, const std::string &flight_type, double radius, double offset)