]> git.mxchange.org Git - flightgear.git/blob - src/Airports/dynamics.hxx
toggle fullscreen: also adapt GUI plane when resizing
[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 "parking.hxx"
29 #include "groundnetwork.hxx"
30 #include "runwayprefs.hxx"
31
32 // forward decls
33 class FGAirport;
34 class FGEnvironment;
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, FGAirport* 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 {
60
61 private:
62     FGAirport* _ap;
63
64     typedef std::set<PositionedID> ParkingSet;
65     // if a parking item is in this set, it is occupied
66     ParkingSet occupiedParkings;
67
68     FGRunwayPreference   rwyPrefs;
69     FGStartupController  startupController;
70     FGGroundNetwork      groundNetwork;
71     FGTowerController    towerController;
72     FGApproachController approachController;
73
74     time_t lastUpdate;
75     std::string prevTrafficType;
76     stringVec landing;
77     stringVec takeoff;
78     stringVec milActive, comActive, genActive, ulActive;
79     stringVec *currentlyActive;
80     intVec freqAwos;     // </AWOS>
81     intVec freqUnicom;   // </UNICOM>
82     intVec freqClearance;// </CLEARANCE>
83     intVec freqGround;   // </GROUND>
84     intVec freqTower;    // </TOWER>
85     intVec freqApproach; // </APPROACH>
86
87     int atisSequenceIndex;
88     double atisSequenceTimeStamp;
89
90     std::string chooseRunwayFallback();
91     bool innerGetActiveRunway(const std::string &trafficType, int action, std::string &runway, double heading);
92     std::string chooseRwyByHeading(stringVec rwys, double heading);
93
94     FGParking* innerGetAvailableParking(double radius, const std::string & flType,
95                                const std::string & airline,
96                                bool skipEmptyAirlineCode);
97 public:
98     FGAirportDynamics(FGAirport* ap);
99     ~FGAirportDynamics();
100
101     void addAwosFreq     (int val) {
102         freqAwos.push_back(val);
103     };
104     void addUnicomFreq   (int val) {
105         freqUnicom.push_back(val);
106     };
107     void addClearanceFreq(int val) {
108         freqClearance.push_back(val);
109     };
110     void addGroundFreq   (int val) {
111         freqGround.push_back(val);
112     };
113     void addTowerFreq    (int val) {
114         freqTower.push_back(val);
115     };
116     void addApproachFreq (int val) {
117         freqApproach.push_back(val);
118     };
119
120     void init();
121   
122     double getElevation() const;
123     const std::string getId() const;
124   
125     FGAirport* parent() const
126     { return _ap; }
127   
128     void getActiveRunway(const string& trafficType, int action, string& runway, 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     FGParking *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