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}
27 my ($addr, $map, $attackerweapon, $targweapon, $value) = split /\t/, $_;
28 $targweapon = int $self->weaponid_from_name($targweapon)
29 if $targweapon ne int $targweapon;
30 $attackerweapon = int $self->weaponid_from_name($attackerweapon)
31 if $attackerweapon ne int $attackerweapon;
32 $self->{stats}->{$addr}{$map}{$attackerweapon}{$targweapon} += $value;
33 $self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $value;
34 $self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $value;
35 $self->{allstats}->{$attackerweapon}{$targweapon} += $value;
42 open my $fh, ">", $self->{fn}
44 while(my ($addr, $addrhash) = each %{$self->{stats}})
46 while(my ($map, $maphash) = each %$addrhash)
48 while(my ($attackerweapon, $attackerweaponhash) = each %$maphash)
50 while(my ($targweapon, $value) = each %$attackerweaponhash)
52 print $fh "$addr\t$map\t$attackerweapon\t$targweapon\t$value\n";
61 my ($self, $addr, $map, $attackerweapon, $targweapon, $type) = @_;
65 $self->{stats}->{$addr}{$map}{$attackerweapon}{$targweapon} += $type;
66 $self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $type;
67 $self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $type;
68 $self->{allstats}->{$attackerweapon}{$targweapon} += $type;
74 my ($self, $callback) = @_;
76 $callback->(undef, undef, $self->{allstats});
78 while(my ($k, $v) = each %{$self->{addrstats}})
80 $callback->($k, undef, $v);
83 while(my ($k, $v) = each %{$self->{mapstats}})
85 $callback->(undef, $k, $v);
88 while(my ($k1, $v1) = each %{$self->{stats}})
90 while(my ($k2, $v2) = each %$v1)
92 $callback->($k1, $k2, $v2);
98 1 => ["Laser", "laser"],
99 2 => ["Shotgun", "shotgun"],
101 4 => ["Mortar", "gl"],
102 5 => ["Electro", "electro"],
103 6 => ["Crylink", "crylink"],
105 8 => ["Hagar", "hagar"],
106 9 => ["Rocket Launcher", "rl"],
107 10 => ["Port-O-Launch", "porto"],
108 11 => ["MinstaNex", "minstanex"],
109 12 => ["Grappling Hook", "hookgun"],
110 13 => ["Heavy Laser Assault Cannon", "hlac"],
111 14 => ["T.A.G. Seeker", "seeker"],
112 15 => ["Camping Rifle", "campingrifle"],
115 sub weaponid_valid($$)
117 my ($self, $id) = @_;
118 return exists $WeaponMap{$id};
121 sub weaponid_to_name($$)
123 my ($self, $id) = @_;
124 exists $WeaponMap{$id} or warn "weapon of id $id not found\n";
125 return $WeaponMap{$id}[0];
128 sub weaponid_to_model($$)
130 my ($self, $id) = @_;
131 exists $WeaponMap{$id} or warn "weapon of id $id not found\n";
132 return $WeaponMap{$id}[1];
135 sub weaponid_from_name($$)
137 my ($self, $name) = @_;
141 if $WeaponMap{$_}[0] eq $name;