]> git.xonotic.org Git - xonotic/xonotic.git/blobdiff - misc/tools/WeaponEncounterProfile.pm
Fix macOS SDL2 framework permissions
[xonotic/xonotic.git] / misc / tools / WeaponEncounterProfile.pm
index 68acfb23bcc5e8b1699c5a81a8ccec2e3064825a..c0cf91451ede0d1fd123c7c59b492e6716de60ac 100644 (file)
@@ -17,6 +17,7 @@ sub load($)
        my ($self) = @_;
        $self->{stats} = {};
        $self->{mapstats} = {};
+       $self->{typestats} = {};
        $self->{addrstats} = {};
        $self->{allstats} = {};
        open my $fh, "<", $self->{fn}
@@ -27,12 +28,38 @@ sub load($)
                /^$/ and next;
                /^#/ and next;
                /^\/\// and next;
-               my ($addr, $map, $attackerweapon, $targweapon, $value) = split /\t/, $_;
+               my ($addr, $map, $attackerweapon, $targweapon, $value);
+               if(/^([^\t]+)\t(\S+)\t(\d+) (\d+)\t(\d+) (\d+)\t(\d+) (\d+) (\S+)$/)
+               {
+                       # new format (Xonotic)
+                       ($addr, $map, $attackerweapon, $targweapon) = ($1, $2, $3, $5);
+                       next if $4 and not $ENV{WEAPONPROFILER_WITHBOTS};
+                       next if $6 and not $ENV{WEAPONPROFILER_WITHBOTS};
+                       $value =
+                               $ENV{WEAPONPROFILER_DAMAGE} ? $9 :
+                               $ENV{WEAPONPROFILER_HITS} ? $8 :
+                               $7;
+               }
+               elsif(/^([^\t]+)\t(\S+)\t(\d+)\t(\d+)\t(\S+)$/)
+               {
+                       # legacy format (Nexuiz)
+                       ($addr, $map, $attackerweapon, $targweapon, $value) = ($1, $2, $3, $4, $5);
+               }
+               else
+               {
+                       print STDERR "UNRECOGNIZED: $_\n";
+                       next;
+               }
                $targweapon = int $self->weaponid_from_name($targweapon)
                        if $targweapon ne int $targweapon;
                $attackerweapon = int $self->weaponid_from_name($attackerweapon)
                        if $attackerweapon ne int $attackerweapon;
-               $self->{stats}->{$addr}{$map}{$attackerweapon}{$targweapon} += $value;
+               $map =~ /(.*?)_(.*)/
+                       or do { warn "invalid map name: $map"; next; };
+               (my $type, $map) = ($1, $2);
+               $self->{stats}->{$addr}{$type}{$map}{$attackerweapon}{$targweapon} += $value;
+               $self->{typestats}->{$type}{$attackerweapon}{$targweapon} += $value;
+               $self->{typemapstats}->{$type}{$map}{$attackerweapon}{$targweapon} += $value;
                $self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $value;
                $self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $value;
                $self->{allstats}->{$attackerweapon}{$targweapon} += $value;
@@ -61,14 +88,19 @@ sub save($)
 
 sub event($$$$$$)
 {
-       my ($self, $addr, $map, $attackerweapon, $targweapon, $type) = @_;
+       my ($self, $addr, $map, $attackerweapon, $targweapon, $value) = @_;
        return if $map eq '';
-       if($type > 0)
+       if($value > 0)
        {
-               $self->{stats}->{$addr}{$map}{$attackerweapon}{$targweapon} += $type;
-               $self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $type;
-               $self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $type;
-               $self->{allstats}->{$attackerweapon}{$targweapon} += $type;
+               $map =~ /(.*?)_(.*)/
+                       or do { warn "invalid map name: $map"; return; };
+               (my $type, $map) = ($1, $2);
+               $self->{stats}->{$addr}{$type}{$map}{$attackerweapon}{$targweapon} += $value;
+               $self->{typemapstats}->{$type}{$map}{$attackerweapon}{$targweapon} += $value;
+               $self->{typestats}->{$type}{$attackerweapon}{$targweapon} += $value;
+               $self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $value;
+               $self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $value;
+               $self->{allstats}->{$attackerweapon}{$targweapon} += $value;
        }
 }
 
@@ -76,23 +108,39 @@ sub allstats($$)
 {
        my ($self, $callback) = @_;
        # send global stats
-       $callback->(undef, undef, $self->{allstats});
+       $callback->(undef, undef, undef, $self->{allstats});
        # send per-host stats
        while(my ($k, $v) = each %{$self->{addrstats}})
        {
-               $callback->($k, undef, $v);
+               $callback->($k, undef, undef, $v);
+       }
+       # send per-type stats
+       while(my ($k, $v) = each %{$self->{typestats}})
+       {
+               $callback->(undef, $k, undef, $v);
+       }
+       # send per-type-map stats
+       while(my ($k1, $v1) = each %{$self->{typemapstats}})
+       {
+               while(my ($k2, $v2) = each %$v1)
+               {
+                       $callback->(undef, $k1, $k2, $v2);
+               }
        }
        # send per-map stats
        while(my ($k, $v) = each %{$self->{mapstats}})
        {
-               $callback->(undef, $k, $v);
+               $callback->(undef, undef, $k, $v);
        }
        # send single stats
        while(my ($k1, $v1) = each %{$self->{stats}})
        {
                while(my ($k2, $v2) = each %$v1)
                {
-                       $callback->($k1, $k2, $v2);
+                       while(my ($k3, $v3) = each %$v2)
+                       {
+                               $callback->($k1, $k2, $k3, $v3);
+                       }
                }
        }
 }
@@ -101,20 +149,21 @@ our %WeaponMap = (
          1 => ["Laser", "laser"],
          2 => ["Shotgun", "shotgun"],
          3 => ["Uzi", "uzi"],
-         4 => ["Mortar", "gl"],
-         5 => ["Electro", "electro"],
-         6 => ["Crylink", "crylink"],
-         7 => ["Nex", "nex"],
-         8 => ["Hagar", "hagar"],
-         9 => ["Rocket Launcher", "rl"],
-        10 => ["Port-O-Launch", "porto"],
-        11 => ["MinstaNex", "minstanex"],
-        12 => ["Grappling Hook", "hookgun"],
-        13 => ["Heavy Laser Assault Cannon", "hlac"],
-        14 => ["Tuba", "tuba"],
-        15 => ["Camping Rifle", "campingrifle"],
-        16 => ["Fireball", "fireball"],
-        17 => ["Seeker", "seeker"],
+         4 => ["Mortar", "grenadelauncher"],
+         5 => ["Mine Layer", "minelayer"],
+         6 => ["Electro", "electro"],
+         7 => ["Crylink", "crylink"],
+         8 => ["Nex", "nex"],
+         9 => ["Hagar", "hagar"],
+        10 => ["Rocket Launcher", "rocketlauncher"],
+        11 => ["Port-O-Launch", "porto"],
+        12 => ["MinstaNex", "minstanex"],
+        13 => ["Grappling Hook", "hook"],
+        14 => ["Heavy Laser Assault Cannon", "hlac"],
+        15 => ["@!#%'n Tuba", "tuba"],
+        16 => ["Sniper Rifle", "rifle"],
+        17 => ["Fireball", "fireball"],
+        18 => ["Seeker", "seeker"],
 );
 
 sub weaponid_valid($$)