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) = split /\t/, $_;
31 $targweapon = int $self->weaponid_from_name($targweapon)
32 if $targweapon ne int $targweapon;
33 $attackerweapon = int $self->weaponid_from_name($attackerweapon)
34 if $attackerweapon ne int $attackerweapon;
35 $self->{stats}->{$addr}{$map}{$attackerweapon}{$targweapon} += $value;
36 $self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $value;
37 $self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $value;
38 $self->{allstats}->{$attackerweapon}{$targweapon} += $value;
45 open my $fh, ">", $self->{fn}
47 while(my ($addr, $addrhash) = each %{$self->{stats}})
49 while(my ($map, $maphash) = each %$addrhash)
51 while(my ($attackerweapon, $attackerweaponhash) = each %$maphash)
53 while(my ($targweapon, $value) = each %$attackerweaponhash)
55 print $fh "$addr\t$map\t$attackerweapon\t$targweapon\t$value\n";
64 my ($self, $addr, $map, $attackerweapon, $targweapon, $type) = @_;
68 $self->{stats}->{$addr}{$map}{$attackerweapon}{$targweapon} += $type;
69 $self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $type;
70 $self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $type;
71 $self->{allstats}->{$attackerweapon}{$targweapon} += $type;
77 my ($self, $callback) = @_;
79 $callback->(undef, undef, $self->{allstats});
81 while(my ($k, $v) = each %{$self->{addrstats}})
83 $callback->($k, undef, $v);
86 while(my ($k, $v) = each %{$self->{mapstats}})
88 $callback->(undef, $k, $v);
91 while(my ($k1, $v1) = each %{$self->{stats}})
93 while(my ($k2, $v2) = each %$v1)
95 $callback->($k1, $k2, $v2);
101 1 => ["Laser", "laser"],
102 2 => ["Shotgun", "shotgun"],
104 4 => ["Mortar", "gl"],
105 5 => ["Electro", "electro"],
106 6 => ["Crylink", "crylink"],
108 8 => ["Hagar", "hagar"],
109 9 => ["Rocket Launcher", "rl"],
110 10 => ["Port-O-Launch", "porto"],
111 11 => ["MinstaNex", "minstanex"],
112 12 => ["Grappling Hook", "hookgun"],
113 13 => ["Heavy Laser Assault Cannon", "hlac"],
114 14 => ["Tuba", "tuba"],
115 15 => ["Camping Rifle", "campingrifle"],
116 16 => ["Fireball", "fireball"],
119 sub weaponid_valid($$)
121 my ($self, $id) = @_;
122 return exists $WeaponMap{$id};
125 sub weaponid_to_name($$)
127 my ($self, $id) = @_;
128 exists $WeaponMap{$id} or warn "weapon of id $id not found\n";
129 return $WeaponMap{$id}[0];
132 sub weaponid_to_model($$)
134 my ($self, $id) = @_;
135 exists $WeaponMap{$id} or warn "weapon of id $id not found\n";
136 return $WeaponMap{$id}[1];
139 sub weaponid_from_name($$)
141 my ($self, $name) = @_;
145 if $WeaponMap{$_}[0] eq $name;