]> git.mxchange.org Git - flightgear.git/blob - src/ATC/AILocalTraffic.hxx
Removed DOS line endings
[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 /*****************************************************************
23 *
24 * WARNING - Curt has some ideas about AI traffic so anything in here
25 * may get rewritten or scrapped.  Contact Curt curt@flightgear.org 
26 * before spending any time or effort on this code!!!
27 *
28 ******************************************************************/
29
30 #ifndef _FG_AILocalTraffic_HXX
31 #define _FG_AILocalTraffic_HXX
32
33 #include <plib/sg.h>
34 #include <plib/ssg.h>
35 #include <simgear/math/point3d.hxx>
36 #include <Main/fg_props.hxx>
37
38 #include "tower.hxx"
39 #include "AIPlane.hxx"
40 #include "ATCProjection.hxx"
41 #include "ground.hxx"
42
43 typedef enum PatternLeg {
44         TAKEOFF_ROLL,
45         CLIMBOUT,
46         TURN1,
47         CROSSWIND,
48         TURN2,
49         DOWNWIND,
50         TURN3,
51         BASE,
52         TURN4,
53         FINAL,
54         LANDING_ROLL
55 };
56
57 typedef enum TaxiState {
58         TD_INBOUND,
59         TD_OUTBOUND,
60         TD_NONE
61 };
62
63 typedef enum OperatingState {
64         IN_PATTERN,
65         TAXIING,
66         PARKED
67 };
68
69 // perhaps we could use an FGRunway instead of this
70 typedef struct RunwayDetails {
71         Point3D threshold_pos;
72         Point3D end1ortho;      // ortho projection end1 (the threshold ATM)
73         Point3D end2ortho;      // ortho projection end2 (the take off end in the current hardwired scheme)
74         double mag_hdg;
75         double mag_var;
76         double hdg;             // true runway heading
77         int ID;         // 1 -> 36
78 };
79
80 typedef struct StartofDescent {
81         PatternLeg leg;
82         double orthopos_x;
83         double orthopos_y;
84 };
85
86 class FGAILocalTraffic : public FGAIPlane {
87         
88 public:
89         
90         FGAILocalTraffic();
91         ~FGAILocalTraffic();
92         
93         // Initialise
94         void Init();
95         
96         // Run the internal calculations
97         void Update(double dt);
98         
99         // Go out and practice circuits
100         void FlyCircuits(int numCircuits, bool tag);
101         
102 protected:
103         
104         // Attempt to enter the traffic pattern in a reasonably intelligent manner
105         void EnterTrafficPattern(double dt);
106         
107         // Do what is necessary to land and parkup at home airport
108         void ReturnToBase(double dt);
109         
110 private:
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         char* airportID;        // The ICAO code of the airport that we're operating around
122         FGGround airport;       // FIXME FIXME FIXME This is a complete hardwired cop-out at the moment - we need to connect to the correct ground in the same way we do to the tower.
123         FGTower* tower; // A pointer to the tower control.
124         RunwayDetails rwy;
125         double patternDirection;        // 1 for right, -1 for left (This is double because we multiply/divide turn rates
126         // with it to get RH/LH turns - DON'T convert it to int under ANY circumstances!!
127         double glideAngle;              // Assumed to be visual glidepath angle for FGAILocalTraffic - can be found at www.airnav.com
128         // Its conceivable that patternDirection and glidePath could be moved into the RunwayDetails structure.
129         
130         // Performance characteristics of the plane in knots and ft/min - some of this might get moved out into FGAIPlane
131         double Vr;
132         double best_rate_of_climb_speed;
133         double best_rate_of_climb;
134         double nominal_climb_speed;
135         double nominal_climb_rate;
136         double nominal_circuit_speed;
137         double min_circuit_speed;
138         double max_circuit_speed;
139         double nominal_descent_rate;
140         double nominal_approach_speed;
141         double nominal_final_speed;
142         double stall_speed_landing_config;
143         double nominal_taxi_speed;
144         
145         // Physical/rendering stuff
146         double wheelOffset;             // Height above ground at which we need to render the plane whilst taxiing
147         
148         // environment - some of this might get moved into FGAIPlane
149         SGPropertyNode* wind_from_hdg;  //degrees
150         SGPropertyNode* wind_speed_knots;               //knots
151         
152         // Pattern details that (may) change
153         int numInPattern;               // Number of planes in the pattern (this might get more complicated if high performance GA aircraft fly a higher pattern eventually)
154         int numAhead;           // More importantly - how many of them are ahead of us?
155         double distToNext;              // And even more importantly, how near are we getting to the one immediately ahead?
156         PatternLeg leg;         // Out current position in the pattern
157         StartofDescent SoD;             // Start of descent calculated wrt wind, pattern size & altitude, glideslope etc
158
159         // Taxiing details
160         // At the moment this assumes that all taxiing in is to gates (a loose term that includes
161         // any permitted parking spot) and that all taxiing out is to runways.
162         bool parked;
163         bool taxiing;
164         TaxiState taxiState;
165         double desiredTaxiHeading;
166         double taxiTurnRadius;
167         double nominalTaxiSpeed;
168         Gate* in_dest;
169         ground_network_path_type path;  // a path through the ground network for the plane to taxi
170         int taxiPathPos;        // position of iterator in taxi path when applicable
171         node* nextTaxiNode;     // next node in taxi path
172         //Runway out_dest; //FIXME - implement this
173
174         void FlyTrafficPattern(double dt);
175
176         // TODO - need to add something to define what option we are flying - Touch and go / Stop and go / Landing properly / others?
177
178         void TransmitPatternPositionReport();
179
180         void CalculateStartofDescent();
181
182         void ExitRunway(Point3D orthopos);
183
184         void StartTaxi();
185
186         void Taxi(double dt);
187
188         void GetNextTaxiNode();
189         
190         void DoGroundElev();
191 };
192
193 #endif  // _FG_AILocalTraffic_HXX