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 #**************************************************************************/
28 our @ISA = qw/Exporter/;
30 our @EXPORT = qw/checkPlanet checkGal shipEff shipStop parseValue prettyValue/;
33 my ($x,$y,$z,$intel) = @_;
35 my $f = $ND::DBH->prepare("SELECT ruler,planet,race,score,size,value,scorerank,sizerank,valuerank, xp, xprank, alliance FROM current_planet_stats WHERE x = ? AND y = ? and z = ?");
36 $f->execute($x,$y,$z);
37 while (my @row = $f->fetchrow()){
38 @row = map (valuecolor(1),@row);
40 $ally = " Alliance=$row[11]," if $intel;
41 $ND::server->command("notice $ND::target $x:$y:$z $row[0] OF $row[1],$ally Race=$row[2], Score=$row[3] ($row[6]), Size=$row[4] ($row[7]), Value=$row[5] ($row[8]), XP=$row[9] ($row[10])");
47 my $f = $ND::DBH->prepare("SELECT name,score,size,value FROM galaxies WHERE x = ? AND y = ? and tick = (SELECT max(tick) from galaxies)");
49 while (my @row = $f->fetchrow()){
50 @row = map (valuecolor(1),@row);
51 $ND::server->command("notice $ND::target $x:$y $row[0], Score=$row[1], Size=$row[2], Value=$row[3]");
56 my ($amount,$ship,$value) = @_;
58 $amount = parseValue($amount);
59 $value = parseValue($value);
60 $value *= -1.5 if defined $value and $value < 0;
62 my @ship = $ND::DBH->selectrow_array(q{
63 SELECT name,target,"type",damage,metal+crystal+eonium,init,"class",guns,race
64 FROM ship_stats WHERE name ILIKE ?
68 $type = "stun" if $ship[2] eq 'Emp';
69 $type = "steal" if ($ship[2] eq 'Steal') or ($ship[2] eq 'Pod');
71 $amount = int(($value*100/$ship[4])) if $amount eq 'value';
72 $value = prettyValue(($amount*$ship[4]/100));
73 my $text = "$amount $ship[0] ($ship[5]:$value) will $type:";
74 my $st = $ND::DBH->prepare(q{
75 SELECT name,"class","type",armor,metal+crystal+eonium,init,target,eres,race
76 FROM ship_stats WHERE "class" = ?
78 $st->execute($ship[1]);
79 while (my @target = $st->fetchrow()){
80 my $dead = $ship[2] eq 'Emp' ? int($amount*$ship[7]*(100-$target[7])/100) : int($amount*$ship[3]/$target[3]);
81 $value = prettyValue($dead*$target[4]/100);
82 if (($target[6] eq $ship[6]) and ($target[5] <= $ship[5])){
83 $target[5] = "${ND::C}04$target[5]$ND::C";
84 }elsif(($target[6] eq $ship[6]) and ($target[5] > $ship[5])){
85 $target[5] = "${ND::C}12$target[5]$ND::C";
87 $target[0] = "${ND::C}04$target[0]$ND::C" if $target[2] eq 'Norm' || $target[2] eq 'Cloak';
88 $target[0] = "${ND::C}12$target[0]$ND::C" if $target[2] eq 'Emp';
89 $target[0] = "${ND::C}13$target[0]$ND::C" if $target[2] eq 'Steal';
90 $text .= " $ND::B$dead$ND::B $target[0] ($target[5]:$value),";
93 $ND::server->command("notice $ND::target $text");
99 my ($amount,$ship,$value) = @_;
101 $amount = parseValue($amount);
102 $value = parseValue($value);
103 $value *= -1.5 if defined $value and $value < 0;
105 my @ship = $ND::DBH->selectrow_array(q{
106 SELECT name,target,"type",armor,metal+crystal+eonium,init,"class",eres,race
107 FROM ship_stats WHERE name ILIKE ?
110 $ship[0] = "${ND::C}04$ship[0]$ND::C" if $ship[2] eq 'Norm';
111 $ship[0] = "${ND::C}12$ship[0]$ND::C" if $ship[2] eq 'Emp';
112 $ship[0] = "${ND::C}13$ship[0]$ND::C" if $ship[2] eq 'Steal';
114 $amount = int(($value*100/$ship[4])) if $amount eq 'value';
115 $value = prettyValue(($amount*$ship[4]/100));
116 my $text = "To stop $amount $ship[0] ($ship[5]:$value) you need:";
117 my $st = $ND::DBH->prepare(q{
118 SELECT name,"class","type",damage,metal+crystal+eonium,init,target,guns,race
119 FROM ship_stats WHERE "target" = ?
121 $st->execute($ship[6]);
122 while (my @stopper = $st->fetchrow()){
123 my $needed = $stopper[2] eq 'Emp' ? ceil($amount*100/(100-$ship[7])/$stopper[7]) : ceil($amount*$ship[3]/$stopper[3]);
124 $value = prettyValue($needed*$stopper[4]/100);
125 if (($stopper[1] eq $ship[1]) and ($ship[5] <= $stopper[5])){
126 $stopper[5] = "${ND::C}04$stopper[5]$ND::C";
127 }elsif(($stopper[1] eq $ship[1]) and ($ship[5] > $stopper[5])){
128 $stopper[5] = "${ND::C}12$stopper[5]$ND::C";
130 $stopper[0] = "${ND::C}04$stopper[0]$ND::C" if $stopper[2] eq 'Norm' || $stopper[2] eq 'Cloak';
131 $stopper[0] = "${ND::C}12$stopper[0]$ND::C" if $stopper[2] eq 'Emp';
132 $stopper[0] = "${ND::C}13$stopper[0]$ND::C" if $stopper[2] eq 'Steal';
133 $text .= " $ND::B$needed$ND::B $stopper[0] ($stopper[5]:$value),";
136 $ND::server->command("notice $ND::target $text");
142 if (defined $_[0] && $_[0] =~ /^(-?\d+(?:\.\d+)?)([khMG])?$/){
143 return $1 unless defined $2;
144 return $1*100 if $2 eq 'h';
145 return $1*1000 if $2 eq 'k';
146 return $1*1000000 if $2 eq 'M';
147 return $1*1000000000 if $2 eq 'G';
155 my @units = ('k','M','G','T');
156 for (my $i = 0; $value >= 1000;$i++){
160 return sprintf('%.2f%s', $value,$unit);
166 return ($x > $y ? $y : $x);
171 return ($x < $y ? $y : $x);
175 my ($x,$y,$z,$roids) = @_;
177 my ($avalue,$ascore) = $ND::DBH->selectrow_array(q{
178 SELECT value,score FROM current_planet_stats WHERE
179 id = (SELECT planet FROM users WHERE hostmask ILIKE ?);
180 }, undef, $ND::address);
181 my ($tvalue,$tscore) = $ND::DBH->selectrow_array(q{
182 SELECT value,score FROM current_planet_stats WHERE
183 x = ? AND y = ? and z = ?;
185 unless (defined $avalue && defined $ascore){
186 $ND::server->command("notice $ND::target You don't have a planet specified");
189 unless (defined $tvalue && defined $tscore){
190 $ND::server->command("notice $ND::target Doesn't seem to be a planet at $x:$y:$z");
193 my $xp = int(max($roids * 10 * (min(2,$tscore/$ascore) + min(2,$tvalue/$avalue) - 1),0));
194 my $score = 60 * $xp;
195 $ND::server->command("notice $ND::target You will gain $ND::B$xp$ND::B XP, $ND::B$score$ND::B score, if you steal $roids roids from $x:$y:$z");