]> ruin.nu Git - ndwebbie.git/commitdiff
Converted targetlist and made it into a more general target picking tool
authorMichael Andreen <harv@ruin.nu>
Sun, 20 Jul 2008 11:05:43 +0000 (13:05 +0200)
committerMichael Andreen <harv@ruin.nu>
Sun, 20 Jul 2008 11:05:43 +0000 (13:05 +0200)
NDWeb/Pages/TargetList.pm [deleted file]
lib/NDWeb/Controller/Raids.pm
root/lib/site/leftbar.tt2
root/src/raids/targetlist.tt2 [new file with mode: 0644]
templates/targetList.tmpl [deleted file]

diff --git a/NDWeb/Pages/TargetList.pm b/NDWeb/Pages/TargetList.pm
deleted file mode 100644 (file)
index 97c0be4..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-package NDWeb::Pages::TargetList;
-use strict;
-use warnings FATAL => 'all';
-use ND::Include;
-use CGI qw/:standard/;
-use NDWeb::Include;
-
-use base qw/NDWeb::XMLPage/;
-
-$NDWeb::Page::PAGES{targetList} = __PACKAGE__;
-
-sub render_body {
-       my $self = shift;
-       my ($BODY) = @_;
-       $self->{TITLE} = 'NF Value';
-       my $DBH = $self->{DBH};
-
-       return $self->noAccess unless $self->isHC;
-
-       my $order = 'nfvalue';
-       if (local $_ = param('order')){
-               if (/^(size|value|score|xp)$/){
-                       $order = "$1 DESC";
-               }elsif (/^(nfvalue|nfvalue2)$/){
-                       $order = "$1 ASC";
-               }
-       }
-
-       my $alliances = '15';
-       if (param('alliances') && param('alliances') =~ /^([\d,]+)$/){
-               $alliances = $1;
-       }
-       my $query = $DBH->prepare(qq{
-SELECT coords(p.x,p.y,p.z),p.alliance, p.score, p.value, p.size, p.xp,nfvalue, nfvalue - sum(pa.value) AS nfvalue2, p.race
-FROM current_planet_stats p
-       JOIN (SELECT g.x,g.y, sum(p.value) AS nfvalue
-       FROM galaxies g join current_planet_stats p on g.x = p.x AND g.y = p.y 
-       WHERE g.tick = (SELECT max(tick) from galaxies)
-               AND ((NOT planet_status IN ('Friendly','NAP')) AND  (NOT relationship IN ('Friendly','NAP'))) 
-       GROUP BY g.x,g.y
-       ) g ON p.x = g.x AND p.y = g.y
-       JOIN current_planet_stats pa ON pa.x = g.x AND pa.y = g.y
-WHERE p.alliance_id IN ($alliances)
-       AND pa.alliance_id IN ($alliances)
-GROUP BY p.x,p.y,p.z,p.alliance, p.score, p.value, p.size, p.xp, nfvalue,p.race
-ORDER BY $order
-               });
-       $query->execute;
-       my @alliances;
-       while (my $alliance = $query->fetchrow_hashref){
-               push @alliances,$alliance;
-       }
-       $BODY->param(Alliances => \@alliances);
-
-       return $BODY;
-}
-1;
index df295773312e9d55a585fafd47f7a253d7a0ca42..205e1056fb8485ec35e3cc4f67af3877a04edd71 100644 (file)
@@ -298,7 +298,7 @@ sub edit : Local {
        }
        $c->stash(targets => \@targets);
 
-       $c->forward('/listAlliances');
+       $c->forward('listAlliances');
 }
 
 sub postraidupdate : Local {
@@ -508,9 +508,89 @@ sub postcreate : Local {
                ,html_escape $c->req->param('message'));
        my $raid = $query->fetchrow_array;
        $c->forward('log',[$raid,"Created raid landing at tick: ".$c->req->param('tick')]);
+
+       if ($c->req->param('gal') || $c->req->param('target')) {
+               my @gals = $c->req->param('gal');
+               my @targets = $c->req->param('target');
+
+               my $addtarget = $dbh->prepare(q{INSERT INTO raid_targets(raid,planet) (
+                       SELECT $1,id FROM current_planet_stats p WHERE (planet_status IN ('','Hostile')
+                               AND (relationship IS NULL OR relationship IN ('','Hostile')))
+                               AND (id = ANY ($2) OR ( size > $4 AND (x,y) IN (
+                                       SELECT x,y FROM current_planet_stats WHERE id = ANY ($3)))
+                               )
+                       )
+               });
+               $addtarget->execute($raid,\@targets,\@gals,$c->req->param('sizelimit'));
+               $c->forward('log',[$raid,"BC added planets (@targets) and the gals for (@gals)"]);
+       }
+
        $c->res->redirect($c->uri_for('edit',$raid));
 }
 
