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