From 6d6fb5c63900813306e63320bd4b8700f8b37719 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Sun, 20 Jul 2008 13:05:43 +0200 Subject: [PATCH] Converted targetlist and made it into a more general target picking tool --- NDWeb/Pages/TargetList.pm | 76 -------------------------------- lib/NDWeb/Controller/Raids.pm | 82 ++++++++++++++++++++++++++++++++++- root/lib/site/leftbar.tt2 | 1 + root/src/raids/targetlist.tt2 | 56 ++++++++++++++++++++++++ templates/targetList.tmpl | 27 ------------ 5 files changed, 138 insertions(+), 104 deletions(-) delete mode 100644 NDWeb/Pages/TargetList.pm create mode 100644 root/src/raids/targetlist.tt2 delete mode 100644 templates/targetList.tmpl diff --git a/NDWeb/Pages/TargetList.pm b/NDWeb/Pages/TargetList.pm deleted file mode 100644 index 97c0be4..0000000 --- a/NDWeb/Pages/TargetList.pm +++ /dev/null @@ -1,76 +0,0 @@ -#************************************************************************** -# Copyright (C) 2006 by Michael Andreen * -# * -# 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; diff --git a/lib/NDWeb/Controller/Raids.pm b/lib/NDWeb/Controller/Raids.pm index df29577..205e105 100644 --- a/lib/NDWeb/Controller/Raids.pm +++ b/lib/NDWeb/Controller/Raids.pm @@ -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; diff --git a/root/lib/site/leftbar.tt2 b/root/lib/site/leftbar.tt2 index 9e250e5..08e1ac3 100644 --- a/root/lib/site/leftbar.tt2 +++ b/root/lib/site/leftbar.tt2 @@ -68,6 +68,7 @@

BC menu

[% 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 index 0000000..9c906b9 --- /dev/null +++ b/root/src/raids/targetlist.tt2 @@ -0,0 +1,56 @@ +[% META title = 'Target List' %] + +
+
Pick alliances + +
+
+
+ +
+ + + + + + + + + + + + + + +[% x = 0; y = 0; %] +[% FOR p IN planets %] + + + + + + + + + + + + [% IF x != p.x OR y != p.y %] + [% x = p.x; y = p.y; %] + + [% END %] + +[% END %] +
CoordsAllianceRaceScoreValueXPSizeNF ValueNF Value - Ally ValueAdd to raidAdd whole gal
[% p.coords %][% p.alliance %][% p.race %][% comma(p.score) %][% comma(p.value) %][% comma(p.xp) %][% comma(p.size) %][% comma(p.nfvalue) %][% comma(p.nfvalue2) %] [% p.x %]:[% p.y %]
+

Landing tick:

+

Number of waves:

+

Sizelimit:

+ +

Raid message here

+

+

+
diff --git a/templates/targetList.tmpl b/templates/targetList.tmpl deleted file mode 100644 index 189e2c1..0000000 --- a/templates/targetList.tmpl +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - -
CoordsAllianceRaceScoreValueXPSizeNF ValueNF Value - Ally Value
-- 2.39.2