]> ruin.nu Git - ndwebbie.git/blobdiff - ND/Web/Pages/Raids.pm
possible to hide targets below bash limits, if we chose to
[ndwebbie.git] / ND / Web / Pages / Raids.pm
index 15b8f68ec53afe5292c01e2cf510fb5efd43287a..afb91c1adb64501481b5f643837489755edc570d 100644 (file)
 
 package ND::Web::Pages::Raids;
 use strict;
-use warnings FATAL => 'all';
+use warnings;
 use ND::Include;
 use POSIX;
 use CGI qw/:standard/;
 use ND::Web::Include;
 
-our @ISA = qw/ND::Web::XMLPage/;
+use base qw/ND::Web::XMLPage/;
 
 $ND::Web::Page::PAGES{raids} = __PACKAGE__;
 
@@ -63,7 +63,6 @@ sub generateClaimXml : method {
        while (my $target = $targets->fetchrow_hashref){
                my %target;
                $target{Id} = $target->{id};
-               $target{Coords} = $target->{id};
                my @waves;
                for (my $i = 1; $i <= $raid->{waves}; $i++){
                        my %wave;
@@ -83,9 +82,6 @@ sub generateClaimXml : method {
                                $claimers = join '/', @claimers;
                                if ($owner){
                                        $wave{Command} = 'Unclaim';
-                                       if ($raid->{released_coords}){
-                                               $target{Coords} = $DBH->selectrow_array('SELECT coords(x,y,z) FROM current_planet_stats WHERE id = ?',undef,$target->{planet});
-                                       }
                                }elsif ($joinable){
                                        $wave{Command} = 'Join';
                                }else{
@@ -178,7 +174,7 @@ sub render_body {
                return $self->generateClaimXml($BODY,$raid,$from);
        }
        if ($self->{XML} && param('cmd') eq 'gettargets' ){
-               $_ = listTargets();
+               $_ = $self->listTargets();
                $BODY->param(TargetList => $_);
        }
 
@@ -195,8 +191,8 @@ sub render_body {
                        $noingal = "AND NOT (x = $planet->{x} AND y = $planet->{y})";
                }
                $BODY->param(Message => parseMarkup($raid->{message}));
-               $BODY->param(LandingTick => parseMarkup($raid->{tick}));
-               my $targetquery = $DBH->prepare(qq{SELECT r.id, r.planet, size, score, value, coords(p.x,p.y,p.z), race, p.value - p.size*200 -coalesce(c.metal+c.crystal+c.eonium,0)/150 - coalesce(c.structures,(SELECT avg(structures) FROM covop_targets)::int)*1500 AS fleetvalue,(c.metal+c.crystal+c.eonium)/100 AS resvalue, comment
+               $BODY->param(LandingTick => $raid->{tick});
+               my $targetquery = $DBH->prepare(qq{SELECT r.id, r.planet, size, score, value, p.x,p.y,p.z, race, p.value - p.size*200 -coalesce(c.metal+c.crystal+c.eonium,0)/150 - coalesce(c.structures,(SELECT avg(structures) FROM covop_targets)::int)*1500 AS fleetvalue,(c.metal+c.crystal+c.eonium)/100 AS resvalue, comment
                        FROM current_planet_stats p 
                        JOIN raid_targets r ON p.id = r.planet 
                        LEFT OUTER JOIN covop_targets c ON p.id = c.planet
@@ -207,6 +203,14 @@ sub render_body {
                my @targets;
                while (my $target = $targetquery->fetchrow_hashref){
                        my %target;
+                       if ($planet){
+                               if ($planet->{x} == $target->{x}){
+                                       $target{style} = 'incluster';
+                               }
+                               $target{ScoreBash} = 'bash' if ($target->{score}/$planet->{score} < 0.4);
+                               $target{ValueBash} = 'bash' if ($target->{value}/$planet->{value} < 0.4);
+                               #next if ($target->{score}/$planet->{score} < 0.4) && ($target->{value}/$planet->{value} < 0.4);
+                       }
                        $target{Id} = $target->{id};
                        $target{Race} = $target->{race};
                        my $num = pow(10,length($target->{score})-2);
@@ -224,7 +228,7 @@ sub render_body {
                        $target{comment} = parseMarkup($target->{comment}) if ($target->{comment});
 
                        my $scans = $DBH->prepare(q{SELECT DISTINCT ON (type) type, tick, scan FROM scans 
-                               WHERE planet = ? AND type ~ 'Unit|Planet|Military|.* Analysis' AND tick + 24 > tick()
+                               WHERE planet = ? AND type ~ 'Unit|Planet|Advanced Unit|.* Analysis' AND tick + 24 > tick() AND scan is not null
                                GROUP BY type, tick, scan ORDER BY type ,tick DESC});
                        $scans->execute($target->{planet});
                        my %scans;
@@ -233,11 +237,11 @@ sub render_body {
                        }
 
                        my @scans;
-                       for my $type ('Planet','Unit','Military','Surface Analysis','Technology Analysis'){
+                       for my $type ('Planet','Unit','Advanced Unit','Surface Analysis','Technology Analysis'){
                                next unless exists $scans{$type};
                                my $scan = $scans{$type};
                                if ($self->{TICK} - $scan->{tick} > 5){
-                                       $scan->{scan} =~ s{<table( cellpadding="\d+")?>}{<table$1 class="old">};
+                                       $scan->{scan} =~ s{<table( cellpadding="\d+")?>}{<table class="old">};
                                }
                                if ($type eq 'Planet'){
                                        $target{PlanetScan} = $scan->{scan};
@@ -247,15 +251,16 @@ sub render_body {
                        }
                        $target{Scans} = \@scans;
 
+
                        my @roids;
                        my @claims;
                        my $size = $target{Size};
                        for (my $i = 1; $i <= $raid->{waves}; $i++){
                                my $roids = floor(0.25*$size);
                                $size -= $roids;
-                               my $xp;
+                               my $xp = 0;
                                if ($planet){
-                                       $xp = max(0,floor($roids * 10 * (min(2,$target{Score}/$planet->{score}) + min(2,$target{Value}/$planet->{value})-1)));
+                                       $xp = pa_xp($roids,$planet->{score},$planet->{value},$target{Score},$target{Value});
                                }
                                push @roids,{Wave => $i, Roids => $roids, XP => $xp};
                                if ($self->{AJAX}){
@@ -270,6 +275,8 @@ sub render_body {
 
                        push @targets,\%target;
                }
+               @targets = sort {$b->{Roids}[0]{XP} <=> $a->{Roids}[0]{XP} or $b->{Size} <=> $a->{Size}} @targets;
+
                $BODY->param(Targets => \@targets);
        }else{#list raids if we haven't chosen one yet
                my $query = $DBH->prepare(q{SELECT id,released_coords FROM raids WHERE open AND not removed AND