]> git.mxchange.org Git - flightgear.git/blob - src/Airports/dynamics.hxx
Code cleanups, code updates and fix at least on (possible) devide-by-zero
[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 #include <simgear/timing/timestamp.hxx>
29
30 #include <ATC/trafficcontrol.hxx>
31 #include <ATC/GroundController.hxx>
32
33 #include "airports_fwd.hxx"
34 #include "parking.hxx"
35 #include "runwayprefs.hxx"
36
37 class ParkingAssignment
38 {
39 public:
40   ParkingAssignment();
41   ~ParkingAssignment();
42   
43 // create a parking assignment (and mark it as unavailable)
44   ParkingAssignment(FGParking* pk, FGAirportDynamics* apt);
45   
46   ParkingAssignment(const ParkingAssignment& aOther);
47   void operator=(const ParkingAssignment& aOther);
48   
49   bool isValid() const;
50   FGParking* parking() const;
51   
52   void release();
53 private:
54   void clear();
55
56   class ParkingAssignmentPrivate;
57   ParkingAssignmentPrivate* _sharedData;
58 };
59
60 class FGAirportDynamics : public SGReferenced
61 {
62
63 private:
64     FGAirport* _ap;
65
66     typedef std::set<FGParkingRef> ParkingSet;
67     // if a parking item is in this set, it is occupied
68     ParkingSet occupiedParkings;
69
70     FGRunwayPreference   rwyPrefs;
71     FGStartupController  startupController;
72     FGTowerController    towerController;
73     FGApproachController approachController;
74     FGGroundController   groundController;
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
83     int atisSequenceIndex;
84     double atisSequenceTimeStamp;
85
86     std::string chooseRunwayFallback();
87     bool innerGetActiveRunway(const std::string &trafficType, int action, std::string &runway, double heading);
88     std::string chooseRwyByHeading(stringVec rwys, double heading);
89
90     FGParking* innerGetAvailableParking(double radius, const std::string & flType,
91                                const std::string & airline,
92                                bool skipEmptyAirlineCode);
93
94     std::string fallbackGetActiveRunway(int action, double heading);
95
96     // runway preference fallback data
97     SGTimeStamp _lastFallbackUpdate;
98     FGRunwayList _fallbackDepartureRunways,
99         _fallbackArrivalRunways;
100     unsigned int _fallbackRunwayCounter;
101
102 public:
103     FGAirportDynamics(FGAirport* ap);
104     virtual ~FGAirportDynamics();
105
106     void init();
107   
108     double getElevation() const;
109     const std::string getId() const;
110   
111     FGAirport* parent() const
112     { return _ap; }
113   
114     void getActiveRunway( const std::string& trafficType,
115                           int action,
116                           std::string& runway,
117                           double heading );
118
119     bool hasParkings() const;
120
121     /**
122      * retrieve an available parking by GateID, or -1 if no suitable
123      * parking location could be found.
124      */
125     ParkingAssignment getAvailableParking(double radius, const std::string& fltype,
126                           const std::string& acType, const std::string& airline);
127
128     void setParkingAvailable(FGParking* park, bool available);
129   
130     bool isParkingAvailable(FGParking* parking) const;
131   
132     void releaseParking(FGParking* id);
133
134     FGParkingList getParkings(bool onlyAvailable, const std::string& type) const;
135
136     /**
137      * Find a parking gate index by name. Note names are often not unique
138      * in our data, so will return the first match. If the parking is found,
139      * it will be marked as in-use (unavailable)
140      */
141     ParkingAssignment getParkingByName(const std::string& name) const;
142
143     // ATC related functions.
144     FGStartupController    *getStartupController()    {
145         return &startupController;
146     };
147     FGGroundController        *getGroundController()        {
148         return &groundController;
149     };
150     FGTowerController      *getTowerController()      {
151         return &towerController;
152     };
153     FGApproachController   *getApproachController()   {
154         return &approachController;
155     };
156
157     FGGroundNetwork* getGroundNetwork() const;
158
159     int getGroundFrequency(unsigned leg);
160     int getTowerFrequency  (unsigned nr);
161
162     /// get current ATIS sequence letter
163     const std::string getAtisSequence();
164
165     /// get the current ATIS sequence number, updating it if necessary
166     int updateAtisSequence(int interval, bool forceUpdate);
167
168     void setRwyUse(const FGRunwayPreference& ref);
169 };
170
171
172
173 #endif