From 9e6b8cccac91f24f2f2ee89d0a913eb270353557 Mon Sep 17 00:00:00 2001 From: Mark Lemming Date: Wed, 16 Jan 2013 23:43:30 -0700 Subject: [PATCH] Fixed renaming stars, and moving a space station drops out of range stars. --- bin/util/fix_seizure.pl | 105 ++++++++++++++++++ .../DB/Result/Propositions/RenameStar.pm | 19 ++++ lib/Lacuna/RPC/Building/BlackHoleGenerator.pm | 90 +++++++++++---- var/messages/planet_moved.txt | 3 +- var/www/public/changes.txt | 2 + 5 files changed, 199 insertions(+), 20 deletions(-) create mode 100644 bin/util/fix_seizure.pl diff --git a/bin/util/fix_seizure.pl b/bin/util/fix_seizure.pl new file mode 100644 index 00000000..97507a25 --- /dev/null +++ b/bin/util/fix_seizure.pl @@ -0,0 +1,105 @@ +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('Getting Seized Stars'); +my %seized_stars = map { $_->id => 1 } $db->resultset('Map::Star')->search({ + station_id => {'!=' => undef}, + }); + +my $laws = $db->resultset('Lacuna::DB::Result::Laws')->search({ + type => 'Jurisdiction', + }); + +while ( my $law = $laws->next) { + my $station = $db->resultset('Map::Body')->find($law->station_id); + if ($station) { + if ($station->in_range_of_influence($law->star)) { + my $star = $law->star; + if ($seized_stars{$law->star_id} == 1) { + my $name = 'Seize '.$star->name; + my $desc = 'Seize control of {Starmap '.$star->x.' '.$star->y.' '.$star->name.'} by {Planet '.$station->id.' '. + $station->name.'}, and apply all present laws to said star and its inhabitants.', + $seized_stars{$law->star_id} = 2; + if ($law->name ne $name or $law->description ne $desc) { + out($name." - ".$desc."."); + $seized_stars{$law->star_id} = 3; + $law->name($name); + $law->description($desc); + $law->update; + } + } + else { + out("Law #".$law->id." is a duplicate from ".$law->station_id."."); + $law->delete; + } + } + else { + out("Law #".$law->id." of ".$law->station_id." is for out of range star".$law->star_id."."); + $seized_stars{$law->star_id} = -1; + $law->delete; + } + } + else { + out("Law #".$law->id." is attached to non-station ".$law->station_id."."); + $seized_stars{$law->star_id} = -2; + $law->delete; + } +} + +for my $star_id (sort keys %seized_stars) { + if ($seized_stars{$star_id} == -2) { + out($star_id." was seized by a bogus law."); + } + elsif ($seized_stars{$star_id} == -1) { + out($star_id." was out of range."); + } + elsif ($seized_stars{$star_id} == 1) { + out($star_id." needs a law to be inserted."); + my $star = $db->resultset('Map::Star')->search({ + id => $star_id, + }); + my $station = $db->resultset('Map::Body')->find($star->station_id); + my $law = Lacuna->db->resultset('Lacuna::DB::Result::Laws')->new({ + name => 'Seize '.$star->name, + description => 'Seize control of {Starmap '.$star->x.' '.$star->y.' '.$star->name.'} by {Planet '.$station->id.' '. + $station->name.'}, and apply all present laws to said star and its inhabitants.', + type => 'Jurisdiction', + station_id => $station->id, + star_id => $star->id, + }); + } + elsif ($seized_stars{$star_id} == 2) { + out($star_id." was in no need of change."); + } + elsif ($seized_stars{$star_id} == 3) { + out($star_id." needed the name and desc to be updated."); + } +} + +############### +## SUBROUTINES +############### + +sub out { + my $message = shift; + unless ($quiet) { + say format_date(DateTime->now), " ", $message; + } +} diff --git a/lib/Lacuna/DB/Result/Propositions/RenameStar.pm b/lib/Lacuna/DB/Result/Propositions/RenameStar.pm index 659e2040..15696d6f 100644 --- a/lib/Lacuna/DB/Result/Propositions/RenameStar.pm +++ b/lib/Lacuna/DB/Result/Propositions/RenameStar.pm @@ -19,6 +19,25 @@ before pass => sub { else { $star->name($name); $star->update; + my $elaw = $station->laws->search({type => 'Jurisdiction', star_id => $star->id})->single; + if ($elaw) { + $elaw->name('Seize '.$name); + $elaw->description('Seize control of {Starmap '.$star->x.' '.$star->y.' '.$name.'} by {Planet '.$station->id.' '. + $station->name.'}, and apply all present laws to said star and its inhabitants.'); + $elaw->update; + } + else { + my $law = Lacuna->db->resultset('Lacuna::DB::Result::Laws')->new({ + name => 'Seize '.$name, + description => 'Seize control of {Starmap '.$star->x.' '.$star->y.' '.$name.'} by {Planet '.$station->id.' '. + $station->name.'}, and apply all present laws to said star and its inhabitants.', + type => 'Jurisdiction', + station_id => $station->id, + star_id => $star->id, + }); + $law->star($star); + $law->insert; + } } }; diff --git a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm index 9e13a7d1..83318ae7 100644 --- a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm +++ b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm @@ -187,6 +187,7 @@ sub find_target { unless ($target_params->{zone} ~~ @zones) { confess [ 1002, 'Could not find '.$target_word.' zone.']; } +#Need to find all non-seized via better DB call. my @bodies = Lacuna->db->resultset('Map::Body')->search( { 'me.zone' => $target_params->{zone}, @@ -865,7 +866,6 @@ sub make_orbit_array { } sub bhg_swap { - # Needs to make sure SS have influence range redone. my ($body, $target) = @_; my $return; my $old_data = { @@ -929,21 +929,35 @@ sub bhg_swap { } } $target->recalc_chains; # Recalc all chains + if ($new_data->{type} eq 'space station') { + drop_stars_beyond_range($target); + } } if (defined($target->empire)) { + my $mbody = Lacuna->db + ->resultset('Lacuna::DB::Result::Map::Body') + ->find($target->id); + my $fbody = Lacuna->db + ->resultset('Lacuna::DB::Result::Map::Body') + ->find($body->id); + my $mess = sprintf("{Starmap %s %s %s} at %s/%s in orbit %s around {Starmap %s %s %s}", + $fbody->x, $fbody->y, $fbody->name, + $fbody->x, $fbody->y, $fbody->orbit, + $fbody->star->x, $fbody->star->y, $fbody->star->name); $target->empire->send_predefined_message( tags => ['Alert'], filename => 'planet_moved.txt', params => [ - $target->x, - $target->y, - $target->name, - $target->x, - $target->y, - $target->orbit, - $target->star->x, - $target->star->y, - $target->star->name, + $mbody->x, + $mbody->y, + $mbody->name, + $mbody->x, + $mbody->y, + $mbody->orbit, + $mbody->star->x, + $mbody->star->y, + $mbody->star->name, + $mess, ], ); } @@ -959,20 +973,45 @@ sub bhg_swap { } } $body->recalc_chains; # Recalc all chains + if ($body->get_type eq 'space station') { + drop_stars_beyond_range($target); + } } if (defined($body->empire)) { + my $mbody = Lacuna->db + ->resultset('Lacuna::DB::Result::Map::Body') + ->find($body->id); + my $mess; + unless ($new_data->{type} eq "empty") { + my $fbody = Lacuna->db + ->resultset('Lacuna::DB::Result::Map::Body') + ->find($target->id); + $mess = sprintf("{Starmap %s %s %s} took our place at %s/%s in orbit %s around {Starmap %s %s %s}.", + $fbody->x, $fbody->y, $fbody->name, + $fbody->x, $fbody->y, $fbody->orbit, + $fbody->star->x, $fbody->star->y, $fbody->star->name); + } + else { + my $star = Lacuna->db-> + resultset('Lacuna::DB::Result::Map::Star')->find($old_data->{star_id}); + $mess = sprintf("There is now an empty orbit at %s/%s in orbit %s around {Starmap %s %s %s}", + $old_data->{x}, $old_data->{y}, $old_data->{orbit}, + $star->x, $star->y, $star->name); + } $body->empire->send_predefined_message( tags => ['Alert'], filename => 'planet_moved.txt', - params => [$body->x, - $body->y, - $body->name, - $body->x, - $body->y, - $body->orbit, - $body->star->x, - $body->star->y, - $body->star->name, + params => [ + $mbody->x, + $mbody->y, + $mbody->name, + $mbody->x, + $mbody->y, + $mbody->orbit, + $mbody->star->x, + $mbody->star->y, + $mbody->star->name, + $mess, ], ); } @@ -988,6 +1027,19 @@ sub bhg_swap { }; } +sub drop_stars_beyond_range { + my ($station) = @_; + + return 0 if ($station->get_type ne 'space station'); + my $laws = $station->laws->search({type => 'Jurisdiction'}); + while (my $law = $laws->next) { + unless ($station->in_range_of_influence($law->star)) { + $law->delete; + } + } + return 1; +} + sub bhg_make_planet { my ($building, $body) = @_; my $class; diff --git a/var/messages/planet_moved.txt b/var/messages/planet_moved.txt index 0a4afd79..54ae860a 100644 --- a/var/messages/planet_moved.txt +++ b/var/messages/planet_moved.txt @@ -1,6 +1,7 @@ We have moved! ~~~ -A blackhole generator must have moved {Starmap %s %s %s} to %s/%s in orbit %s around {Starmap %s %s %s}. +A blackhole generator has moved {Starmap %s %s %s} to %s/%s in orbit %s around {Starmap %s %s %s}! +%s Regards, diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 8eecc1a4..13c77460 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -2,6 +2,8 @@ - Fix: Fissure Sealers were sending extra email on home arrival. - Add: Cult of the Fissure added into code base. - Fix: Snarks will actually hit planet instead of doing a flyby. + - Fix: Renaming a star will update the seizure law. + - Fix: A moved space station will lose jurisdiction of stars out of range. 3.0877: - Fix: Shipyard,Intelligence,ThemePark work time now correctly updated -- 2.51.2