1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
29 our @ISA = qw/Exporter/;
31 our @EXPORT = qw/shipEff shipStop parseValue prettyValue findCovOpper/;
34 my ($msg,$command) = @_;
35 my ($amount,$ship,$value,$target);
37 $eff = 0 if $command =~ /stop/;
38 if(defined $msg && $msg =~ /^(-?\d+(?:\.\d+)?[hkMG]?) (\w+)(?: (\w+))?/){
40 $target = ($3 || '%');
42 if ($command =~ /^v.+$/){
43 $value = parseValue($am);
44 $value *= -1.5 if $value < 0;
47 $amount = parseValue($am);
50 $ND::server->command("notice $ND::nick syntax: $command amount ship [race|class] | Amount can use SI prefixes like k and M. Race or class is an optional argument, using the short form (i.e. cath or Fi)");
55 my $s= $ND::DBH->selectrow_hashref(q{
56 SELECT name,t1,t2,t3,"type",damage
57 ,metal+crystal+eonium AS cost
58 ,init,"class",guns,race,eres,armor
59 FROM ship_stats WHERE name ILIKE ?
63 $amount = int(($value*100/$s->{cost}));
64 $feud = '(FEUD: '.prettyValue(int($amount/0.86)).') ';
66 $value = prettyValue(($amount*$s->{cost}/100));
67 my $name = shipColor($s->{name},$s->{type});
68 my $text = prettyValue($amount)." $name ($s->{init}:$value) :";
69 for my $tn ('t1','t2','t3'){
70 next if ($eff && not defined $s->{$tn});
71 $text .= " $ND::B${ND::C}03" . ($eff ? $s->{$tn} : $tn) . "$ND::O: ";
73 SELECT name,"class","type",armor
74 ,metal+crystal+eonium AS cost
75 ,init,t1,t2,t3,eres,race
80 $st = $ND::DBH->prepare($st . q{
82 AND ("class" ILIKE $2 OR race ILIKE $2)
84 $st->execute($s->{$tn},$target);
86 $st = $ND::DBH->prepare($st . qq{
88 AND ("class" ILIKE \$2 OR race ILIKE \$2)
90 $st->execute($s->{class},$target);
92 while (my $t = $st->fetchrow_hashref()){
93 my $number = calcEff($s,$t,$amount,$eff);
95 $number *= 0.60 if $tn eq 't2';
96 $number *= 0.30 if $tn eq 't3';
98 $number /= 0.60 if $tn eq 't2';
99 $number /= 0.30 if $tn eq 't3';
101 $number = int($number);
102 $value = prettyValue($number*$t->{cost}/100);
103 my $name = shipColor($t->{name},$t->{type});
104 $text .= " $ND::B$number$ND::O $name ($t->{init}:$value),";
108 $ND::server->command("notice $ND::nick $text");
113 my ($s,$t,$amount,$eff) = @_;
117 $number = $s->{type} eq 'Emp' ?
118 ($amount*$s->{guns}*(100-$t->{eres})/100)
119 : ($amount*$s->{damage}/$t->{armor});
121 $number = $t->{type} eq 'Emp' ?
122 ($amount*100/(100 - $s->{eres})/$t->{guns})
123 : ($amount*$s->{armor}/$t->{damage});
126 for my $tn ('t1','t2','t3'){
127 my ($s1,$t1) = $eff ? ($s,$t) : ($t,$s);
128 next unless (defined $t1->{$tn});
129 next unless ($t1->{$tn} eq $s1->{class});
131 if($t1->{init} <= $s1->{init}){
132 $t->{init} = "${ND::C}04$t->{init}$ND::O";
134 $t->{init} = "${ND::C}12$t->{init}$ND::O";
141 my ($string,$type) = @_;
143 $c = 12 if $type eq 'Emp';
144 $c = 13 if $type eq 'Steal';
145 return "$ND::C$c$string$ND::O";
149 my ($stolen, $command) = @_;
151 my $tick = $ND::tick;
154 if (defined $stolen && $stolen =~ /(\d+) (\d+) (\d+)/){
158 }elsif (defined $stolen && $stolen =~ /(\d+) (\d+)/){
162 $ND::server->command("notice $ND::nick syntax: .$command [tick] agents stolen | tick can be omitted if you're doing this the same tick you got cov opped, if you have different amount of your resources stolen, specify the highest amount. Only works if less than 10% of your resources and < 10,000*agents were stolen");
166 my ($value,$score) = $ND::DBH->selectrow_array(q{
167 SELECT value,score FROM planet_stats WHERE
168 id = (SELECT planet FROM users WHERE hostmask ILIKE ?) AND tick = ?;
169 }, undef, $ND::address,$tick);
171 $ND::server->command("notice $ND::nick No value found for tick $tick, can't find your cov opper.");
174 my $attackers = $ND::DBH->prepare(q{
175 SELECT coords(p.x,p.y,p.z), ruler, planet FROM current_planet_stats p JOIN planet_stats ps using (id) WHERE
176 ps.tick = $1 AND (2000.0*$2*$3/ps.value)::int = $4 ;
178 $attackers->execute($tick,$agents,$value,$stolen);
179 if ($attackers->rows == 0){
180 $ND::server->command("notice $ND::nick No cov opper found, did you specify the right tick, and was the stolen amount not capped?");
184 while (my $attacker = $attackers->fetchrow_hashref){
185 $coords .= " ($attacker->{coords} : $attacker->{ruler} OF $attacker->{planet})";
187 $ND::server->command("notice $ND::nick The planet that cov opped you is one of: $coords");