2006-01-09 14:39:33 +00:00
|
|
|
#############################################################################
|
|
|
|
#
|
|
|
|
# Simple sequenced ATC background chatter function
|
|
|
|
#
|
|
|
|
# Written by Curtis Olson
|
|
|
|
# Started 8 Jan 2006.
|
|
|
|
#
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
#############################################################################
|
|
|
|
# Global shared variables
|
|
|
|
#############################################################################
|
|
|
|
|
2011-04-02 09:48:39 +00:00
|
|
|
var fg_root = nil;
|
|
|
|
var chatter = "UK";
|
|
|
|
var chatter_dir = "";
|
2006-01-09 14:39:33 +00:00
|
|
|
|
2011-04-02 09:48:39 +00:00
|
|
|
var chatter_min_interval = 20.0;
|
|
|
|
var chatter_max_interval = 40.0;
|
|
|
|
var next_interval = nil;
|
2006-01-09 19:11:04 +00:00
|
|
|
|
2011-04-02 09:48:39 +00:00
|
|
|
var chatter_index = 0;
|
|
|
|
var chatter_size = 0;
|
|
|
|
var chatter_list = 0;
|
2006-01-09 14:39:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
#############################################################################
|
2011-04-02 09:48:39 +00:00
|
|
|
# Chatter is initialized only when actually enabled. See listener connected
|
|
|
|
# to /sim/sound/chatter/enabled.
|
2006-01-09 14:39:33 +00:00
|
|
|
#############################################################################
|
|
|
|
|
2011-04-02 09:48:39 +00:00
|
|
|
var chatter_init = func {
|
2006-01-09 14:39:33 +00:00
|
|
|
# default values
|
|
|
|
fg_root = getprop("/sim/fg-root");
|
|
|
|
chatter_dir = sprintf("%s/ATC/Chatter/%s", fg_root, chatter);
|
|
|
|
chatter_list = directory( chatter_dir );
|
|
|
|
chatter_size = size(chatter_list);
|
2006-01-09 15:18:16 +00:00
|
|
|
# seed the random number generator (with time) so we don't start in
|
|
|
|
# same place in the sequence each run.
|
|
|
|
srand();
|
2006-01-09 14:39:33 +00:00
|
|
|
chatter_index = int( chatter_size * rand() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#############################################################################
|
|
|
|
# main update function to be called each frame
|
|
|
|
#############################################################################
|
|
|
|
|
2011-04-02 09:48:39 +00:00
|
|
|
var chatter_update = func {
|
2006-01-09 14:39:33 +00:00
|
|
|
if ( chatter_index >= chatter_size ) {
|
2006-01-09 15:18:16 +00:00
|
|
|
chatter_index = 0;
|
2006-01-09 14:39:33 +00:00
|
|
|
}
|
|
|
|
|
2006-01-10 02:57:32 +00:00
|
|
|
if ( substr(chatter_list[chatter_index],
|
|
|
|
size(chatter_list[chatter_index]) - 4) == ".wav" )
|
2007-04-19 04:42:20 +00:00
|
|
|
{
|
2009-11-30 12:02:55 +00:00
|
|
|
var vol =getprop("/sim/sound/chatter/volume");
|
2007-04-19 04:42:20 +00:00
|
|
|
if(vol == nil){vol = 0.5;}
|
|
|
|
tmpl = { path : chatter_dir, file : chatter_list[chatter_index] , volume : vol};
|
2009-11-30 12:02:55 +00:00
|
|
|
if ( getprop("/sim/sound/chatter/enabled") ) {
|
2006-01-09 15:18:16 +00:00
|
|
|
# go through the motions, but only schedule the message to play
|
|
|
|
# if atc-chatter is enabled.
|
2006-02-17 22:20:15 +00:00
|
|
|
printlog("info", "update atc chatter ", chatter_list[chatter_index] );
|
2007-05-15 14:40:58 +00:00
|
|
|
fgcommand("play-audio-sample", props.Node.new(tmpl) );
|
2006-01-09 15:18:16 +00:00
|
|
|
}
|
2006-01-10 02:57:32 +00:00
|
|
|
} else {
|
2006-01-14 17:30:55 +00:00
|
|
|
# skip non-wav file found in directory
|
2006-01-09 14:39:33 +00:00
|
|
|
}
|
|
|
|
|
2006-01-09 15:18:16 +00:00
|
|
|
chatter_index = chatter_index + 1;
|
2006-01-09 14:39:33 +00:00
|
|
|
nextChatter();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#############################################################################
|
2011-04-02 09:48:39 +00:00
|
|
|
# Use the nasal timer to update every 10 seconds
|
2006-01-09 14:39:33 +00:00
|
|
|
#############################################################################
|
|
|
|
|
2011-04-02 09:48:39 +00:00
|
|
|
var nextChatter = func {
|
|
|
|
if (!getprop("/sim/sound/chatter/enabled"))
|
|
|
|
{
|
|
|
|
next_interval = nil;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-01-09 19:11:04 +00:00
|
|
|
# schedule next message in next min-max interval seconds so we have a bit
|
2006-01-09 14:39:33 +00:00
|
|
|
# of a random pacing
|
2006-01-09 19:11:04 +00:00
|
|
|
next_interval = chatter_min_interval
|
|
|
|
+ int(rand() * (chatter_max_interval - chatter_min_interval));
|
2011-04-02 09:48:39 +00:00
|
|
|
|
2006-02-17 22:20:15 +00:00
|
|
|
# printlog("info", "next chatter in ", next_interval, " seconds");
|
2011-04-02 09:48:39 +00:00
|
|
|
|
2006-01-09 19:11:04 +00:00
|
|
|
settimer(chatter_update, next_interval );
|
2006-01-09 14:39:33 +00:00
|
|
|
}
|
2011-04-02 09:48:39 +00:00
|
|
|
|
|
|
|
#############################################################################
|
|
|
|
# Start chatter processing. Also connected to chatter/enabled property as a
|
|
|
|
# listener.
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
var startChatter = func {
|
|
|
|
if ( getprop("/sim/sound/chatter/enabled") ) {
|
|
|
|
if (fg_root == nil)
|
|
|
|
chatter_init();
|
|
|
|
if (next_interval == nil)
|
|
|
|
nextChatter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# connect listener
|
2011-04-03 16:19:03 +00:00
|
|
|
_setlistener("/sim/sound/chatter/enabled", startChatter);
|
2011-04-02 09:48:39 +00:00
|
|
|
|
|
|
|
# start chatter immediately, if enable is already set.
|
|
|
|
settimer(startChatter, 0);
|
|
|
|
|