+sub targetlist : Local {
+       my ($self, $c, $alliances, $order) = @_;
+       my $dbh = $c->model;
+
+       $c->stash(comma => \&comma_value);
+       $c->stash(allies => $alliances);
+       my @alliances = split /,/, $alliances;
+
+       $c->forward('listAlliances');
+
+       if ($order =~ /^(sizerank|valuerank|scorerank|xprank|nfvalue|nfvalue2)$/){
+               $order = "$1";
+       }else{
+               $order = "nfvalue";
+       }
+       $order = "p.$order" if $order =~ /rank$/;
+
+       my $query = $dbh->prepare(q{
+SELECT p.id, coords(p.x,p.y,p.z),p.x,p.y,p.alliance, p.score, p.value, p.size, p.xp,nfvalue, nfvalue - sum(pa.value) AS nfvalue2, p.race
+FROM current_planet_stats p
+       JOIN (SELECT g.x,g.y, sum(p.value) AS nfvalue
+               FROM galaxies g join current_planet_stats p on g.x = p.x AND g.y = p.y
+               WHERE g.tick = (SELECT max(tick) from galaxies)
+                       AND (planet_status IN ('','Hostile')
+                               AND (relationship IS NULL OR relationship IN ('','Hostile')))
+               GROUP BY g.x,g.y
+       ) g ON p.x = g.x AND p.y = g.y
+       JOIN current_planet_stats pa ON pa.x = g.x AND pa.y = g.y
+WHERE p.x <> 200
+       AND p.alliance_id = ANY ($1)
+       AND pa.alliance_id = ANY ($1)
+       AND p.relationship IN ('','Hostile')
+GROUP BY p.id, p.x,p.y,p.z,p.alliance, p.score, p.value, p.size, p.xp, nfvalue,p.race
+       ,p.scorerank,p.valuerank,p.sizerank,p.xprank
+ORDER BY
+               } . $order);
+       $query->execute(\@alliances);
+       $c->stash(planets => $query->fetchall_arrayref({}) );
+       $c->forward('create');
+}
+
+sub posttargetalliances : Local {
+       my ($self, $c) = @_;
+
+       $c->res->redirect($c->uri_for('targetlist',join ',',$c->req->param('alliances')));
+}
+
+sub listAlliances : Private {
+       my ($self, $c) = @_;
+       my @alliances;
+       my $query = $c->model->prepare(q{SELECT id,name FROM alliances
+               WHERE relationship IN ('','Hostile')
+                       AND id IN (SELECT alliance_id FROM planets)
+                ORDER BY LOWER(name)
+               });
+       $query->execute;
+       push @alliances,{id => -1, name => ''};
+       while (my $ally = $query->fetchrow_hashref){
+               push @alliances,$ally;
+       }
+       $c->stash(alliances => \@alliances);
+}
+
 sub log : Private {
        my ($self, $c, $raid, $message) = @_;
        my $dbh = $c->model;
index 9e250e52b83fb484f34f39044725b251a6fd3fbb..08e1ac362dc1896ee67056a2cd0d6734d1cd11ba 100644 (file)
@@ -68,6 +68,7 @@
 <p>BC menu</p>
 <ul class="linkbar">
        <li><a href="/raids/create">Create raid</a></li>
+       <li><a href="/raids/targetlist">Find targets</a></li>
 </ul>
 [% END %]
 [% IF c.check_user_roles("dc_menu") %]
diff --git a/root/src/raids/targetlist.tt2 b/root/src/raids/targetlist.tt2
new file mode 100644 (file)
index 0000000..9c906b9
--- /dev/null
@@ -0,0 +1,56 @@
+[% META title = 'Target List' %]
+
+<form action="[% c.uri_for('posttargetalliances',raid.id) %]" method="post">
+       <fieldset> <legend>Pick alliances</legend>
+               <select name="alliances" multiple size="5">
+               [% FOR a IN alliances %]
+                               <option value="[% a.id %]" [% IF selected %]selected="selected"[% END %]>[% a.name %]</option>
+               [% END %]
+                       </select>
+                       <br><input type="submit" value="Show">
+       </fieldset>
+</form>
+
+<form action="[% c.uri_for('postcreate') %]" method="post">
+<table class="stats">
+       <tr>
+               <th>Coords</th>
+               <th>Alliance</th>
+               <th>Race</th>
+               <th><a href="[% c.uri_for('targetlist',allies,'scorerank') %]">Score</a></th>
+               <th><a href="[% c.uri_for('targetlist',allies,'valuerank') %]">Value</a></th>
+               <th><a href="[% c.uri_for('targetlist',allies,'xprank') %]">XP</a></th>
+               <th><a href="[% c.uri_for('targetlist',allies,'sizerank') %]">Size</a></th>
+               <th><a href="[% c.uri_for('targetlist',allies,'nfvalue') %]">NF Value</a></th>
+               <th><a href="[% c.uri_for('targetlist',allies,'nfvalue2') %]">NF Value - Ally Value</a></th>
+               <th>Add to raid</th>
+               <th>Add whole gal</th>
+       </tr>
+[% x = 0; y = 0; %]
+[% FOR p IN planets %]
+       <tr class="[% loop.count % 2 == 0 ? 'even' : 'odd ' %]">
+               <td><a href="[% c.uri_for('/stats/planet',p.id) %]">[% p.coords %]</a></td>
+               <td>[% p.alliance %]</td>
+               <td>[% p.race %]</td>
+               <td>[% comma(p.score) %]</td>
+               <td>[% comma(p.value) %]</td>
+               <td>[% comma(p.xp) %]</td>
+               <td>[% comma(p.size) %]</td>
+               <td>[% comma(p.nfvalue) %]</td>
+               <td>[% comma(p.nfvalue2) %]</td>
+               <td><input type="checkbox" name="target" value="[% p.id %]"></td>
+       [% IF x != p.x OR y != p.y %]
+               [% x = p.x; y = p.y; %]
+               <td><input type="checkbox" name="gal" value="[% p.id %]"> [% p.x %]:[% p.y %]</td>
+       [% END %]
+       </tr>
+[% END %]
+</table>
+<p>Landing tick: <input type="text" name="tick" value="[% landingtick %]"></p>
+<p>Number of waves: <input type="text" name="waves" value="[% waves %]"></p>
+<p>Sizelimit: <input type="text" name="sizelimit" value="0"></p>
+
+<p>Raid message here</p>
+<p><textarea rows="15" cols="40" name="message"></textarea></p>
+<p><input type="submit" value="Create raid"></p>
+</form>
diff --git a/templates/targetList.tmpl b/templates/targetList.tmpl
deleted file mode 100644 (file)
index 189e2c1..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-<TMPL_VAR NAME=Error>
-<table class="stats">
-       <tr>
-               <th>Coords</th>
-               <th>Alliance</th>
-               <th>Race</th>
-               <th><a href="/<TMPL_VAR NAME=PAGE>?order=score">Score</a></th>
-               <th><a href="/<TMPL_VAR NAME=PAGE>?order=value">Value</a></th>
-               <th><a href="/<TMPL_VAR NAME=PAGE>?order=xp">XP</a></th>
-               <th><a href="/<TMPL_VAR NAME=PAGE>?order=size">Size</a></th>
-               <th><a href="/<TMPL_VAR NAME=PAGE>?order=nfvalue">NF Value</a></th>
-               <th><a href="/<TMPL_VAR NAME=PAGE>?order=nfvalue2">NF Value - Ally Value</a></th>
-       </tr>
-<TMPL_LOOP Alliances>
-       <tr class="<TMPL_IF __odd__>odd<TMPL_ELSE>even</TMPL_IF>">
-               <td><a href="/check?coords=<TMPL_VAR NAME=Coords>"><TMPL_VAR NAME=Coords></a></td>
-               <td><TMPL_VAR NAME=Alliance></td>
-               <td><TMPL_VAR NAME=Race></td>
-               <td><TMPL_VAR NAME=score></td>
-               <td><TMPL_VAR NAME=Value></td>
-               <td><TMPL_VAR NAME=XP></td>
-               <td><TMPL_VAR NAME=size></td>
-               <td><TMPL_VAR NAME=nfvalue></td>
-               <td><TMPL_VAR NAME=nfvalue2></td>
-       </tr>
-</TMPL_LOOP>
-</table>