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 #**************************************************************************/
26 $ND::TEMPLATE->param(TITLE => 'Defense Calls');
28 die "You don't have access" unless isBC();
32 if (param('call') =~ /^(\d+)$/){
33 my $query = $DBH->prepare(q{
34 SELECT c.id, coords(p.x,p.y,p.z), c.landing_tick, c.info, covered, open, dc.username AS dc, u.defense_points,c.member
36 JOIN users u ON c.member = u.uid
37 LEFT OUTER JOIN users dc ON c.dc = dc.uid
38 JOIN current_planet_stats p ON u.planet = p.id
40 $call = $DBH->selectrow_hashref($query,undef,$1);
44 $BODY->param(Call => $call->{id});
45 $BODY->param(Coords => $call->{coords});
46 $BODY->param(DefensePoints => $call->{defense_points});
47 $BODY->param(LandingTick => $call->{landing_tick});
48 $BODY->param(ETA => $call->{landing_tick}-$ND::TICK);
49 $BODY->param(Info => $call->{info});
50 if ($call->{covered}){
51 $BODY->param(Cover => 'Uncover');
53 $BODY->param(Cover => 'Cover');
55 if ($call->{open} && !$call->{covered}){
56 $BODY->param(Cover => 'Ignore');
58 $BODY->param(Cover => 'Open');
60 my $fleets = $DBH->prepare(q{
61 SELECT id,mission,landing_tick,eta, (landing_tick+eta-1) AS back FROM fleets WHERE uid = ? AND (fleet = 0 OR (landing_tick + eta > ? AND landing_tick - eta - 11 < ? ))
63 my $ships = $DBH->prepare('SELECT ship,amount FROM fleet_ships WHERE fleet = ?');
64 $fleets->execute($call->{member},$call->{landing_tick},$call->{landing_tick});
66 while (my $fleet = $fleets->fetchrow_hashref){
67 if ($fleet->{back} == $call->{landing_tick}){
68 $fleet->{Fleetcatch} = 1;
70 $ships->execute($fleet->{id});
72 while (my $ship = $ships->fetchrow_hashref){
75 $fleet->{Ships} = \@ships;
78 $BODY->param(Fleets => \@fleets);
80 my $attackers = $DBH->prepare(q{
81 SELECT coords(p.x,p.y,p.z), p.planet_status, p.race,i.eta,i.amount,i.fleet,i.shiptype,p.relationship,p.alliance,i.id
83 JOIN current_planet_stats p ON i.sender = p.id
85 ORDER BY p.x,p.y,p.z});
86 $attackers->execute($call->{id});
88 while(my $attacker = $attackers->fetchrow_hashref){
89 push @attackers,$attacker;
91 $BODY->param(Attackers => \@attackers);
93 my $where = 'open AND c.landing_tick-6 > tick()';
94 if (param('show') eq 'covered'){
96 }elsif (param('show') eq 'all'){
98 }elsif (param('show') eq 'uncovered'){
99 $where = 'not covered';
101 my $query = $DBH->prepare(qq{
102 SELECT c.id, coords(p.x,p.y,p.z), u.defense_points, c.landing_tick,
103 TRIM('/' FROM concat(p2.race||'/')) AS race, TRIM('/' FROM concat(i.amount||'/')) AS amount,
104 TRIM('/' FROM concat(i.eta||'/')) AS eta, TRIM('/' FROM concat(i.shiptype||'/')) AS shiptype,
105 TRIM('/' FROM concat(c.landing_tick - tick() ||'/')) AS curreta,
106 TRIM('/' FROM concat(p2.alliance ||'/')) AS alliance,
107 TRIM('/' FROM concat(coords(p2.x,p2.y,p2.z) ||'/')) AS attackers
109 JOIN incomings i ON i.call = c.id
110 JOIN users u ON c.member = u.uid
111 JOIN current_planet_stats p ON u.planet = p.id
112 JOIN current_planet_stats p2 ON i.sender = p2.id
114 GROUP BY c.id, p.x,p.y,p.z, u.username, c.landing_tick, c.info,u.defense_points
115 ORDER BY c.landing_tick DESC
116 })or print $DBH->errstr;
117 $query->execute or print $DBH->errstr;
120 while (my $call = $query->fetchrow_hashref){
121 $call->{ODD} = $i % 2;
125 $BODY->param(Calls => \@calls);