X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fxonotic.git;a=blobdiff_plain;f=misc%2Ftools%2FWeaponEncounterProfile.pm;h=c0cf91451ede0d1fd123c7c59b492e6716de60ac;hp=52766ea13e01cc84e05f6c63cccf1647c2138b83;hb=1a0ff870ff6b234747a81dd669d18d463e802cb9;hpb=e5832bf2ecac60a672a29c85cd8dec341a215e1c diff --git a/misc/tools/WeaponEncounterProfile.pm b/misc/tools/WeaponEncounterProfile.pm index 52766ea1..c0cf9145 100644 --- a/misc/tools/WeaponEncounterProfile.pm +++ b/misc/tools/WeaponEncounterProfile.pm @@ -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,19 +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"], + 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($$)