]> git.mxchange.org Git - flightgear.git/blob - src/ATC/AILocalTraffic.hxx
Some fixes to Alexander's pop-up dialog box
[flightgear.git] / src / ATC / AILocalTraffic.hxx
1 // FGAILocalTraffic - AIEntity derived class with enough logic to
2 // fly and interact with the traffic pattern.
3 //
4 // Written by David Luff, started March 2002.
5 //
6 // Copyright (C) 2002  David C. Luff - david.luff@nottingham.ac.uk
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 #ifndef _FG_AILocalTraffic_HXX
23 #define _FG_AILocalTraffic_HXX
24
25 #include <plib/sg.h>
26 #include <plib/ssg.h>
27 #include <simgear/math/point3d.hxx>
28 #include <Main/fg_props.hxx>
29
30 #include "tower.hxx"
31 #include "AIPlane.hxx"
32 #include "ATCProjection.hxx"
33 #include "ground.hxx"
34
35 #include <string>
36 SG_USING_STD(string);
37
38 enum PatternLeg {
39         TAKEOFF_ROLL,
40         CLIMBOUT,
41         TURN1,
42         CROSSWIND,
43         TURN2,
44         DOWNWIND,
45         TURN3,
46         BASE,
47         TURN4,
48         FINAL,
49         LANDING_ROLL
50 };
51
52 enum TaxiState {
53         TD_INBOUND,
54         TD_OUTBOUND,
55         TD_NONE,
56         TD_LINING_UP
57 };
58
59 enum OperatingState {
60         IN_PATTERN,
61         TAXIING,
62         PARKED
63 };
64
65 struct StartofDescent {
66         PatternLeg leg;
67         double orthopos_x;
68         double orthopos_y;
69 };
70
71 class FGAILocalTraffic : public FGAIPlane {
72         
73 public:
74         
75         FGAILocalTraffic();
76         ~FGAILocalTraffic();
77         
78         // Initialise
79         bool Init(string ICAO, OperatingState initialState = PARKED, PatternLeg initialLeg = DOWNWIND);
80         
81         // Run the internal calculations
82         void Update(double dt);
83         
84         // Go out and practice circuits
85         void FlyCircuits(int numCircuits, bool tag);
86         
87         // TODO - this will get more complex and moved into the main class
88         // body eventually since the position approved to taxi to will have
89         // to be passed.
90         inline void ApproveTaxiRequest() {taxiRequestCleared = true;}
91         
92         inline void DenyTaxiRequest() {taxiRequestCleared = false;}
93         
94         void RegisterTransmission(int code); 
95         
96         // This is a hack and will probably go eventually
97         inline bool AtHoldShort() {return(holdingShort);}
98         
99 protected:
100         
101         // Attempt to enter the traffic pattern in a reasonably intelligent manner
102         void EnterTrafficPattern(double dt);
103         
104         // Do what is necessary to land and parkup at home airport
105         void ReturnToBase(double dt);
106         
107 private:
108         FGATCMgr* ATC;  
109         // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
110
111         // High-level stuff
112         OperatingState operatingState;
113         int circuitsToFly;      //Number of circuits still to do in this session NOT INCLUDING THE CURRENT ONE
114         bool touchAndGo;        //True if circuits should be flown touch and go, false for full stop
115         
116         // Its possible that this might be moved out to the ground/airport class at some point.
117         FGATCAlignedProjection ortho;   // Orthogonal mapping of the local area with the threshold at the origin
118         // and the runway aligned with the y axis.
119         
120         // Airport/runway/pattern details
121         string airportID;       // The ICAO code of the airport that we're operating around
122         double aptElev;         // Airport elevation
123         FGGround* ground;       // A pointer to the ground control.
124         FGTower* tower; // A pointer to the tower control.
125         RunwayDetails rwy;
126         double patternDirection;        // 1 for right, -1 for left (This is double because we multiply/divide turn rates
127         // with it to get RH/LH turns - DON'T convert it to int under ANY circumstances!!
128         double glideAngle;              // Assumed to be visual glidepath angle for FGAILocalTraffic - can be found at www.airnav.com
129         // Its conceivable that patternDirection and glidePath could be moved into the RunwayDetails structure.
130         
131         // Performance characteristics of the plane in knots and ft/min - some of this might get moved out into FGAIPlane
132         double Vr;
133         double best_rate_of_climb_speed;
134         double best_rate_of_climb;
135         double nominal_climb_speed;
136         double nominal_climb_rate;
137         double nominal_circuit_speed;
138         double min_circuit_speed;
139         double max_circuit_speed;
140         double nominal_descent_rate;
141         double nominal_approach_speed;
142         double nominal_final_speed;
143         double stall_speed_landing_config;
144         double nominal_taxi_speed;
145         
146         // Physical/rendering stuff
147         double wheelOffset;             // Height above ground at which we need to render the plane whilst taxiing
148         bool elevInitGood;              // We have had at least one good elev reading
149         bool inAir;                             // True when off the ground 
150         
151         // environment - some of this might get moved into FGAIPlane
152         SGPropertyNode* wind_from_hdg;  //degrees
153         SGPropertyNode* wind_speed_knots;               //knots
154         
155         // Pattern details that (may) change
156         int numInPattern;               // Number of planes in the pattern (this might get more complicated if high performance GA aircraft fly a higher pattern eventually)
157         int numAhead;           // More importantly - how many of them are ahead of us?
158         double distToNext;              // And even more importantly, how near are we getting to the one immediately ahead?
159         PatternLeg leg;         // Out current position in the pattern
160         StartofDescent SoD;             // Start of descent calculated wrt wind, pattern size & altitude, glideslope etc
161
162         // Taxiing details
163         // At the moment this assumes that all taxiing in is to gates (a loose term that includes
164         // any permitted parking spot) and that all taxiing out is to runways.
165         bool parked;
166         bool taxiing;
167         bool taxiRequestPending;
168         bool taxiRequestCleared;
169         TaxiState taxiState;
170         double desiredTaxiHeading;
171         double taxiTurnRadius;
172         double nominalTaxiSpeed;
173         Gate* ourGate;
174         ground_network_path_type path;  // a path through the ground network for the plane to taxi
175         unsigned int taxiPathPos;       // position of iterator in taxi path when applicable
176         node* nextTaxiNode;     // next node in taxi path
177         node* holdShortNode;
178         //Runway out_dest; //FIXME - implement this
179         bool holdingShort;
180         bool reportReadyForDeparture;   // set true when ATC has requested that the plane report when ready for departure
181         bool clearedToLineUp;
182         bool clearedToTakeOff;
183         bool liningUp;  // Set true when the turn onto the runway heading is commenced when taxiing out
184         bool contactTower;      // we have been told to contact tower
185         bool contactGround;     // we have been told to contact ground
186         bool changeFreq;        // true when we need to change frequency
187         atc_type changeFreqType;        // the service we need to change to
188         double responseCounter;         // timer in seconds to allow response to requests to be a little while after them
189
190         void FlyTrafficPattern(double dt);
191
192         // TODO - need to add something to define what option we are flying - Touch and go / Stop and go / Landing properly / others?
193
194         void TransmitPatternPositionReport();
195
196         void CalculateStartofDescent();
197
198         void ExitRunway(Point3D orthopos);
199
200         void StartTaxi();
201
202         void Taxi(double dt);
203
204         void GetNextTaxiNode();
205         
206         void DoGroundElev();
207         
208         void GetRwyDetails();
209 };
210
211 #endif  // _FG_AILocalTraffic_HXX