From 0849915e4828cd4bce1c530f03f389ff5d9599d9 Mon Sep 17 00:00:00 2001 From: Mark Lemming Date: Thu, 26 Mar 2015 16:41:29 -0600 Subject: [PATCH] Skip deleted spies, new util for setting up planets. --- bin/puppet/ship_add.js | 195 +++++++++++++++++++++++++++++++++++++ bin/puppet/ships_insert.pl | 101 +++++++++++++++++++ bin/summarize_spies.pl | 1 + 3 files changed, 297 insertions(+) create mode 100644 bin/puppet/ship_add.js create mode 100644 bin/puppet/ships_insert.pl diff --git a/bin/puppet/ship_add.js b/bin/puppet/ship_add.js new file mode 100644 index 00000000..ad1ccc70 --- /dev/null +++ b/bin/puppet/ship_add.js @@ -0,0 +1,195 @@ +{ + "Alfheim" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Algrim" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Baldur" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Copenhagen" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Donner" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Heimdall" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Fjord 1" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Fjord 2" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Fjord 3" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + }, + { + "combat" : "5000", "hold_size" : "0", "name" : "Bleeder", "number" : "120", + "speed" : "5000", "stealth" : "1000", "type" : "bleeder", "type_human" : "Bleeder" + } + ], + "Fjord 4" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Fjord 5" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Fjord 6" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Fjord 7" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Hogun" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Muspelheim" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Oslo" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Reykjavik" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Sif" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Thor" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Uppsalir" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ], + "Vinland" : [ + { "combat" : "23600", "hold_size" : "0", "name" : "Snark III", "number" : "50", + "speed" : "4510", "stealth" : "13530", "type" : "snark3", "type_human" : "Snark III" + }, + { + "combat" : "34844", "hold_size" : "0", "name" : "Sweeper", "number" : "4000", + "speed" : "11902", "stealth" : "15148", "type" : "sweeper", "type_human" : "Sweeper" + } + ] +} diff --git a/bin/puppet/ships_insert.pl b/bin/puppet/ships_insert.pl new file mode 100644 index 00000000..90729e01 --- /dev/null +++ b/bin/puppet/ships_insert.pl @@ -0,0 +1,101 @@ +use 5.010; +use strict; +use lib '/data/Lacuna-Server/lib'; +use Lacuna::DB; +use Lacuna; +use Lacuna::Util qw(randint format_date); +use Getopt::Long; +use JSON; +use utf8; + + + $|=1; + + our $quiet; + our $config; + our $fill; + our $maintain; + + GetOptions( + 'config=s' => \$config, + 'fill' => \$fill, + 'maintain' => \$maintain, + ); + + die "Must give config\n" unless ($config); + out('Started'); + my $start = DateTime->now; + + out('Loading DB'); + my $builds = get_ships($config); + + for my $body_name (sort keys %$builds) { + my $body = Lacuna->db->resultset('Map::Body')->search( { name => "$body_name" })->first; + for my $shash (@{$builds->{$body_name}}) { + my $to_build = $shash->{number}; + if ($maintain) { + my $current = Lacuna->db->resultset('Ships')->search({ body_id => $body->id, type => $shash->{type} })->count; + $to_build -= $current; + $to_build = 0 if $to_build < 0; + } + if ($fill and $to_build > $body->spaceport->docks_available) { + $to_build = $body->spaceport->docks_available; + } + printf "Adding %s of %s %s to %s\n", $to_build, $shash->{number}, $shash->{type}, $body_name; + for (1..$to_build) { + my $new = $body->ships->new({ + type => $shash->{type}, + name => $shash->{name}, + shipyard_id => "552", + speed => $shash->{speed}, + combat => $shash->{combat}, + stealth => $shash->{stealth}, + hold_size => $shash->{hold_size}, + date_available => DateTime->now, + date_started => DateTime->now, + body_id => $body->id, + task => 'Docked', + })->insert; + } + } + } +exit; + +############### +## SUBROUTINES +############### + +sub out { + my $message = shift; + unless ($quiet) { + say format_date(DateTime->now), " ", $message; + } +} + +sub get_ships { + my ( $data_file ) = @_; + + my $bld_data = get_json($data_file); + unless ($bld_data) { + die "Could not read $data_file\n"; + } + return $bld_data; +} + +sub get_json { + my ($file) = @_; + + if (-e $file) { + my $json = JSON->new->utf8(1); + my $fh; my $lines; + open($fh, "$file") || die "Could not open $file\n"; + $lines = join("", <$fh>); + my $data = $json->decode($lines); + close($fh); + return $data; + } + else { + warn "$file not found!\n"; + } + return 0; +} diff --git a/bin/summarize_spies.pl b/bin/summarize_spies.pl index 3d604777..520f4937 100644 --- a/bin/summarize_spies.pl +++ b/bin/summarize_spies.pl @@ -147,6 +147,7 @@ sub summarize_spies { my $defense_success_rate = ($spy->defense_mission_count) ? 100 * $spy->defense_mission_successes / $spy->defense_mission_count : 0; my $success_rate = $offense_success_rate + $defense_success_rate; my $planet = $db->resultset('Lacuna::DB::Result::Map::Body')->find($spy->from_body_id); + next unless defined $planet; my %spy_data = ( date_stamp => DateTime->now, spy_name => $spy->name, -- 2.51.2