]> ruin.nu Git - ndwebbie.git/blobdiff - lib/NDWeb/Scans.pm
Add Full fleet from Military scan
[ndwebbie.git] / lib / NDWeb / Scans.pm
index bb05e99408d6bbe1cb69aea55b30a29f220f4df4..f2661498c9d585fb638a291a9dd25372c915f2d4 100644 (file)
@@ -24,7 +24,7 @@ require Exporter;
 
 our @ISA = qw/Exporter/;
 
-our @EXPORT = qw/parseMilScan doMilScan/;
+our @EXPORT = qw/parseMilScan doMilScan doPlanetScan/;
 
 my %classes = (Fighter => 'Fi', Corvette => 'Co', Frigate => 'Fr', Destroyer => 'De', Cruiser => 'Cr', Battleship => 'Bs', Structure => 'St', Roids => 'Ro', Resources => 'Re', '-' => '-');
 
@@ -33,13 +33,16 @@ sub parseMilScan ($) {
        my @fleets;
 
        while ($file =~ m{<th class="center">([^<]+)</th>}g) {
-               push @fleets, {name => $1, ships => []};
+               push @fleets, {name => $1, mission => 'Military', ships => []};
        }
+       push @fleets, {name => 'Military', mission => 'Full fleet', ships => []};
 
+       my $total = 0;
        while ($file =~ m{<tr><td class="left">([^<]+)</td>(.+?)</tr>}g) {
                my $ship = $1;
                next if $ship eq 'Total Ships';
                my $amounts = $2;
+               my $tot_amount = 0;
                my $i = 0;
                while ($amounts =~ m{<td class="center">([\d,]+)</td>}g) {
                        my $fleet = $fleets[$i];
@@ -48,11 +51,18 @@ sub parseMilScan ($) {
                        if ($ship eq 'Total Visible Ships') {
                                $fleet->{amount} = $amount;
                        } elsif ($amount > 0) {
+                               $tot_amount += $amount;
+                               $total += $amount;
                                push @{$fleet->{ships}}, {ship => $ship, amount => $amount};
                        }
                        ++$i;
                }
+
+               if ($tot_amount > 0) {
+                       push @{$fleets[4]->{ships}}, {ship => $ship, amount => $tot_amount};
+               }
        }
+       $fleets[4]->{amount} = $total;
 
        return @fleets;
 }
@@ -70,8 +80,8 @@ sub doMilScan ($$$) {
 
        my @fleets = parseMilScan($file);
        for my $fleet (@fleets) {
-               next if $fleet->{amount} == 0;
-               $addfleet->execute($fleet->{name},$scan->{type},$scan->{pid}
+               next if $fleet->{amount} == 0 && $fleet->{mission} eq 'Military';
+               $addfleet->execute($fleet->{name},$fleet->{mission},$scan->{pid}
                        ,$scan->{tick}, $fleet->{amount});
                my ($id) = $addfleet->fetchrow_array;
                $fleetscan->execute($id,$scan->{id}) or die $dbh->errstr;
@@ -81,4 +91,32 @@ sub doMilScan ($$$) {
        }
 }
 
+my $addplanetscan_sql = q{INSERT INTO planet_scans
+       (id,tick,pid,metal_roids,metal,crystal_roids,crystal,eonium_roids,eonium
+               ,agents,guards,light,medium,heavy,hidden)
+       VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)};
+
+sub doPlanetScan ($$$) {
+       my ($dbh, $scan,$file) = @_;
+
+       my $addplanetscan = $dbh->prepare_cached($addplanetscan_sql);
+
+       my @values = ($scan->{id},$scan->{tick},$scan->{pid});
+       $file =~ s/(\d),(\d)/$1$2/g;
+
+       while($file =~ m{"center">(Metal|Crystal|Eonium)</td>\D+(\d+)\D+([\d,]+)}g){
+               push @values,$2,$3;
+       }
+       if($file =~ m{Security\ Guards .+? "center">(\d+)</td>
+                       .+? "center">(\d+)</td>}sx){
+               push @values,$1,$2;
+       }
+       if($file =~ m{<td class="center">([A-Z][a-z]+)</td><td class="center">([A-Z][a-z]+)</td><td class="center">([A-Z][a-z]+)</td>}){
+               push @values,$1,$2,$3;
+       }
+       if($file =~ m{<span class="superhighlight">([\d,]+)</span>}){
+               push @values,$1;
+       }
+       $addplanetscan->execute(@values);
+}