From 708fc49a28aaa95ca3ef4efce4174c055c90214d Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 19 Apr 2012 21:29:42 -0600 Subject: [PATCH] Slight change to beginning planets. Also a test script adding more. --- bin/util/new_starters.pl | 101 ++++++++++++++++++++++++ lib/Lacuna/DB/Result/Empire.pm | 1 + lib/Lacuna/DB/Result/Map/Body/Planet.pm | 5 +- 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 bin/util/new_starters.pl diff --git a/bin/util/new_starters.pl b/bin/util/new_starters.pl new file mode 100644 index 00000000..16f2da1f --- /dev/null +++ b/bin/util/new_starters.pl @@ -0,0 +1,101 @@ +# Setting more starter planets in the center zones. More likely, the closer to 0,0 the body is. +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; +$|=1; +our $quiet; +GetOptions( + 'quiet' => \$quiet, +); + + +out('Started'); +my $start = time; + +out('Loading DB'); +our $db = Lacuna->db; + +out('Reviewing planets'); +my $planets_rs = $db->resultset('Lacuna::DB::Result::Map::Body'); +my @planets = $planets_rs->search( { + empire_id => undef, + orbit => {'!=' => 8}, + size => {'>=' => 30}, + size => {'<=' => 50}, + } + )->get_column('id')->all; +out('Found '.scalar @planets.' planets.'); +my $old_s = 0; my $new_s = 0; my $unch = 0; +foreach my $id (@planets) { + my $planet = $planets_rs->find($id); + next unless ($planet->get_type eq 'habitable planet'); + next unless ($planet->zone ~~ ['1|1','1|-1','-1|1','-1|-1','0|0','0|1','1|0','-1|0','0|-1']); + + my $orbit = $planet->orbit; + my $start_val = 80 - sqrt($planet->y**2 + $planet->x**2)/10; + if ($orbit == 3) { + $start_val = int(0.9 * $start_val); + } + elsif ($orbit == 4) { + $start_val = int(0.7 * $start_val); + } + elsif ($orbit == 5 or $orbit == 6) { + $start_val = int(0.6 * $start_val); + } + elsif ($orbit == 1 or $orbit == 7) { + $start_val = int(0.4 * $start_val); + } + my $start_enb = (randint(0,99) < $start_val) ? 1 : 0; + my $old_val = $planet->usable_as_starter; + my $old_enb = $planet->usable_as_starter_enabled; + +# If old start, then leave alone + if ($old_enb) { + $old_s++; + out( sprintf("%30s OL:%4d-%d nv:%2d-%d o:%s (%4d,%4d) Z:%5s %s", + $planet->name, + $old_val, $old_enb, + $start_val, $start_enb, + $planet->orbit, + $planet->x, $planet->y, + $planet->zone, + $planet->get_type, + )); + } + elsif ($start_enb) { + $new_s++; + out( sprintf("%30s oo:%4d-%d NN:%2d-%d o:%s (%4d,%4d) Z:%5s %s", + $planet->name, + $old_val, $old_enb, + $start_val, $start_enb, + $planet->orbit, + $planet->x, $planet->y, + $planet->zone, + $planet->get_type, + )); + } + else { + $unch++; + } +} + +my $finish = time; +out('Finished'); +out((($finish - $start)/60)." minutes have elapsed"); +out(sprintf("%6d Planets checked, %6d added, %6d old, %6d unch", scalar @planets, $new_s, $old_s, $unch)); + + +############### +## SUBROUTINES +############### + +sub out { + my $message = shift; + unless ($quiet) { + say format_date(DateTime->now), " ", $message; + } +} diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index 9da52c3b..8c1b9d70 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -507,6 +507,7 @@ sub find_home_planet { my %search = ( usable_as_starter_enabled => 1, orbit => { between => [ $self->min_orbit, $self->max_orbit] }, + empire_id => undef, ); # determine search area diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 714183ed..487095a7 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -140,7 +140,10 @@ sub sanitize { Lacuna->db->resultset('Lacuna::DB::Result::MercenaryMarket')->search({body_id => $self->id})->delete_all; Lacuna->db->resultset('Lacuna::DB::Result::Probes')->search({body_id => $self->id})->delete; $self->empire_id(undef); - if ($self->get_type eq 'habitable planet' && $self->size >= 40 && $self->size <= 50 && $self->zone ~~ ['1|1','1|-1','-1|1','-1|-1','0|0','0|1','1|0','-1|0','0|-1']) { + if ($self->get_type eq 'habitable planet' && + $self->size >= 40 && $self->size <= 50 && + $self->orbit != 8 && + $self->zone ~~ ['1|1','1|-1','-1|1','-1|-1','0|0','0|1','1|0','-1|0','0|-1']) { $self->usable_as_starter_enabled(1); } $self->update; -- 2.54.0