From 59acb1279e8b64df20c319c8007be299f53259a1 Mon Sep 17 00:00:00 2001 From: Mark Lemming Date: Fri, 2 Oct 2015 17:01:15 -0600 Subject: [PATCH] Can wipe by empire, but won't wipe capitols. --- bin/util/wipe_colony.pl | 68 ++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/bin/util/wipe_colony.pl b/bin/util/wipe_colony.pl index 57c80e41..81703940 100755 --- a/bin/util/wipe_colony.pl +++ b/bin/util/wipe_colony.pl @@ -6,18 +6,24 @@ use Lacuna; use Lacuna::Util qw(randint format_date); use Getopt::Long; use JSON; -$|=1; -our $quiet; - my @body_id; +use utf8; + $|=1; + our $quiet; + my @bid; + my @eid; my $sanitize; + binmode STDOUT, ":utf8"; + GetOptions( 'quiet' => \$quiet, - 'body=s@' => \@body_id, + 'body=s@' => \@bid, + 'empire=s@' => \@eid, + 'sanitize' => \$sanitize, ); - die "Usage: perl $0 --body X\n" unless ( @body_id ); + die "Usage: perl $0 --body X or perl $0 --empire X\n" unless ( @bid|@eid); out('Started'); my $start = time; @@ -25,24 +31,50 @@ our $quiet; out('Loading DB'); our $db = Lacuna->db; - for my $body_id (@body_id) { - my $body = $db->resultset('Lacuna::DB::Result::Map::Body')->find($body_id); - printf "Found %d, %s at %d/%d in zone %s\n", $body_id, $body->name, $body->x, $body->y, $body->zone; - unless ($body) { - print "Cannot find body id $body_id\n"; - next; - } - next if ($body->get_type eq 'asteroid'); - my @all_buildings = @{$body->building_cache}; - $body->delete_buildings(\@all_buildings); - $body->sanitize; + if (@eid) { + for my $eid (@eid) { + my @bodies = map { $_->id } $db->resultset('Lacuna::DB::Result::Map::Body')->search({ + empire_id => $eid, + }); + push @bid, @bodies; + } } + clean_off($sanitize, \@bid); + out('Done'); exit; - - ############### ## SUBROUTINES ############### +sub clean_off { + my ($sanitize, $bids) = @_; + + for my $bid (@$bids) { + my $body = $db->resultset('Lacuna::DB::Result::Map::Body')->find($bid); + unless ($body) { + print "Cannot find body id $bid\n"; + next; + } + printf "Found %d, %s at %d/%d in zone %s owned by %d/%s. ", + $bid, $body->name, $body->x, $body->y, $body->zone, + $body->empire_id ? $body->empire_id : 0, + $body->empire_id ? $body->empire->name : ""; + if ($body->empire_id and $body->empire->home_planet_id == $bid) { + print "Capitol, Skip\n"; + next; + } + if ($sanitize) { + print "Clearing!\n"; + } + else { + print "Dry Run check.\n"; + next; + } + next if ($body->get_type eq 'asteroid'); + my @all_buildings = @{$body->building_cache}; + $body->delete_buildings(\@all_buildings); + $body->sanitize; + } +} sub out { my $message = shift; -- 2.54.0