1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
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. *
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. *
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 #**************************************************************************/
28 if (param('raid') =~ /^(\d+)$/){
29 my $query = $DBH->prepare(q{SELECT id,tick,waves,message,released_coords FROM raids WHERE id = ? AND open AND not removed AND id IN (SELECT raid FROM raid_access NATURAL JOIN groupmembers WHERE uid = ?)});
30 $raid = $DBH->selectrow_hashref($query,undef,$1,$ND::UID);
34 $ND::TEMPLATE->param(TITLE => 'Raids');
35 $ND::TEMPLATE->param(HEADER => '<script type="text/javascript" src="raid.js"></script>');
36 if ($raid){#We have a raid, so list all targets
37 $BODY->param(Raid => $raid->{id});
41 my $query = $DBH->prepare("SELECT value, score,x,y FROM current_planet_stats WHERE id = ?");
42 $planet = $DBH->selectrow_hashref($query,undef,$ND::PLANET);
43 $noingal = "AND NOT (x = $planet->{x} AND y = $planet->{y})";
45 $BODY->param(Message => parseMarkup($raid->{message}));
46 $BODY->param(LandingTick => parseMarkup($raid->{tick}));
47 my $targetquery = $DBH->prepare(qq{SELECT r.id, r.planet, size, score, value, coords(p.x,p.y,p.z), race, p.value - p.size*200 -coalesce(c.metal+c.crystal+c.eonium,0)/150 - coalesce(c.structures,(SELECT avg(structures) FROM covop_targets)::int)*1500 AS fleetvalue,(c.metal+c.crystal+c.eonium)/100 AS resvalue, comment
48 FROM current_planet_stats p
49 JOIN raid_targets r ON p.id = r.planet
50 LEFT OUTER JOIN covop_targets c ON p.id = c.planet
54 $targetquery->execute($raid->{id});
56 while (my $target = $targetquery->fetchrow_hashref){
58 $target{Id} = $target->{id};
59 my $num = pow(10,length($target->{score})-2);
60 $target{Score} = ceil($target->{score}/$num)*$num;
61 $num = pow(10,length($target->{value})-2);
62 $target{Value} = ceil($target->{value}/$num)*$num;
63 $num = pow(10,length($target->{size})-2);
64 $target{Size} = floor($target->{size}/$num)*$num;
65 $num = pow(10,length($target->{fleetvalue})-2);
66 $target{FleetValue} = floor($target->{fleetvalue}/$num)*$num;
67 $num = pow(10,length($target->{resvalue})-2);
68 $target{ResValue} = floor($target->{resvalue}/$num)*$num;
69 $target{comment} = parseMarkup($target->{comment}) if ($target->{comment});
71 my $size = $target{Size};
72 for (my $i = 1; $i <= $raid->{waves}; $i++){
73 my $roids = floor(0.25*$size);
77 $xp = max(0,floor($roids * 10 * (min(2,$target{Score}/$planet->{score}) + min(2,$target{Value}/$planet->{value})-1)));
79 push @roids,{Wave => $i, Roids => $roids, XP => $xp};
81 $target{Roids} = \@roids;
83 push @targets,\%target;
85 $BODY->param(Targets => \@targets);
86 }else{#list raids if we haven't chosen one yet
87 my $query = $DBH->prepare(q{SELECT id,released_coords FROM raids WHERE open AND not removed AND
88 id IN (SELECT raid FROM raid_access NATURAL JOIN groupmembers WHERE uid = ?)});
89 $query->execute($ND::UID);
91 while (my $raid = $query->fetchrow_hashref){
92 push @raids,{Raid => $raid->{id}, ReleasedCoords => $raid->{released_coords}, isBC => isBC()};
94 $BODY->param(Raids => \@raids);
97 my $query = $DBH->prepare(q{SELECT id,open FROM raids WHERE not removed AND (not open
98 OR id NOT IN (SELECT raid FROM raid_access NATURAL JOIN groupmembers WHERE uid = ?))});
99 $query->execute($ND::UID);
101 while (my $raid = $query->fetchrow_hashref){
102 push @raids,{Raid => $raid->{id}, Open => $raid->{open}};
104 $BODY->param(ClosedRaids => \@raids);