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(/^(\S+)\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(/^(\S+)\t(\S+)\t(\d+)\t(\d+)\t(\S+)$/)
44 # legacy format (Nexuiz)
45 ($addr, $map, $attackerweapon, $targweapon, $value) = ($1, $2, $3, $4, $5);
51 $targweapon = int $self->weaponid_from_name($targweapon)
52 if $targweapon ne int $targweapon;
53 $attackerweapon = int $self->weaponid_from_name($attackerweapon)
54 if $attackerweapon ne int $attackerweapon;
55 $self->{stats}->{$addr}{$map}{$attackerweapon}{$targweapon} += $value;
56 $self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $value;
57 $self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $value;
58 $self->{allstats}->{$attackerweapon}{$targweapon} += $value;
65 open my $fh, ">", $self->{fn}
67 while(my ($addr, $addrhash) = each %{$self->{stats}})
69 while(my ($map, $maphash) = each %$addrhash)
71 while(my ($attackerweapon, $attackerweaponhash) = each %$maphash)
73 while(my ($targweapon, $value) = each %$attackerweaponhash)
75 print $fh "$addr\t$map\t$attackerweapon\t$targweapon\t$value\n";
84 my ($self, $addr, $map, $attackerweapon, $targweapon, $type) = @_;
88 $self->{stats}->{$addr}{$map}{$attackerweapon}{$targweapon} += $type;
89 $self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $type;
90 $self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $type;
91 $self->{allstats}->{$attackerweapon}{$targweapon} += $type;
97 my ($self, $callback) = @_;
99 $callback->(undef, undef, $self->{allstats});
100 # send per-host stats
101 while(my ($k, $v) = each %{$self->{addrstats}})
103 $callback->($k, undef, $v);
106 while(my ($k, $v) = each %{$self->{mapstats}})
108 $callback->(undef, $k, $v);
111 while(my ($k1, $v1) = each %{$self->{stats}})
113 while(my ($k2, $v2) = each %$v1)
115 $callback->($k1, $k2, $v2);
121 1 => ["Laser", "laser"],
122 2 => ["Shotgun", "shotgun"],
124 4 => ["Mortar", "gl"],
125 5 => ["Mine Layer", "minelayer"],
126 6 => ["Electro", "electro"],
127 7 => ["Crylink", "crylink"],
129 9 => ["Hagar", "hagar"],
130 10 => ["Rocket Launcher", "rl"],
131 11 => ["Port-O-Launch", "porto"],
132 12 => ["MinstaNex", "minstanex"],
133 13 => ["Grappling Hook", "hookgun"],
134 14 => ["Heavy Laser Assault Cannon", "hlac"],
135 15 => ["Tuba", "tuba"],
136 16 => ["Camping Rifle", "campingrifle"],
137 17 => ["Fireball", "fireball"],
138 18 => ["Seeker", "seeker"],
141 sub weaponid_valid($$)
143 my ($self, $id) = @_;
144 return exists $WeaponMap{$id};
147 sub weaponid_to_name($$)
149 my ($self, $id) = @_;
150 exists $WeaponMap{$id} or warn "weapon of id $id not found\n";
151 return $WeaponMap{$id}[0];
154 sub weaponid_to_model($$)
156 my ($self, $id) = @_;
157 exists $WeaponMap{$id} or warn "weapon of id $id not found\n";
158 return $WeaponMap{$id}[1];
161 sub weaponid_from_name($$)
163 my ($self, $name) = @_;
167 if $WeaponMap{$_}[0] eq $name;