]> git.mxchange.org Git - flightgear.git/blob - src/ATC/AILocalTraffic.hxx
Preliminary support for AI planes from Dave Luff. This works only at
[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
37 #include "tower.hxx"
38 #include "AIPlane.hxx"
39 #include "ATCProjection.hxx"
40
41 typedef enum PatternLeg {
42     TAKEOFF_ROLL,
43     CLIMBOUT,
44     TURN1,
45     CROSSWIND,
46     TURN2,
47     DOWNWIND,
48     TURN3,
49     BASE,
50     TURN4,
51     FINAL,
52     LANDING_ROLL
53 };
54
55 // perhaps we could use an FGRunway instead of this
56 typedef struct RunwayDetails {
57     Point3D threshold_pos;
58     Point3D end1ortho;  // ortho projection end1 (the threshold ATM)
59     Point3D end2ortho;  // ortho projection end2 (the take off end in the current hardwired scheme)
60     double mag_hdg;
61     double mag_var;
62     double hdg;         // true runway heading
63 };
64
65 typedef 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     void Init();
80
81     // Run the internal calculations
82     void Update(double dt);
83
84 protected:
85
86     // Attempt to enter the traffic pattern in a reasonably intelligent manner
87     void EnterTrafficPattern(double dt);
88
89 private:
90     FGATCAlignedProjection ortho;       // Orthogonal mapping of the local area with the threshold at the origin
91                                         // and the runway aligned with the y axis.
92
93     // Airport/runway/pattern details
94     char* airport;      // The ICAO code of the airport that we're operating around
95     FGTower* tower;     // A pointer to the tower control.
96     RunwayDetails rwy;
97     double patternDirection;    // 1 for right, -1 for left (This is double because we multiply/divide turn rates
98                                 // with it to get RH/LH turns - DON'T convert it to int under ANY circumstances!!
99     double glideAngle;          // Assumed to be visual glidepath angle for FGAILocalTraffic - can be found at www.airnav.com
100     // Its conceivable that patternDirection and glidePath could be moved into the RunwayDetails structure.
101
102     // Performance characteristics of the plane in knots and ft/min - some of this might get moved out into FGAIPlane
103     double Vr;
104     double best_rate_of_climb_speed;
105     double best_rate_of_climb;
106     double nominal_climb_speed;
107     double nominal_climb_rate;
108     double nominal_circuit_speed;
109     double min_circuit_speed;
110     double max_circuit_speed;
111     double nominal_descent_rate;
112     double nominal_approach_speed;
113     double nominal_final_speed;
114     double stall_speed_landing_config;
115
116     // environment - some of this might get moved into FGAIPlane
117     double wind_from_hdg;       // degrees
118     double wind_speed_knots;    // knots
119
120     // Pattern details that (may) change
121     int numInPattern;           // Number of planes in the pattern (this might get more complicated if high performance GA aircraft fly a higher pattern eventually)
122     int numAhead;               // More importantly - how many of them are ahead of us?
123     double distToNext;          // And even more importantly, how near are we getting to the one immediately ahead?
124     PatternLeg leg;             // Out current position in the pattern
125     StartofDescent SoD;         // Start of descent calculated wrt wind, pattern size & altitude, glideslope etc
126
127     void FlyTrafficPattern(double dt);
128
129     // TODO - need to add something to define what option we are flying - Touch and go / Stop and go / Landing properly / others?
130
131     void TransmitPatternPositionReport();
132
133     void CalculateStartofDescent();
134 };
135
136 #endif  // _FG_AILocalTraffic_HXX