]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/AIPlane.cxx
Alex Romosan:
[flightgear.git] / src / ATC / AIPlane.cxx
index 867bdcd054fceaed7f5b22a629199538eb7d654f..8d501910d971d905a30e29922ce9ae69ff40d463 100644 (file)
@@ -22,7 +22,7 @@
 #include <Main/fg_props.hxx>
 #include <simgear/math/point3d.hxx>
 #include <simgear/debug/logstream.hxx>
-#include <simgear/sound/soundmgr.hxx>
+#include <simgear/sound/soundmgr_openal.hxx>
 #include <math.h>
 #include <string>
 SG_USING_STD(string);
@@ -70,6 +70,10 @@ void FGAIPlane::Update(double dt) {
                                                _timeout = 0.0;
                                                _pending = false;
                                                // timed out - don't render.
+                                               if(_callback_code == 99) {
+                                                       // MEGA-HACK - 99 is the remove self callback - currently this *does* need to be run even if the transmission isn't made.
+                                                       ProcessCallback(_callback_code);
+                                               }
                                        }
                                }
                        }
@@ -86,13 +90,18 @@ void FGAIPlane::Update(double dt) {
        // TODO - turn it off if user switches to another freq - keep track of where in message we are etc.
        if(_transmit) {
                //cout << "transmit\n";
-               double user_freq0 = fgGetDouble("/radios/comm[0]/frequencies/selected-mhz");
-               double user_freq1 = fgGetDouble("/radios/comm[1]/frequencies/selected-mhz");
+               double user_freq0 = fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz");
+               double user_freq1 = fgGetDouble("/instrumentation/comm[1]/frequencies/selected-mhz");
                _counter = 0.0;
                _max_count = 5.0;               // FIXME - hardwired length of message - need to calculate it!
                
                //cout << "Transmission = " << pending_transmission << '\n';
-               if(freq == user_freq0 || freq == user_freq1) {
+
+               // The radios dialog seems to set slightly imprecise freqs, eg 118.099998
+               // The eplison stuff below is a work-around
+               double eps0 = fabs(freq - user_freq0);
+               double eps1 = fabs(freq - user_freq1);
+               if(eps0 < 0.002 || eps1 < 0.002) {
                        //cout << "Transmitting..." << endl;
                        // we are on the same frequency, so check distance to the user plane
                        if(1) {
@@ -102,7 +111,6 @@ void FGAIPlane::Update(double dt) {
                        }
                }
                // Run the callback regardless of whether on same freq as user or not.
-               //cout << "_callback_code = " << _callback_code << '\n';
                if(_callback_code) {
                        ProcessCallback(_callback_code);
                }
@@ -114,6 +122,7 @@ void FGAIPlane::Update(double dt) {
                        _transmitting = false;
                        // For now we'll let ATC decide whether to respond
                        //if(tuned_station) tuned_station->SetResponseReqd(plane.callsign);
+                       //if(tuned_station->get_ident() == "KRHV") cout << "Notifying transmission finished" << endl;
                        if(tuned_station) tuned_station->NotifyTransmissionFinished(plane.callsign);
                }
                _counter += dt;
@@ -172,18 +181,17 @@ void FGAIPlane::ProcessCallback(int code) {
 // Outputs the transmission either on screen or as audio depending on user preference
 // The refname is a string to identify this sample to the sound manager
 // The repeating flag indicates whether the message should be repeated continuously or played once.
-void FGAIPlane::Render(string refname, bool repeating) {
+void FGAIPlane::Render(const string& refname, bool repeating) {
 #ifdef ENABLE_AUDIO_SUPPORT
-       voice = (voiceOK && fgGetBool("/sim/sound/audible")
-                 && fgGetBool("/sim/sound/voice"));
+       voice = (voiceOK && fgGetBool("/sim/sound/voice"));
        if(voice) {
                int len;
                unsigned char* buf = vPtr->WriteMessage((char*)pending_transmission.c_str(), len, voice);
                if(voice) {
-                       SGSimpleSound* simple = new SGSimpleSound(buf, len);
+                       SGSoundSample* simple = new SGSoundSample(buf, len, 8000, false);
                        // TODO - at the moment the volume is always set off comm1 
                        // and can't be changed after the transmission has started.
-                       simple->set_volume(5.0 * fgGetDouble("/radios/comm[0]/volume"));
+                       simple->set_volume(5.0 * fgGetDouble("/instrumentation/comm[0]/volume"));
                        globals->get_soundmgr()->add(simple, refname);
                        if(repeating) {
                                globals->get_soundmgr()->play_looped(refname);
@@ -208,7 +216,7 @@ void FGAIPlane::Render(string refname, bool repeating) {
 
 
 // Cease rendering a transmission.
-void FGAIPlane::NoRender(string refname) {
+void FGAIPlane::NoRender(const string& refname) {
        if(playing) {
                if(voice) {
 #ifdef ENABLE_AUDIO_SUPPORT