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