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