2004-06-03 17:59:14 +00:00
|
|
|
/* -*- Mode: C++ -*- *****************************************************
|
|
|
|
* Schedule.hxx
|
|
|
|
* Written by Durk Talsma. Started May 5, 2004
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-06-03 17:59:14 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************************************
|
2012-11-24 11:59:13 +01:00
|
|
|
* This file contains the definition of the class Schedule.
|
2004-06-03 17:59:14 +00:00
|
|
|
*
|
2012-11-24 11:59:13 +01:00
|
|
|
* A schedule is basically a number of scheduled flights, which can be
|
2004-06-03 17:59:14 +00:00
|
|
|
* assigned to an AI aircraft.
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _FGSCHEDULE_HXX_
|
|
|
|
#define _FGSCHEDULE_HXX_
|
|
|
|
|
2008-11-16 13:45:24 +00:00
|
|
|
#define TRAFFICTOAIDISTTOSTART 150.0
|
|
|
|
#define TRAFFICTOAIDISTTODIE 200.0
|
2004-06-03 17:59:14 +00:00
|
|
|
|
2012-11-21 14:49:34 +00:00
|
|
|
// forward decls
|
|
|
|
class FGAIAircraft;
|
2015-12-11 12:11:46 -06:00
|
|
|
class FGScheduledFlight;
|
|
|
|
|
|
|
|
typedef std::vector<FGScheduledFlight*> FGScheduledFlightVec;
|
2004-11-29 09:41:43 +00:00
|
|
|
|
2004-06-03 17:59:14 +00:00
|
|
|
class FGAISchedule
|
|
|
|
{
|
|
|
|
private:
|
2012-11-23 21:00:20 +01:00
|
|
|
std::string modelPath;
|
|
|
|
std::string homePort;
|
|
|
|
std::string livery;
|
|
|
|
std::string registration;
|
|
|
|
std::string airline;
|
|
|
|
std::string acType;
|
|
|
|
std::string m_class;
|
|
|
|
std::string flightType;
|
|
|
|
std::string flightIdentifier;
|
|
|
|
std::string currentDestination;
|
2004-06-03 17:59:14 +00:00
|
|
|
bool heavy;
|
|
|
|
FGScheduledFlightVec flights;
|
2010-02-19 00:31:38 +00:00
|
|
|
SGGeod position;
|
2005-02-10 09:01:51 +00:00
|
|
|
double radius;
|
|
|
|
double groundOffset;
|
|
|
|
double distanceToUser;
|
2010-08-30 21:13:16 +02:00
|
|
|
double score;
|
|
|
|
unsigned int runCount;
|
|
|
|
unsigned int hits;
|
A number of cosmetic and/or infrastructural changes.
Traffic Manager:
* Just continue routing until we run out of flights. This change removes one of the major requirements for setting the "Home port" field.
* Add a time restriction requirement for the aircraft scheduler; this became necessary after removing the limited-to-home-port routing restriction.
* Added a new field to the heuristics calculation: take into account whether an aircraft has already been used in a previous session. Rotate aircraft assignments for greater variability across sessions.
* Added a revision number to the cache files, so that old cache results, which are no longer compatible with the new file format, are discarded.
Groundnetwork and traffic control:
* Added a revision number to the cache files, so that old and incompatible results are discarded.
* The caching algorithm probably didn't store the correct data for airports that were processed while the user was quite far away. This is now corrected by checking whether the cached elevation data are equal to the generic airport elevation.
AIAircraft:
* I've been searching for the infamous aircraft bend-over-backward bug, that can occur during initialization, but to no avail yet. The only variable potentially responsible (tgt_vs) wich can explain the irregular jumping behavior, as well as the weird pitch results is initialized in AIAircraft's only constructor (through AIBase), and I can't find any situation in the ground handling code where this variable could get bizarre values. But,
* a couple of tgt_vs. calculations appear to be completely redundant. This value was calculated twice inside the ProcessFlightplan function, and subsequently again in the updateSecondaryTargetValues function. I have removed the calculations in the process flightplan function, without any apparent side effect.
2011-09-04 20:27:36 +02:00
|
|
|
unsigned int lastRun;
|
2004-06-03 17:59:14 +00:00
|
|
|
bool firstRun;
|
2009-02-15 15:29:56 +00:00
|
|
|
double courseToDest;
|
2010-08-30 21:13:16 +02:00
|
|
|
bool initialized;
|
2011-04-19 18:01:24 +02:00
|
|
|
bool valid;
|
2012-11-25 16:41:10 +01:00
|
|
|
bool scheduleComplete;
|
2004-06-03 17:59:14 +00:00
|
|
|
|
2012-11-25 16:41:10 +01:00
|
|
|
bool scheduleFlights(time_t now);
|
2011-10-09 23:44:42 +02:00
|
|
|
int groundTimeFromRadius();
|
2010-02-19 00:31:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transition this schedule from distant mode to AI mode;
|
|
|
|
* create the AIAircraft (and flight plan) and register with the AIManager
|
|
|
|
*/
|
|
|
|
bool createAIAircraft(FGScheduledFlight* flight, double speedKnots, time_t deptime);
|
|
|
|
|
2012-11-21 14:49:34 +00:00
|
|
|
// the aiAircraft associated with us
|
|
|
|
SGSharedPtr<FGAIAircraft> aiAircraft;
|
2004-06-03 17:59:14 +00:00
|
|
|
public:
|
|
|
|
FGAISchedule(); // constructor
|
2012-11-24 11:59:13 +01:00
|
|
|
FGAISchedule(const std::string& model,
|
|
|
|
const std::string& livery,
|
|
|
|
const std::string& homePort,
|
|
|
|
const std::string& registration,
|
|
|
|
const std::string& flightId,
|
2008-11-16 13:45:24 +00:00
|
|
|
bool heavy,
|
2012-11-24 11:59:13 +01:00
|
|
|
const std::string& acType,
|
|
|
|
const std::string& airline,
|
|
|
|
const std::string& m_class,
|
|
|
|
const std::string& flight_type,
|
2008-11-16 13:45:24 +00:00
|
|
|
double radius,
|
|
|
|
double offset); // construct & init
|
2006-07-29 18:17:19 +00:00
|
|
|
FGAISchedule(const FGAISchedule &other); // copy constructor
|
2004-06-03 17:59:14 +00:00
|
|
|
|
2006-08-26 07:22:20 +00:00
|
|
|
|
|
|
|
|
2004-06-03 17:59:14 +00:00
|
|
|
~FGAISchedule(); //destructor
|
|
|
|
|
2012-05-03 11:05:37 +01:00
|
|
|
static bool validModelPath(const std::string& model);
|
2013-09-18 12:08:20 +01:00
|
|
|
static SGPath resolveModelPath(const std::string& model);
|
2012-05-03 11:05:37 +01:00
|
|
|
|
2010-02-19 00:31:38 +00:00
|
|
|
bool update(time_t now, const SGVec3d& userCart);
|
2005-02-10 09:01:51 +00:00
|
|
|
bool init();
|
|
|
|
|
|
|
|
double getSpeed ();
|
2006-07-29 18:17:19 +00:00
|
|
|
//void setClosestDistanceToUser();
|
2008-11-16 13:45:24 +00:00
|
|
|
bool next(); // forces the schedule to move on to the next flight.
|
2004-11-29 09:41:43 +00:00
|
|
|
|
2008-11-16 13:45:24 +00:00
|
|
|
// TODO: rework these four functions
|
2015-12-11 12:11:46 -06:00
|
|
|
time_t getDepartureTime ();
|
|
|
|
FGAirport * getDepartureAirport ();
|
|
|
|
FGAirport * getArrivalAirport ();
|
|
|
|
int getCruiseAlt ();
|
2005-02-10 09:01:51 +00:00
|
|
|
double getRadius () { return radius; };
|
|
|
|
double getGroundOffset () { return groundOffset;};
|
2012-11-24 11:59:13 +01:00
|
|
|
const std::string& getFlightType () { return flightType;};
|
|
|
|
const std::string& getAirline () { return airline; };
|
|
|
|
const std::string& getAircraft () { return acType; };
|
2015-12-18 21:42:22 -08:00
|
|
|
std::string getCallSign ();
|
2012-11-24 11:59:13 +01:00
|
|
|
const std::string& getRegistration () { return registration;};
|
2015-12-18 21:42:22 -08:00
|
|
|
std::string getFlightRules ();
|
2005-02-10 09:01:51 +00:00
|
|
|
bool getHeavy () { return heavy; };
|
2009-02-15 15:29:56 +00:00
|
|
|
double getCourse () { return courseToDest; };
|
2010-08-30 21:13:16 +02:00
|
|
|
unsigned int getRunCount () { return runCount; };
|
|
|
|
unsigned int getHits () { return hits; };
|
|
|
|
|
|
|
|
void setrunCount(unsigned int count) { runCount = count; };
|
|
|
|
void setHits (unsigned int count) { hits = count; };
|
2010-08-31 16:57:07 +02:00
|
|
|
void setScore ();
|
2010-08-30 21:13:16 +02:00
|
|
|
double getScore () { return score; };
|
2011-04-12 23:28:48 +02:00
|
|
|
void setHeading ();
|
2015-12-11 12:11:46 -06:00
|
|
|
void assign (FGScheduledFlight *ref);
|
2012-11-24 11:59:13 +01:00
|
|
|
void setFlightType (const std::string& val) { flightType = val; };
|
|
|
|
FGScheduledFlight*findAvailableFlight (const std::string& currentDestination, const std::string &req, time_t min=0, time_t max=0);
|
|
|
|
// used to sort in descending order of score: I've probably found a better way to
|
|
|
|
// descending order sorting, but still need to test that.
|
A number of cosmetic and/or infrastructural changes.
Traffic Manager:
* Just continue routing until we run out of flights. This change removes one of the major requirements for setting the "Home port" field.
* Add a time restriction requirement for the aircraft scheduler; this became necessary after removing the limited-to-home-port routing restriction.
* Added a new field to the heuristics calculation: take into account whether an aircraft has already been used in a previous session. Rotate aircraft assignments for greater variability across sessions.
* Added a revision number to the cache files, so that old cache results, which are no longer compatible with the new file format, are discarded.
Groundnetwork and traffic control:
* Added a revision number to the cache files, so that old and incompatible results are discarded.
* The caching algorithm probably didn't store the correct data for airports that were processed while the user was quite far away. This is now corrected by checking whether the cached elevation data are equal to the generic airport elevation.
AIAircraft:
* I've been searching for the infamous aircraft bend-over-backward bug, that can occur during initialization, but to no avail yet. The only variable potentially responsible (tgt_vs) wich can explain the irregular jumping behavior, as well as the weird pitch results is initialized in AIAircraft's only constructor (through AIBase), and I can't find any situation in the ground handling code where this variable could get bizarre values. But,
* a couple of tgt_vs. calculations appear to be completely redundant. This value was calculated twice inside the ProcessFlightplan function, and subsequently again in the updateSecondaryTargetValues function. I have removed the calculations in the process flightplan function, without any apparent side effect.
2011-09-04 20:27:36 +02:00
|
|
|
bool operator< (const FGAISchedule &other) const;
|
2012-11-24 11:59:13 +01:00
|
|
|
int getLastUsed() { return lastRun; };
|
|
|
|
void setLastUsed(unsigned int val) {lastRun = val; };
|
2005-02-10 09:01:51 +00:00
|
|
|
//void * getAiRef () { return AIManagerRef; };
|
|
|
|
//FGAISchedule* getAddress () { return this;};
|
2004-06-03 17:59:14 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-03-04 16:31:37 +01:00
|
|
|
typedef std::vector<FGAISchedule*> ScheduleVector;
|
|
|
|
typedef std::vector<FGAISchedule*>::iterator ScheduleVectorIterator;
|
2006-10-06 17:36:31 +00:00
|
|
|
|
|
|
|
bool compareSchedules(FGAISchedule*a, FGAISchedule*b);
|
2004-06-03 17:59:14 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|