From: Rudolf Polzer Date: Tue, 27 Sep 2011 08:03:23 +0000 (+0200) Subject: bot orchestra: try keeping voices on the channel if possible X-Git-Tag: xonotic-v0.6.0~78 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=1a5b8ef7f7191eaa5e590592177d3f9c95728d92;p=xonotic%2Fxonotic.git bot orchestra: try keeping voices on the channel if possible --- diff --git a/misc/tools/midi2cfg-ng.conf b/misc/tools/midi2cfg-ng.conf index 4d9cc6f6..a96cf06e 100644 --- a/misc/tools/midi2cfg-ng.conf +++ b/misc/tools/midi2cfg-ng.conf @@ -4,6 +4,7 @@ timeoffset_predone 2 timeoffset_postdone 2 timeoffset_preintermission 2 timeoffset_postintermission 2 +time_forgetfulness 1.5 raw set places_tuba "tUba1 tUba2 tUba3 tUba4 tUba5 tUba6 tUba7 tUba8 tUba9 tUba10 tUba11 tUba12 tUba13 tUba14 tUba15 tUba16 tUba17 tUba18 tUba19 tUba20 tUba21 tUba22 tUba23 tUba24 tUba25 tUba26 tUba27 tUba28 tUba29 tUba30 tUba31 tUba32" raw set places_percussion "tChr1 tChr2 tChr3 tChr4 tChr5 tChr6 tChr7 tChr8 tChr9 tChr10 tChr11 tChr12 tChr13 tChr14 tChr15 tChr16 tChr17 tChr18 tChr19 tChr20 tChr21 tChr22 tChr23 tChr24 tChr25 tChr26 tChr27 tChr38 tChr39 tChr30 tChr31 tChr32" diff --git a/misc/tools/midi2cfg-ng.pl b/misc/tools/midi2cfg-ng.pl index d8db264e..ecebb475 100755 --- a/misc/tools/midi2cfg-ng.pl +++ b/misc/tools/midi2cfg-ng.pl @@ -24,6 +24,7 @@ my $timeoffset_predone = 2; my $timeoffset_postdone = 2; my $timeoffset_preintermission = 2; my $timeoffset_postintermission = 2; +my $time_forgetfulness = 1.5; my ($config, @midilist) = @ARGV; @@ -202,6 +203,10 @@ sub botconfig_read($) { $timeoffset_postintermission = $1; } + elsif(/^time_forgetfulness (.*)/) + { + $time_forgetfulness = $1; + } else { print "unknown command: $_\n"; @@ -297,8 +302,6 @@ sub busybot_cmd_bot_execute($$@) { my ($bot, $time, @commands) = @_; - $bot->{lastuse} = $time; - for(@commands) { if($_->[0] eq 'time') @@ -342,7 +345,8 @@ sub busybot_cmd_bot_execute($$@) elsif($_->[0] eq 'barrier') { $commands .= sprintf "sv_cmd bot_cmd %d barrier\n", $bot->{id}; - $bot->{lastuse} = $bot->{timer} = $bot->{busytimer} = 0; + $bot->{timer} = $bot->{busytimer} = 0; + undef $bot->{lastuse}; } elsif($_->[0] eq 'raw') { @@ -468,6 +472,12 @@ sub busybot_note_on_bot($$$$$$$) $bot->{busy} = [$channel, $note, $cmds_off]; } ++$bot->{seen}{$k0}{$k1}; + + $bot->{lastuse} = $time; + $bot->{lastchannel} = $channel; + $bot->{lastprogram} = $program; + $bot->{lastnote} = $note; + return 1; } @@ -501,6 +511,45 @@ sub busybot_note_off($$$) return 0; } +sub botsort($$$$@) +{ + my ($time, $channel, $program, $note, @bots) = @_; + return + map + { + $_->[0] + } + sort + { + $a->[1] <=> $b->[1] + or + ($a->[0]->{lastuse} // -666) <=> ($b->[0]->{lastuse} // -666) + or + $a->[2] <=> $b->[2] + } + map + { + my $q = 0; + if($_->{lastuse} >= $time - $time_forgetfulness) + { + if($channel == $_->{lastchannel}) + { + ++$q; + if($program == $_->{lastprogram}) + { + ++$q; + if($note == $_->{lastnote}) + { + ++$q; + } + } + } + } + [$_, $q, rand] + } + @bots; +} + sub busybot_note_on($$$$) { my ($time, $channel, $program, $note) = @_; @@ -516,7 +565,7 @@ sub busybot_note_on($$$$) my @epicfailbots = (); - for(map { $_->[1] } sort { $a->[1]->{lastuse} <=> $b->[1]->{lastuse} or $a->[0] <=> $b->[0] } map { [rand, $_] } @busybots_allocated) + for(botsort $time, $channel, $program, $note, @busybots_allocated) { my $canplay = busybot_note_on_bot $_, $time, $channel, $program, $note, 0, 0; if($canplay > 0)