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/checkPlanet checkGal shipEff shipStop parseValue prettyValue calcXp/;
34 my ($x,$y,$z,$intel) = @_;
36 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 = ?");
37 $f->execute($x,$y,$z);
38 while (my @row = $f->fetchrow()){
39 @row = map (valuecolor(1),@row);
41 $ally = " Alliance=$row[11]," if $intel;
42 $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])");
48 my $f = $ND::DBH->prepare("SELECT name,score,size,value FROM galaxies WHERE x = ? AND y = ? and tick = (SELECT max(tick) from galaxies)");
50 while (my @row = $f->fetchrow()){
51 @row = map (valuecolor(1),@row);
52 $ND::server->command("notice $ND::target $x:$y $row[0], Score=$row[1], Size=$row[2], Value=$row[3]");
57 my ($amount,$ship,$value) = @_;
59 $amount = parseValue($amount);
60 $value = parseValue($value);
61 $value *= -1.5 if defined $value and $value < 0;
63 my @ship = $ND::DBH->selectrow_array(q{
64 SELECT name,target,"type",damage,metal+crystal+eonium,init,"class",guns,race
65 FROM ship_stats WHERE name ILIKE ?
69 $type = "stun" if $ship[2] eq 'Emp';
70 $type = "steal" if ($ship[2] eq 'Steal') or ($ship[2] eq 'Pod');
72 $amount = int(($value*100/$ship[4])) if $amount eq 'value';
73 $value = prettyValue(($amount*$ship[4]/100));
74 my $text = "$amount $ship[0] ($ship[5]:$value) will $type:";
75 my $st = $ND::DBH->prepare(q{
76 SELECT name,"class","type",armor,metal+crystal+eonium,init,target,eres,race
77 FROM ship_stats WHERE "class" = ?
79 $st->execute($ship[1]);
80 while (my @target = $st->fetchrow()){
81 my $dead = $ship[2] eq 'Emp' ? int($amount*$ship[7]*(100-$target[7])/100) : int($amount*$ship[3]/$target[3]);
82 $value = prettyValue($dead*$target[4]/100);
83 if (($target[6] eq $ship[6]) and ($target[5] <= $ship[5])){
84 $target[5] = "${ND::C}04$target[5]$ND::C";
85 }elsif(($target[6] eq $ship[6]) and ($target[5] > $ship[5])){
86 $target[5] = "${ND::C}12$target[5]$ND::C";
88 $target[0] = "${ND::C}04$target[0]$ND::C" if $target[2] eq 'Norm' || $target[2] eq 'Cloak';
89 $target[0] = "${ND::C}12$target[0]$ND::C" if $target[2] eq 'Emp';
90 $target[0] = "${ND::C}13$target[0]$ND::C" if $target[2] eq 'Steal';
91 $text .= " $ND::B$dead$ND::B $target[0] ($target[5]:$value),";
94 $ND::server->command("notice $ND::target $text");
100 my ($amount,$ship,$value) = @_;
102 $amount = parseValue($amount);
103 $value = parseValue($value);
104 $value *= -1.5 if defined $value and $value < 0;
106 my @ship = $ND::DBH->selectrow_array(q{
107 SELECT name,target,"type",armor,metal+crystal+eonium,init,"class",eres,race
108 FROM ship_stats WHERE name ILIKE ?
111 $ship[0] = "${ND::C}04$ship[0]$ND::C" if $ship[2] eq 'Norm';
112 $ship[0] = "${ND::C}12$ship[0]$ND::C" if $ship[2] eq 'Emp';
113 $ship[0] = "${ND::C}13$ship[0]$ND::C" if $ship[2] eq 'Steal';
115 $amount = int(($value*100/$ship[4])) if $amount eq 'value';
116 $value = prettyValue(($amount*$ship[4]/100));
117 my $text = "To stop $amount $ship[0] ($ship[5]:$value) you need:";
118 my $st = $ND::DBH->prepare(q{
119 SELECT name,"class","type",damage,metal+crystal+eonium,init,target,guns,race
120 FROM ship_stats WHERE "target" = ?
122 $st->execute($ship[6]);
123 while (my @stopper = $st->fetchrow()){
124 my $needed = $stopper[2] eq 'Emp' ? ceil($amount*100/(100-$ship[7])/$stopper[7]) : ceil($amount*$ship[3]/$stopper[3]);
125 $value = prettyValue($needed*$stopper[4]/100);
126 if (($stopper[1] eq $ship[1]) and ($ship[5] <= $stopper[5])){
127 $stopper[5] = "${ND::C}04$stopper[5]$ND::C";
128 }elsif(($stopper[1] eq $ship[1]) and ($ship[5] > $stopper[5])){
129 $stopper[5] = "${ND::C}12$stopper[5]$ND::C";
131 $stopper[0] = "${ND::C}04$stopper[0]$ND::C" if $stopper[2] eq 'Norm' || $stopper[2] eq 'Cloak';
132 $stopper[0] = "${ND::C}12$stopper[0]$ND::C" if $stopper[2] eq 'Emp';
133 $stopper[0] = "${ND::C}13$stopper[0]$ND::C" if $stopper[2] eq 'Steal';
134 $text .= " $ND::B$needed$ND::B $stopper[0] ($stopper[5]:$value),";
137 $ND::server->command("notice $ND::target $text");
143 my ($x,$y,$z,$roids) = @_;
145 my ($avalue,$ascore) = $ND::DBH->selectrow_array(q{
146 SELECT value,score FROM current_planet_stats WHERE
147 id = (SELECT planet FROM users WHERE hostmask ILIKE ?);
148 }, undef, $ND::address);
149 my ($tvalue,$tscore) = $ND::DBH->selectrow_array(q{
150 SELECT value,score FROM current_planet_stats WHERE
151 x = ? AND y = ? and z = ?;
153 unless (defined $avalue && defined $ascore){
154 $ND::server->command("notice $ND::target You don't have a planet specified");
157 unless (defined $tvalue && defined $tscore){
158 $ND::server->command("notice $ND::target Doesn't seem to be a planet at $x:$y:$z");
161 my $xp = int(max($roids * 10 * (min(2,$tscore/$ascore) + min(2,$tvalue/$avalue) - 1),0));
162 my $score = 60 * $xp;
163 $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");