X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=raids.pl;h=4480d6bff2a13ba74a3797b3532ba4d0b3b6f268;hb=bb3ed008868592ef478d8432b86a39c293efae2d;hp=535a1bb131e496a211a276c4d0fc653d6cc74ad7;hpb=8d1ec9372fa9786009022fca3503ef3c79974f3e;p=ndwebbie.git diff --git a/raids.pl b/raids.pl index 535a1bb..4480d6b 100644 --- a/raids.pl +++ b/raids.pl @@ -33,7 +33,6 @@ sub generateClaimXml { if ($target){ $target = "r.id = $target"; $_ = listTargets(); - chop; $BODY->param(TargetList => $_); }else{ $target = "r.raid = $raid->{id}"; @@ -156,15 +155,17 @@ if ($XML && $raid && param('cmd') eq 'update' ){ } generateClaimXml($raid,$from); } +if ($XML && param('cmd') eq 'gettargets' ){ + $_ = listTargets(); + $BODY->param(TargetList => $_); +} unless ($XML){ $ND::TEMPLATE->param(TITLE => 'Raids'); - $ND::TEMPLATE->param(HEADER => ''); + #$ND::TEMPLATE->param(HEADER => ''); if ($raid){#We have a raid, so list all targets $BODY->param(Raid => $raid->{id}); - my $ajax = 1; - $ajax = 0 if ($ENV{HTTP_USER_AGENT} =~ /MSIE/); - $BODY->param(Ajax => $ajax); + $BODY->param(Ajax => $ND::AJAX); my $noingal = ''; my $planet; if ($ND::PLANET){ @@ -186,6 +187,8 @@ ORDER BY size}); while (my $target = $targetquery->fetchrow_hashref){ my %target; $target{Id} = $target->{id}; + $target{Race} = $target->{race}; + $target{Ajax} = $ND::AJAX; my $num = pow(10,length($target->{score})-2); $target{Score} = ceil($target->{score}/$num)*$num; $num = pow(10,length($target->{value})-2); @@ -197,6 +200,31 @@ ORDER BY size}); $num = pow(10,length($target->{resvalue})-2); $target{ResValue} = floor($target->{resvalue}/$num)*$num; $target{comment} = parseMarkup($target->{comment}) if ($target->{comment}); + + my $scans = $DBH->prepare(q{SELECT DISTINCT ON (type) type, tick, scan FROM scans + WHERE planet = ? AND type ~ 'Unit|Planet|Military|.* Analysis' AND tick + 24 > tick() + GROUP BY type, tick, scan ORDER BY type ,tick DESC}); + $scans->execute($target->{planet}); + my %scans; + while (my $scan = $scans->fetchrow_hashref){ + $scans{$scan->{type}} = $scan; + } + + my @scans; + for my $type ('Planet','Unit','Military','Surface Analysis','Technology Analysis'){ + next unless exists $scans{$type}; + my $scan = $scans{$type}; + if ($ND::TICK - $scan->{tick} > 5){ + $scan->{scan} =~ s{}{}; + } + if ($type eq 'Planet'){ + $target{PlanetScan} = $scan->{scan}; + next; + } + push @scans,{Scan => $scan->{scan}}; + } + $target{Scans} = \@scans; + my @roids; my @claims; my $size = $target{Size}; @@ -208,8 +236,12 @@ ORDER BY size}); $xp = max(0,floor($roids * 10 * (min(2,$target{Score}/$planet->{score}) + min(2,$target{Value}/$planet->{value})-1))); } push @roids,{Wave => $i, Roids => $roids, XP => $xp}; - push @claims,{Wave => $i, Target => $target{Id}, Command => 'Claim' - , Owner => 1, Raid => $raid->{id}, Joinable => 1}; + if ($ND::AJAX){ + push @claims,{Wave => $i, Target => $target{Id}} + }else{ + push @claims,{Wave => $i, Target => $target{Id}, Command => 'Claim' + , Owner => 1, Raid => $raid->{id}, Joinable => 0}; + } } $target{Roids} = \@roids; $target{Claims} = \@claims;