]> git.mxchange.org Git - flightgear.git/blob - src/ATC/AIPlane.hxx
Migrate FlightGear code to use "#include SG_GL*" defined in
[flightgear.git] / src / ATC / AIPlane.hxx
1 // FGAIPlane - abstract base class for an AI plane
2 //
3 // Written by David Luff, started 2002.
4 //
5 // Copyright (C) 2002  David C. Luff - david.luff@nottingham.ac.uk
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 #ifndef _FG_AI_PLANE_HXX
22 #define _FG_AI_PLANE_HXX
23
24 #include <simgear/math/point3d.hxx>
25 #include <simgear/scene/model/model.hxx>
26
27 #include "AIEntity.hxx"
28 #include "ATC.hxx"
29
30 enum PatternLeg {
31         TAKEOFF_ROLL,
32         CLIMBOUT,
33         TURN1,
34         CROSSWIND,
35         TURN2,
36         DOWNWIND,
37         TURN3,
38         BASE,
39         TURN4,
40         FINAL,
41         LANDING_ROLL,
42         LEG_UNKNOWN
43 };
44
45 ostream& operator << (ostream& os, PatternLeg pl);
46
47 enum LandingType {
48         FULL_STOP,
49         STOP_AND_GO,
50         TOUCH_AND_GO,
51         AIP_LT_UNKNOWN
52 };
53
54 ostream& operator << (ostream& os, LandingType lt);
55
56 /*****************************************************************
57 *
58 *  FGAIPlane - this class is derived from FGAIEntity and adds the 
59 *  practical requirement for an AI plane - the ability to send radio
60 *  communication, and simple performance details for the actual AI
61 *  implementation to use.  The AI implementation is expected to be
62 *  in derived classes - this class does nothing useful on its own.
63 *
64 ******************************************************************/
65 class FGAIPlane : public FGAIEntity {
66
67 public:
68
69         FGAIPlane();
70     virtual ~FGAIPlane();
71
72     // Run the internal calculations
73         void Update(double dt);
74         
75         // Send a transmission *TO* the AIPlane.
76         // FIXME int code is a hack - eventually this will receive Alexander's coded messages.
77         virtual void RegisterTransmission(int code);
78         
79         // Return the current pattern leg the plane is flying.
80         inline PatternLeg GetLeg() {return leg;}
81         
82         // Return what type of landing we're doing on this circuit
83         virtual LandingType GetLandingOption();
84         
85         // Return the callsign
86         inline string GetCallsign() {return plane.callsign;}
87
88 protected:
89         PlaneRec plane;
90
91     double mag_hdg;     // degrees - the heading that the physical aircraft is *pointing*
92     double track;       // track that the physical aircraft is *following* - degrees relative to *true* north
93     double crab;        // Difference between heading and track due to wind.
94     double mag_var;     // degrees
95     double IAS;         // Indicated airspeed in knots
96     double vel;         // velocity along track in knots
97     double vel_si;      // velocity along track in m/s
98     double slope;       // Actual slope that the plane is flying (degrees) - +ve is uphill
99     double AoA;         // degrees - difference between slope and pitch
100     // We'll assume that the plane doesn't yaw or slip - the track/heading difference is to allow for wind
101
102     double freq;        // The comm frequency that we're operating on
103
104     // We need some way for this class to display its radio transmissions if on the 
105     // same frequency and in the vicinity of the user's aircraft
106     // This may need to be done independently of ATC eg CTAF
107     // Make radio transmission - this simply sends the transmission for physical rendering if the users
108     // aircraft is on the same frequency and in range.  It is up to the derived classes to let ATC know
109     // what is going on.
110         string pending_transmission;    // derived classes set this string before calling Transmit(...)
111         FGATC* tuned_station;                   // and this if they are tuned to ATC
112         
113         // Transmit a message when channel becomes free of other dialog
114     void Transmit(int callback_code = 0);
115         
116         // Transmit a message if channel becomes free within timeout (seconds). timeout of zero implies no limit
117         void ConditionalTransmit(double timeout, int callback_code = 0);
118         
119         // Transmit regardless of other dialog on the channel eg emergency
120         void ImmediateTransmit(int callback_code = 0);
121         
122         inline void SetTrack(double t) { _tgtTrack = t; _trackSet = true; }
123         inline void ClearTrack() { _trackSet = false; }
124
125     inline void Bank(double r) { _tgtRoll = r; }
126     inline void LevelWings(void) { _tgtRoll = 0.0; }
127         
128         virtual void ProcessCallback(int code);
129         
130         PatternLeg leg;
131         
132 private:
133         bool _pending;
134         double _timeout;
135         int _callback_code;     // A callback code to be notified and processed by the derived classes
136                                                 // A value of zero indicates no callback required
137         bool _transmit;         // we are to transmit
138         bool _transmitting;     // we are transmitting
139         double _counter;
140         double _max_count;
141         
142         // Render a transmission (in string pending_transmission)
143         // Outputs the transmission either on screen or as audio depending on user preference
144         // The refname is a string to identify this sample to the sound manager
145         // The repeating flag indicates whether the message should be repeated continuously or played once.
146         void Render(string refname, bool repeating);
147
148         // Cease rendering a transmission.
149         // Requires the sound manager refname if audio, else "".
150         void NoRender(string refname);
151         
152         // Rendering related stuff
153         bool voice;                     // Flag - true if we are using voice
154         bool playing;           // Indicates a message in progress      
155         bool voiceOK;           // Flag - true if at least one voice has loaded OK
156         FGATCVoice* vPtr;
157         
158         // Navigation
159         double _tgtTrack;       // Track to be following if _trackSet is true
160         bool _trackSet;         // Set true if tgtTrack is to be followed
161         double _tgtRoll;
162         bool _rollSuspended;    // Set true when a derived class has suspended AIPlane's roll control
163 };
164
165 #endif  // _FG_AI_PLANE_HXX
166