X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=raids.pl;h=b131fe575239db3e7c4d295055f646efc5deaa4b;hb=354c2fb813a139fb08476b6d0e7f30308091038a;hp=ee38de30b18e25d216a7cab9420f3f2e16394345;hpb=2b422881a5d25958c939a31a90d50e0ad2ccfdd6;p=ndwebbie.git diff --git a/raids.pl b/raids.pl index ee38de3..b131fe5 100644 --- a/raids.pl +++ b/raids.pl @@ -18,80 +18,14 @@ #**************************************************************************/ use strict; +use warnings FATAL => 'all'; +no warnings qw(uninitialized); use POSIX; our $BODY; our $DBH; our $LOG; our $XML; - -sub generateClaimXml { - my ($raid, $from, $target) = @_; - - my ($timestamp) = $DBH->selectrow_array("SELECT MAX(modified)::timestamp AS modified FROM raid_targets"); - $BODY->param(Timestamp => $timestamp); - if ($target){ - $target = "r.id = $target"; - $_ = listTargets(); - chop; - $BODY->param(TargetList => $_); - }else{ - $target = "r.raid = $raid->{id}"; - } - - if ($from){ - $from = "AND modified > '$from'"; - } - my $targets = $DBH->prepare(qq{SELECT r.id,r.planet FROM raid_targets r WHERE $target $from}); - $targets->execute; - my $claims = $DBH->prepare(qq{ SELECT username,joinable,launched FROM raid_claims - NATURAL JOIN users WHERE target = ? AND wave = ?}); - my @targets; - while (my $target = $targets->fetchrow_hashref){ - my %target; - $target{Id} = $target->{id}; - $target{Coords} = $target->{id}; - my @waves; - for (my $i = 1; $i <= $raid->{waves}; $i++){ - my %wave; - $wave{Id} = $i; - $claims->execute($target->{id},$i); - my $joinable = 0; - my $claimers; - if ($claims->rows != 0){ - my $owner = 0; - my @claimers; - while (my $claim = $claims->fetchrow_hashref){ - $owner = 1 if ($ND::USER eq $claim->{username}); - $joinable = 1 if ($claim->{joinable}); - $claim->{username} .= '*' if ($claim->{launched}); - push @claimers,$claim->{username}; - } - $claimers = join '/', @claimers; - if ($owner){ - $wave{Command} = 'Unclaim'; - if ($raid->{released_coords}){ - $target{Coords} = $DBH->selectrow_array('SELECT coords(x,y,z) FROM current_planet_stats WHERE id = ?',undef,$target->{planet}); - } - }elsif ($joinable){ - $wave{Command} = 'Join'; - }else{ - $wave{Command} = 'none'; - } - }else{ - #if (!isset($planet) || ($target->value/$planet->value > 0.4 || $target->score/$planet->score > 0.4)) - $wave{Command} = 'Claim'; - } - $wave{Claimers} = $claimers; - $wave{Joinable} = $joinable; - push @waves,\%wave; - } - $target{Waves} = \@waves; - push @targets,\%target; - } - $BODY->param(Targets => \@targets); -} - my $raid; if (param('raid') =~ /^(\d+)$/){ 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 = ?)}); @@ -158,18 +92,15 @@ if ($XML && $raid && param('cmd') eq 'update' ){ } if ($XML && param('cmd') eq 'gettargets' ){ $_ = listTargets(); - chop; $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){ @@ -191,6 +122,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); @@ -202,6 +135,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}; @@ -213,8 +171,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;