]> ruin.nu Git - ndwebbie.git/blob - resources.pl
more fatal warnings and other cleanup
[ndwebbie.git] / resources.pl
1 #**************************************************************************
2 #   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
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.                                   *
8 #                                                                         *
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.                          *
13 #                                                                         *
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 #**************************************************************************/
19
20 use strict;
21 use warnings FATAL => 'all';
22 no warnings qw(uninitialized);
23 use POSIX;
24 our $BODY;
25 our $DBH;
26 our $LOG;
27 my $error;
28
29 $ND::TEMPLATE->param(TITLE => 'Alliance Resources');
30
31 die "You don't have access" unless isHC();
32
33 my $order = "respplanet DESC";
34 if (param('order') =~ /^(score|resources|respplanet|nscore|nscore2|nscore3)$/){
35         $order = "$1 DESC";
36 }
37
38
39 my $query = $DBH->prepare(qq{
40 SELECT a.id,a.name,a.relationship,s.members,s.score,s.size,r.resources,r.planets, resources/planets AS respplanet, 
41         resources / 300 AS scoregain, score + (resources / 300) AS nscore, 
42         (resources/planets*LEAST(members,60))/300 AS scoregain2, score + (resources/planets*LEAST(members,60))/300 AS nscore2,
43         (s.size::int8*(1464-tick())*250)/100 + score + (resources/planets*LEAST(members,60))/300 AS nscore3,
44         (s.size::int8*(1464-tick())*250)/100 AS scoregain3
45 FROM (SELECT alliance_id AS id,sum(metal+crystal+eonium) AS resources, count(*) AS planets 
46                 FROM planets p join covop_targets c ON p.id = c.planet GROUP by alliance_id) r 
47         NATURAL JOIN alliances a 
48         LEFT OUTER JOIN (SELECT * FROM alliance_stats WHERE tick = (SELECT max(tick) FROM alliance_stats)) s ON a.id = s.id
49 ORDER BY $order
50         });
51 $query->execute;
52 my @alliances;
53 my $i = 0;
54 while (my $alliance = $query->fetchrow_hashref){
55         $i++;
56         $alliance->{ODD} = $i % 2;
57         push @alliances,$alliance;
58 }
59 $BODY->param(Alliances => \@alliances);
60
61 $BODY->param(Error => $error);
62 1;