]> git.rm.cloudns.org Git - xonotic/xonotic.git/commitdiff
bot orchestra: try keeping voices on the channel if possible
authorRudolf Polzer <divverent@alientrap.org>
Tue, 27 Sep 2011 08:03:23 +0000 (10:03 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Tue, 27 Sep 2011 08:04:05 +0000 (10:04 +0200)
misc/tools/midi2cfg-ng.conf
misc/tools/midi2cfg-ng.pl

index 4d9cc6f6c4fe019fdc57433369a13eb94ff556c8..a96cf06e3a5b906a4ba99f688a69b6dcfa3d61af 100644 (file)
@@ -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"
index d8db264ec1ff5fdac8768a2eee3e7bf54046b194..ecebb475fef7358967e0d17129f6cc5c98170d97 100755 (executable)
@@ -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)