]> ruin.nu Git - ndwebbie.git/blob - include.pl
working on raids
[ndwebbie.git] / include.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
22
23 sub isMember {
24         return exists $ND::GROUPS{Members};
25 }
26
27 sub isHC {
28         return exists $ND::GROUPS{HC};
29 }
30
31 sub isDC {
32         return exists $ND::GROUPS{DC};
33 }
34
35 sub isBC {
36         return exists $ND::GROUPS{BC};
37 }
38
39 sub isOfficer {
40         return exists $ND::GROUPS{Officers};
41 }
42
43 sub isScanner {
44         return exists $ND::GROUPS{Scanner};
45 }
46
47 sub parseMarkup {
48         my ($text) = @_;
49
50         $text =~ s{\n}{\n<br/>}g;
51         $text =~ s{\[B\](.*?)\[/B\]}{<b>$1</b>};
52         return $text;
53 }
54
55 sub min {
56     my ($x,$y) = @_;
57     return ($x > $y ? $y : $x);
58 }
59
60 sub max {
61     my ($x,$y) = @_;
62     return ($x < $y ? $y : $x);
63 }
64
65 sub listTargets {
66         my $query = $ND::DBH->prepare(qq{SELECT t.id, r.id AS raid, r.tick+c.wave-1 AS landingtick, released_coords, coords(x,y,z),c.launched
67 FROM raid_claims c
68         JOIN raid_targets t ON c.target = t.id
69         JOIN raids r ON t.raid = r.id
70         JOIN current_planet_stats p ON t.planet = p.id
71 WHERE c.uid = ? AND r.tick+c.wave > ? AND r.open AND not r.removed
72 ORDER BY r.tick+c.wave,x,y,z});
73         $query->execute($ND::UID,$ND::TICK);
74         my @targets;
75         while (my $target = $query->fetchrow_hashref){
76                 my $coords = "Target $target->{id}";
77                 $coords = $target->{coords} if $target->{released_coords};
78                 push @targets,{Coords => $coords, Launched => $target->{launched}, Raid => $target->{raid}
79                         , Target => $target->{id}, Tick => $target->{landingtick}};
80         }
81         my $template = HTML::Template->new(filename => "templates/targetlist.tmpl");
82         $template->param(Targets => \@targets);
83         return $template->output;
84 }
85
86 1;