]> ruin.nu Git - ndwebbie.git/blob - covop.pl
nicer output
[ndwebbie.git] / covop.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
23 $ND::TEMPLATE->param(TITLE => 'CovOp Targets');
24
25 our $BODY;
26 our $DBH;
27 our $LOG;
28
29 die "You don't have access" unless isMember();
30
31 my $show = q{AND ((planet_status IS NULL OR NOT planet_status IN ('Friendly','NAP')) AND  (relationship IS NULL OR NOT relationship IN ('Friendly','NAP')))};
32 $show = '' if defined param('show') && param('show') eq 'all';
33 if (defined param('covop') && param('covop') =~ /^(\d+)$/){
34         my $update = $DBH->prepare('UPDATE covop_targets SET covop_by = ?, last_covop = tick() WHERE planet = ? ');
35         $update->execute($ND::UID,$1);
36 }
37
38 my $list = '';
39 my $where = '';
40 if (defined param('list') && param('list') eq 'distwhores'){
41         $list = '&amp;list=distwhores';
42         $where = qq{WHERE dists > 0 $show
43 ORDER BY dists DESC,COALESCE(sec_centres::float/structures*100,0)ASC}
44 }else{
45         $where = qq{WHERE MaxResHack > 130000 
46                 $show
47 ORDER BY COALESCE(sec_centres::float/structures*100,0) ASC,MaxResHack DESC,metal+crystal+eonium DESC};
48 }
49
50 my $query = $DBH->prepare(qq{SELECT id, coords, metal, crystal, eonium, sec_centres::float/structures*100 AS secs, dists, last_covop, username, MaxResHack
51 FROM (SELECT p.id,coords(x,y,z), metal,crystal,eonium,
52         sec_centres,NULLIF(structures,0) AS structures,dists,last_covop,
53         u.username,max_bank_hack(metal,crystal,eonium,p.value,(SELECT value FROM
54         current_planet_stats WHERE id = ?)) AS MaxResHack, planet_status, relationship
55 FROM covop_targets c JOIN current_planet_stats p ON p.id = c.planet
56         LEFT OUTER JOIN users u ON u.uid = c.covop_by) AS foo
57         $where});
58 $query->execute($ND::PLANET);
59
60 my @targets;
61 my $i = 0;
62 while (my ($id,$coords,$metal,$crystal,$eonium,$seccents,$dists,$lastcovop,$user,$max) = $query->fetchrow){
63         $i++;
64         push @targets,{Username => $user, Target => $id, Coords => $coords
65                 , Metal => $metal, Crystal => $crystal, Eonium => $eonium, SecCents => $seccents
66                 , Dists => $dists, MaxResHack => $max, LastCovOp => $lastcovop, List => $list, ODD => $i % 2};
67 }
68 $BODY->param(Targets => \@targets);
69
70 1;