]> git.mxchange.org Git - flightgear.git/blob - src/Airports/dynamics.hxx
GUI ‘restore defaults’ support.
[flightgear.git] / src / Airports / dynamics.hxx
1 // dynamics.hxx - a class to manage the higher order airport ground activities
2 // Written by Durk Talsma, started December 2004.
3 //
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 // $Id$
20
21
22 #ifndef _AIRPORT_DYNAMICS_HXX_
23 #define _AIRPORT_DYNAMICS_HXX_
24
25 #include <set>
26
27 #include <ATC/trafficcontrol.hxx>
28 #include "airports_fwd.hxx"
29 #include "parking.hxx"
30 #include "groundnetwork.hxx"
31 #include "runwayprefs.hxx"
32
33 class ParkingAssignment
34 {
35 public:
36   ParkingAssignment();
37   ~ParkingAssignment();
38   
39 // create a parking assignment (and mark it as unavailable)
40   ParkingAssignment(FGParking* pk, FGAirport* apt);
41   
42   ParkingAssignment(const ParkingAssignment& aOther);
43   void operator=(const ParkingAssignment& aOther);
44   
45   bool isValid() const;
46   FGParking* parking() const;
47   
48   void release();
49 private:
50   void clear();
51
52   class ParkingAssignmentPrivate;
53   ParkingAssignmentPrivate* _sharedData;
54 };
55
56 class FGAirportDynamics {
57
58 private:
59     FGAirport* _ap;
60
61     typedef std::set<PositionedID> ParkingSet;
62     // if a parking item is in this set, it is occupied
63     ParkingSet occupiedParkings;
64
65     FGRunwayPreference   rwyPrefs;
66     FGStartupController  startupController;
67     FGGroundNetwork      groundNetwork;
68     FGTowerController    towerController;
69     FGApproachController approachController;
70
71     time_t lastUpdate;
72     std::string prevTrafficType;
73     stringVec landing;
74     stringVec takeoff;
75     stringVec milActive, comActive, genActive, ulActive;
76     stringVec *currentlyActive;
77     intVec freqAwos;     // </AWOS>
78     intVec freqUnicom;   // </UNICOM>
79     intVec freqClearance;// </CLEARANCE>
80     intVec freqGround;   // </GROUND>
81     intVec freqTower;    // </TOWER>
82     intVec freqApproach; // </APPROACH>
83
84     int atisSequenceIndex;
85     double atisSequenceTimeStamp;
86
87     std::string chooseRunwayFallback();
88     bool innerGetActiveRunway(const std::string &trafficType, int action, std::string &runway, double heading);
89     std::string chooseRwyByHeading(stringVec rwys, double heading);
90
91     FGParking* innerGetAvailableParking(double radius, const std::string & flType,
92                                const std::string & airline,
93                                bool skipEmptyAirlineCode);
94 public:
95     FGAirportDynamics(FGAirport* ap);
96     ~FGAirportDynamics();
97
98     void addAwosFreq     (int val) {
99         freqAwos.push_back(val);
100     };
101     void addUnicomFreq   (int val) {
102         freqUnicom.push_back(val);
103     };
104     void addClearanceFreq(int val) {
105         freqClearance.push_back(val);
106     };
107     void addGroundFreq   (int val) {
108         freqGround.push_back(val);
109     };
110     void addTowerFreq    (int val) {
111         freqTower.push_back(val);
112     };
113     void addApproachFreq (int val) {
114         freqApproach.push_back(val);
115     };
116
117     void init();
118   
119     double getElevation() const;
120     const std::string getId() const;
121   
122     FGAirport* parent() const
123     { return _ap; }
124   
125     void getActiveRunway( const std::string& trafficType,
126                           int action,
127                           std::string& runway,
128                           double heading );
129     
130     /**
131      * retrieve an available parking by GateID, or -1 if no suitable
132      * parking location could be found.
133      */
134     ParkingAssignment getAvailableParking(double radius, const std::string& fltype,
135                           const std::string& acType, const std::string& airline);
136
137     void setParkingAvailable(PositionedID guid, bool available);
138   
139     bool isParkingAvailable(PositionedID parking) const;
140   
141     FGParkingRef getParking(PositionedID i) const;
142     void releaseParking(PositionedID id);
143     std::string getParkingName(PositionedID i) const;
144
145     /**
146      * Find a parking gate index by name. Note names are often not unique
147      * in our data, so will return the first match. If the parking is found,
148      * it will be marked as in-use (unavailable)
149      */
150     ParkingAssignment getParkingByName(const std::string& name) const;
151
152     // ATC related functions.
153     FGStartupController    *getStartupController()    {
154         return &startupController;
155     };
156     FGGroundNetwork        *getGroundNetwork()        {
157         return &groundNetwork;
158     };
159     FGTowerController      *getTowerController()      {
160         return &towerController;
161     };
162     FGApproachController   *getApproachController()   {
163         return &approachController;
164     };
165
166     int getGroundFrequency(unsigned leg);
167     int getTowerFrequency  (unsigned nr);
168
169     /// get current ATIS sequence letter
170     const std::string getAtisSequence();
171
172     /// get the current ATIS sequence number, updating it if necessary
173     int updateAtisSequence(int interval, bool forceUpdate);
174
175     void setRwyUse(const FGRunwayPreference& ref);
176 };
177
178
179
180 #endif