X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=resources.pl;fp=resources.pl;h=5e63b7a5d3d6583c405101a982b668f39cf5ff97;hb=6eacbf94cc13b8b6df3018df1159065fc9a5140e;hp=0000000000000000000000000000000000000000;hpb=5af89dd22a075c6652b779ef471bf21cb9965cb6;p=ndwebbie.git diff --git a/resources.pl b/resources.pl new file mode 100644 index 0000000..5e63b7a --- /dev/null +++ b/resources.pl @@ -0,0 +1,60 @@ +#************************************************************************** +# 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. * +#**************************************************************************/ + +use strict; +use POSIX; +our $BODY; +our $DBH; +our $LOG; +my $error; + +$ND::TEMPLATE->param(TITLE => 'Alliance Resources'); + +die "You don't have access" unless isHC(); + +my $order = "respplanet DESC"; +if (param('order') =~ /^(score|resources|respplanet|nscore|nscore2|nscore3)$/){ + $order = "$1 DESC"; +} + + +my $query = $DBH->prepare(qq{ +SELECT a.id,a.name,a.relationship,s.members,s.score,s.size,r.resources,r.planets, resources/planets AS respplanet, + resources / 300 AS scoregain, score + (resources / 300) AS nscore, + (resources/planets*LEAST(members,60))/300 AS scoregain2, score + (resources/planets*LEAST(members,60))/300 AS nscore2, + (s.size::int8*(1464-tick())*250)/100 + score + (resources/planets*LEAST(members,60))/300 AS nscore3, + (s.size::int8*(1464-tick())*250)/100 AS scoregain3 +FROM (SELECT alliance_id AS id,sum(metal+crystal+eonium) AS resources, count(*) AS planets + FROM planets p join covop_targets c ON p.id = c.planet GROUP by alliance_id) r + NATURAL JOIN alliances a + LEFT OUTER JOIN (SELECT * FROM alliance_stats WHERE tick = (SELECT max(tick) FROM alliance_stats)) s ON a.id = s.id +ORDER BY $order + }); +$query->execute; +my @alliances; +my $i = 0; +while (my $alliance = $query->fetchrow_hashref){ + $alliance->{ODD} = $i % 2; + push @alliances,$alliance; + $i++ +} +$BODY->param(Alliances => \@alliances); + +$BODY->param(Error => $error); +1;