3 /***************************************************************************
4 * Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 ***************************************************************************/
26 use DBD::Pg qw(:pg_types);
29 use lib "$FindBin::Bin/../lib";
33 our $dbh = ND::DB::DB();
37 my $query = $dbh->prepare(q{INSERT INTO raids (tick,waves,message)
38 VALUES(tick() + 10,3,'Retal raid') RETURNING (id)});
40 my $raid = $query->fetchrow_array;
46 $dbh->do(q{INSERT INTO raid_access (raid,gid) VALUES(?,2)}
49 my $addtarget = $dbh->prepare(q{INSERT INTO raid_targets(raid,planet,comment)
52 my $incs = $dbh->prepare(q{SELECT pid,array_agg(i.eta) AS eta,array_agg(amount) AS amount
53 ,array_agg(shiptype) AS type,array_agg(fleet) AS name,array_agg(c.landing_tick) AS landing
55 JOIN incomings i ON i.call = c.id
56 WHERe NOT c.covered AND c.landing_tick BETWEEN tick() AND tick() + 6
57 AND c.landing_tick + GREATEST(i.eta,7) > tick() + 10
62 while (my $inc = $incs->fetchrow_hashref){
64 for my $eta (@{$inc->{eta}}){
65 my $amount = shift @{$inc->{amount}};
66 my $type = shift @{$inc->{type}};
67 my $name = shift @{$inc->{name}};
68 my $landing = shift @{$inc->{landing}};
69 my $back = $landing + $eta;
70 $comment .= "$name: ETA=$eta Amount=$amount Type:'$type' Landing tick=$landing Estimated back:$back\n";
72 $addtarget->execute($raid,$inc->{pid},$comment);