| 1 | /* -*- Mode: C++ -*- ***************************************************** |
| 2 | * SchedFlight.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 | * ScheduledFlight is a class that is used by FlightGear's Traffic Manager |
| 24 | * A scheduled flight can be assigned to a schedule, which can be assigned |
| 25 | * to an aircraft. The traffic manager decides for each schedule which |
| 26 | * scheduled flight (if any) is currently active. I no scheduled flights |
| 27 | * are found active, it tries to position the aircraft associated with this |
| 28 | * schedule at departure airport of the next scheduled flight. |
| 29 | * The class ScheduledFlight is a software implementation of this. |
| 30 | * In summary, this class stores arrival and departure information, as well |
| 31 | * as some administrative data, such as the callsign of this particular |
| 32 | * flight (used in future ATC scenarios), under which flight rules the |
| 33 | * flight is taking place, as well as a requested initial cruise altitude. |
| 34 | * Finally, the class contains a repeat period, which indicates after how |
| 35 | * many seconds a flight should repeat in this schedule (which is usually |
| 36 | * after either a day or a week). If this value is zero, this flight won't |
| 37 | * repeat. |
| 38 | **************************************************************************/ |
| 39 | |
| 40 | #pragma once |
| 41 | |
| 42 | |
| 43 | class FGAirport; |
| 44 | |
| 45 | class FGScheduledFlight |
| 46 | { |
| 47 | private: |
| 48 | static std::map<std::string, std::string> missingAirports; |
| 49 | |
| 50 | std::string callsign; |
| 51 | std::string fltRules; |
| 52 | |
| 53 | FGAirport *departurePort; |
| 54 | FGAirport *arrivalPort; |
| 55 | |
| 56 | std::string depId; |
| 57 | std::string arrId; |
| 58 | std::string requiredAircraft; |
| 59 | |
| 60 | time_t departureTime; |
| 61 | time_t arrivalTime; |
| 62 | time_t repeatPeriod; |
| 63 | |
| 64 | int cruiseAltitude; |
| 65 | bool initialized; |
| 66 | bool available; |
| 67 | |
| 68 | public: |
| 69 | FGScheduledFlight(); |
| 70 | FGScheduledFlight(const FGScheduledFlight &other); |
| 71 | // FGScheduledFlight(const std::string); |
| 72 | FGScheduledFlight(const std::string& cs, |
| 73 | const std::string& fr, |
| 74 | const std::string& depPrt, |
| 75 | const std::string& arrPrt, |
| 76 | int cruiseAlt, |
| 77 | const std::string& deptime, |
| 78 | const std::string& arrtime, |
| 79 | const std::string& rep, |
| 80 | const std::string& reqAC |
| 81 | ); |
| 82 | ~FGScheduledFlight(); |
| 83 | |
| 84 | void update(); |
| 85 | bool initializeAirports(); |
| 86 | |
| 87 | void adjustTime(time_t now); |
| 88 | |
| 89 | time_t getDepartureTime() { return departureTime; }; |
| 90 | time_t getArrivalTime () { return arrivalTime; }; |
| 91 | |
| 92 | void setDepartureAirport(const std::string& port) { depId = port; }; |
| 93 | void setArrivalAirport (const std::string& port) { arrId = port; }; |
| 94 | FGAirport *getDepartureAirport(); |
| 95 | FGAirport *getArrivalAirport (); |
| 96 | |
| 97 | int getCruiseAlt() { return cruiseAltitude; }; |
| 98 | |
| 99 | bool operator<(const FGScheduledFlight &other) const |
| 100 | { |
| 101 | return (departureTime < other.departureTime); |
| 102 | }; |
| 103 | const std::string& getFlightRules() { return fltRules; }; |
| 104 | |
| 105 | time_t processTimeString(const std::string& time); |
| 106 | const std::string& getCallSign() {return callsign; }; |
| 107 | const std::string& getRequirement() { return requiredAircraft; } |
| 108 | |
| 109 | void lock() { available = false; }; |
| 110 | void release() { available = true; }; |
| 111 | |
| 112 | bool isAvailable() { return available; }; |
| 113 | |
| 114 | void setCallSign(const std::string& val) { callsign = val; }; |
| 115 | void setFlightRules(const std::string& val) { fltRules = val; }; |
| 116 | |
| 117 | static bool compareScheduledFlights(const FGScheduledFlight *a, const FGScheduledFlight *b); |
| 118 | }; |
| 119 | |
| 120 | typedef std::vector<FGScheduledFlight*> FGScheduledFlightVec; |
| 121 | typedef std::vector<FGScheduledFlight*>::iterator FGScheduledFlightVecIterator; |
| 122 | |
| 123 | typedef std::map < std::string, FGScheduledFlightVec > FGScheduledFlightMap; |