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}
28 my ($addr, $map, $attackerweapon, $targweapon, $value) = split /\t/, $_;
29 $targweapon = int $self->weaponid_from_name($targweapon)
30 if $targweapon ne int $targweapon;
31 $attackerweapon = int $self->weaponid_from_name($attackerweapon)
32 if $attackerweapon ne int $attackerweapon;
33 $self->{stats}->{$addr}{$map}{$attackerweapon}{$targweapon} += $value;
34 $self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $value;
35 $self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $value;
36 $self->{allstats}->{$attackerweapon}{$targweapon} += $value;
43 open my $fh, ">", $self->{fn}
45 while(my ($addr, $addrhash) = each %{$self->{stats}})
47 while(my ($map, $maphash) = each %$addrhash)
49 while(my ($attackerweapon, $attackerweaponhash) = each %$maphash)
51 while(my ($targweapon, $value) = each %$attackerweaponhash)
53 print $fh "$addr\t$map\t$attackerweapon\t$targweapon\t$value\n";
62 my ($self, $addr, $map, $attackerweapon, $targweapon, $type) = @_;
66 $self->{stats}->{$addr}{$map}{$attackerweapon}{$targweapon} += $type;
67 $self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $type;
68 $self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $type;
69 $self->{allstats}->{$attackerweapon}{$targweapon} += $type;
75 my ($self, $callback) = @_;
77 $callback->(undef, undef, $self->{allstats});
79 while(my ($k, $v) = each %{$self->{addrstats}})
81 $callback->($k, undef, $v);
84 while(my ($k, $v) = each %{$self->{mapstats}})
86 $callback->(undef, $k, $v);
89 while(my ($k1, $v1) = each %{$self->{stats}})
91 while(my ($k2, $v2) = each %$v1)
93 $callback->($k1, $k2, $v2);
99 1 => ["Laser", "laser"],
100 2 => ["Shotgun", "shotgun"],
102 4 => ["Mortar", "gl"],
103 5 => ["Electro", "electro"],
104 6 => ["Crylink", "crylink"],
106 8 => ["Hagar", "hagar"],
107 9 => ["Rocket Launcher", "rl"],
108 10 => ["Port-O-Launch", "porto"],
109 11 => ["MinstaNex", "minstanex"],
110 12 => ["Grappling Hook", "hookgun"],
111 13 => ["Heavy Laser Assault Cannon", "hlac"],
112 14 => ["Tuba", "tuba"],
113 15 => ["Camping Rifle", "campingrifle"],
114 16 => ["Fireball", "fireball"],
117 sub weaponid_valid($$)
119 my ($self, $id) = @_;
120 return exists $WeaponMap{$id};
123 sub weaponid_to_name($$)
125 my ($self, $id) = @_;
126 exists $WeaponMap{$id} or warn "weapon of id $id not found\n";
127 return $WeaponMap{$id}[0];
130 sub weaponid_to_model($$)
132 my ($self, $id) = @_;
133 exists $WeaponMap{$id} or warn "weapon of id $id not found\n";
134 return $WeaponMap{$id}[1];
137 sub weaponid_from_name($$)
139 my ($self, $name) = @_;
143 if $WeaponMap{$_}[0] eq $name;