3 package WeaponEncounterProfile;
9 my ($cls, $filename) = @_;
10 my $self = bless { fn => $filename }, 'WeaponEncounterProfile';
19 $self->{mapstats} = {};
20 $self->{addrstats} = {};
21 $self->{allstats} = {};
22 open my $fh, "<", $self->{fn}
30 my ($addr, $map, $attackerweapon, $targweapon, $value);
31 if(/^([^\t]+)\t(\S+)\t(\d+) (\d+)\t(\d+) (\d+)\t(\d+) (\d+) (\S+)$/)
33 # new format (Xonotic)
34 ($addr, $map, $attackerweapon, $targweapon) = ($1, $2, $3, $5);
35 next if $4 and not $ENV{WEAPONPROFILER_WITHBOTS};
36 next if $6 and not $ENV{WEAPONPROFILER_WITHBOTS};
38 $ENV{WEAPONPROFILER_DAMAGE} ? $9 :
39 $ENV{WEAPONPROFILER_HITS} ? $8 :
42 elsif(/^([^\t]+)\t(\S+)\t(\d+)\t(\d+)\t(\S+)$/)
44 # legacy format (Nexuiz)
45 ($addr, $map, $attackerweapon, $targweapon, $value) = ($1, $2, $3, $4, $5);
49 print STDERR "UNRECOGNIZED: $_\n";
52 $targweapon = int $self->weaponid_from_name($targweapon)
53 if $targweapon ne int $targweapon;
54 $attackerweapon = int $self->weaponid_from_name($attackerweapon)
55 if $attackerweapon ne int $attackerweapon;
56 $self->{stats}->{$addr}{$map}{$attackerweapon}{$targweapon} += $value;
57 $self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $value;
58 $self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $value;
59 $self->{allstats}->{$attackerweapon}{$targweapon} += $value;
66 open my $fh, ">", $self->{fn}
68 while(my ($addr, $addrhash) = each %{$self->{stats}})
70 while(my ($map, $maphash) = each %$addrhash)
72 while(my ($attackerweapon, $attackerweaponhash) = each %$maphash)
74 while(my ($targweapon, $value) = each %$attackerweaponhash)
76 print $fh "$addr\t$map\t$attackerweapon\t$targweapon\t$value\n";
85 my ($self, $addr, $map, $attackerweapon, $targweapon, $type) = @_;
89 $self->{stats}->{$addr}{$map}{$attackerweapon}{$targweapon} += $type;
90 $self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $type;
91 $self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $type;
92 $self->{allstats}->{$attackerweapon}{$targweapon} += $type;
98 my ($self, $callback) = @_;
100 $callback->(undef, undef, $self->{allstats});
101 # send per-host stats
102 while(my ($k, $v) = each %{$self->{addrstats}})
104 $callback->($k, undef, $v);
107 while(my ($k, $v) = each %{$self->{mapstats}})
109 $callback->(undef, $k, $v);
112 while(my ($k1, $v1) = each %{$self->{stats}})
114 while(my ($k2, $v2) = each %$v1)
116 $callback->($k1, $k2, $v2);
122 1 => ["Laser", "laser"],
123 2 => ["Shotgun", "shotgun"],
125 4 => ["Mortar", "gl"],
126 5 => ["Mine Layer", "minelayer"],
127 6 => ["Electro", "electro"],
128 7 => ["Crylink", "crylink"],
130 9 => ["Hagar", "hagar"],
131 10 => ["Rocket Launcher", "rl"],
132 11 => ["Port-O-Launch", "porto"],
133 12 => ["MinstaNex", "minstanex"],
134 13 => ["Grappling Hook", "hookgun"],
135 14 => ["Heavy Laser Assault Cannon", "hlac"],
136 15 => ["@!#%'n Tuba", "tuba"],
137 16 => ["Sniper Rifle", "sniperrifle"],
138 17 => ["Fireball", "fireball"],
139 18 => ["Seeker", "seeker"],
142 sub weaponid_valid($$)
144 my ($self, $id) = @_;
145 return exists $WeaponMap{$id};
148 sub weaponid_to_name($$)
150 my ($self, $id) = @_;
151 exists $WeaponMap{$id} or warn "weapon of id $id not found\n";
152 return $WeaponMap{$id}[0];
155 sub weaponid_to_model($$)
157 my ($self, $id) = @_;
158 exists $WeaponMap{$id} or warn "weapon of id $id not found\n";
159 return $WeaponMap{$id}[1];
162 sub weaponid_from_name($$)
164 my ($self, $name) = @_;
168 if $WeaponMap{$_}[0] eq $name;