On Mon, Oct 6, 2008 at 6:52 PM, Stuart Buchanan
<[EMAIL PROTECTED]> wrote:
>
> When I originally wrote the MP chat, I had quite a lot of difficulty doing 
> the frequency matching between the sender and receiver, possibly because I 
> was doing a float comparison, or because the property is transfered as a 
> float, or because the radio frequency was a float.
>
> I'm sure it would be pretty easy to sort out, but I never returned to it. If 
> anyone wants to take a look, they are more than welcome.

Here is a first whack at the problem. Listens on all comm radios,
transmits on first one. Incoming messages without frequency or zero
frequency will always be received. Note, fg has comm1 set to 118.5MHz
by default.

I have the following additional ideas:
* separate property to disable frequency matching (receive-all, this
is done by selecting 0 freq in the patch)
* property to select active radio for transmission (maybe be per-radio flag?)
* startup warning message telling pilot to tune to an appropriate frequency
* comm1 automatically tuned to nearest tower, comm2 to guard on startup
* separate receive and transmit "serviceable" flags

Comments welcome.

-- 
Csaba/Jester
Index: multiplayer.nas
===================================================================
RCS file: /var/cvs/FlightGear-0.9/data/Nasal/multiplayer.nas,v
retrieving revision 1.9
diff -u -r1.9 multiplayer.nas
--- multiplayer.nas	2 Oct 2008 20:12:00 -0000	1.9
+++ multiplayer.nas	6 Oct 2008 22:47:56 -0000
@@ -10,6 +10,29 @@
 
 var messages = {};
 
+# check if any comm radio is tuned to freq (in Hz)
+var check_freq = func(freq)
+{
+  freq = num(freq);
+  if (freq == nil or freq == 0) return 1;
+  freq = freq / 1000000;
+  var comm_nodes = props.globals.getNode("/instrumentation").getChildren("comm");
+  foreach (var comm_node; comm_nodes)
+  {
+    var serviceable_node = comm_node.getNode("serviceable");
+    if (serviceable_node != nil and serviceable_node.getBoolValue())
+    {
+      var selected_freq_node = comm_node.getNode("frequencies/selected-mhz");
+      var selected_freq = selected_freq_node == nil ? nil : selected_freq_node.getValue();
+      if (selected_freq != nil and (math.abs(selected_freq - freq) < 0.000001 or selected_freq == 0))
+      {
+        return 1;
+      }
+    }
+  }
+  return 0;
+}
+
 var check_messages = func
 {
 
@@ -41,8 +64,12 @@
           # Save the message so we don't repeat it.
           messages[lcallsign] = lmsg;
 
-          # Display the message.
-          echo_message(lmsg, lcallsign);
+          var lfreq = getprop(i.getPath() ~ "/sim/multiplay/transmission-freq-hz");
+          if (check_freq(lfreq))
+          {
+            # Display the message.
+            echo_message(lmsg, lcallsign);
+          }
         }
       }
     }
@@ -87,15 +114,23 @@
   }
 }
 
-settimer(func {
-  # Call-back to ensure we see our own messages.
-  setlistener("/sim/multiplay/chat", func(n) {
-    echo_message(n.getValue(), getprop("/sim/multiplay/callsign"));
-  });
+var update_transmission_freq = func(n)
+{
+  setprop("/sim/multiplay/transmission-freq-hz", n.getValue() * 1000000);
+}
 
-  # check for new messages
-  check_messages();
-}, 1);
+_setlistener("/sim/signals/nasal-dir-initialized", func {
+  settimer(func {
+    # Call-back to ensure we see our own messages.
+    setlistener("/sim/multiplay/chat", func(n) {
+      echo_message(n.getValue(), getprop("/sim/multiplay/callsign"));
+    });
+
+    # check for new messages
+    check_messages();
+  }, 1);
+  setlistener("/instrumentation/comm/frequencies/selected-mhz", update_transmission_freq, 1);
+});
 
 # Message composition function, activated using the - key.
 var prefix = "Chat Message:";
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to