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