]> ruin.nu Git - ndwebbie.git/blobdiff - lib/NDWeb/Scans.pm
Add Full fleet from Military scan
[ndwebbie.git] / lib / NDWeb / Scans.pm
index cfec2fd5ce4e7eb44441d3f77427a2d223619ffa..f2661498c9d585fb638a291a9dd25372c915f2d4 100644 (file)
@@ -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;