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 => ["Mine Layer", "minelayer"],
106 6 => ["Electro", "electro"],
107 7 => ["Crylink", "crylink"],
109 9 => ["Hagar", "hagar"],
110 10 => ["Rocket Launcher", "rl"],
111 11 => ["Port-O-Launch", "porto"],
112 12 => ["MinstaNex", "minstanex"],
113 13 => ["Grappling Hook", "hookgun"],
114 14 => ["Heavy Laser Assault Cannon", "hlac"],
115 15 => ["Tuba", "tuba"],
116 16 => ["Camping Rifle", "campingrifle"],
117 17 => ["Fireball", "fireball"],
118 18 => ["Seeker", "seeker"],
121 sub weaponid_valid($$)
123 my ($self, $id) = @_;
124 return exists $WeaponMap{$id};
127 sub weaponid_to_name($$)
129 my ($self, $id) = @_;
130 exists $WeaponMap{$id} or warn "weapon of id $id not found\n";
131 return $WeaponMap{$id}[0];
134 sub weaponid_to_model($$)
136 my ($self, $id) = @_;
137 exists $WeaponMap{$id} or warn "weapon of id $id not found\n";
138 return $WeaponMap{$id}[1];
141 sub weaponid_from_name($$)
143 my ($self, $name) = @_;
147 if $WeaponMap{$_}[0] eq $name;