From f63d86da36763540a6d42b851fc6041125d99f84 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 10 Mar 2011 15:11:44 -0600 Subject: [PATCH] better record keeping for stations --- lib/Lacuna/DB/Result/Empire.pm | 2 +- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 13 +++++++++---- lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm | 3 ++- lib/Lacuna/Role/Ship/Arrive/ConvertToStation.pm | 9 +++++++++ .../cannot_convert_to_station_no_alliance.txt | 5 +++++ 5 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 var/messages/cannot_convert_to_station_no_alliance.txt diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index 58e2c80f..240df825 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -689,7 +689,7 @@ has count_probed_stars => ( }, ); -before 'delete' => sub { +before delete => sub { my ($self) = @_; Lacuna->db->resultset('Lacuna::DB::Result::Invite')->search({ -or => {invitee_id => $self->id, inviter_id => $self->id }})->delete; $self->probes->delete; diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 2b6fd52e..e3b20f5b 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -107,6 +107,7 @@ sub sanitize { foreach my $attribute (@attributes) { $self->$attribute(0); } + $self->alliance_id(undef); $self->plans->delete; $self->glyphs->delete; my $incoming = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search({foreign_body_id => $self->id}); @@ -677,10 +678,14 @@ sub found_colony { sub convert_to_station{ my ($self, $empire) = @_; + $self->size(3); + $self->plots_available(0); $self->empire_id($empire->id); $self->empire($empire); $self->usable_as_starter_enabled(0); $self->last_tick(DateTime->now); + $self->alliance_id($self->empire->alliance_id); + $self->class('Lacuna::DB::Result::Map::Body::Planet::Station'); $self->update; # award medal @@ -718,9 +723,6 @@ sub convert_to_station{ $self->build_building($warehouse); $command->finish_upgrade; - # convert to station - $self->class('Lacuna::DB::Result::Map::Body::Planet::Station'); - # add starting resources $self->tick; $self->add_algae(2500); @@ -832,7 +834,10 @@ sub recalc_stats { } # deal with plot usage - my $max_plots = $self->size + $pantheon_of_hagness + $station_command; + my $max_plots = $self->size + $pantheon_of_hagness; + if ($self->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) { + $max_plots = $stats{size} = $station_command * 3; + } if ($self->isa('Lacuna::DB::Result::Map::Body::Planet::GasGiant')) { $max_plots = $gas_giant_platforms < $max_plots ? $gas_giant_platforms : $max_plots; } diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm index 8a6a49c6..77478f3f 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm @@ -7,11 +7,12 @@ extends 'Lacuna::DB::Result::Map::Body::Planet'; use constant image => 'station'; -after abandon => sub { +after sanitize => sub { my $self = shift; $self->update({ size => randint(1,10), class => 'Lacuna::DB::Result::Map::Body::Asteroid::A'.randint(1,20), + alliance_id => undef, }); }; diff --git a/lib/Lacuna/Role/Ship/Arrive/ConvertToStation.pm b/lib/Lacuna/Role/Ship/Arrive/ConvertToStation.pm index f9e15555..f14b03f0 100644 --- a/lib/Lacuna/Role/Ship/Arrive/ConvertToStation.pm +++ b/lib/Lacuna/Role/Ship/Arrive/ConvertToStation.pm @@ -30,6 +30,15 @@ after handle_arrival_procedures => sub { ); } + # can't convert because not in an alliance + elsif (!$empire->alliance_id) { + $empire->send_predefined_message( + tags => ['Alert'], + filename => 'cannot_convert_to_station_no_alliance.txt', + params => [$planet->x, $planet->y, $planet->name, $planet->name], + ); + } + # let's claim this for our very own! else { $planet->lock; diff --git a/var/messages/cannot_convert_to_station_no_alliance.txt b/var/messages/cannot_convert_to_station_no_alliance.txt new file mode 100644 index 00000000..7749e1a3 --- /dev/null +++ b/var/messages/cannot_convert_to_station_no_alliance.txt @@ -0,0 +1,5 @@ +Coming Home +~~~ +We arrived at {Starmap %s %s %s}, but received a message from within your government saying that you had left the alliance, and therefore setting up a space station would be illegal. Confused, we were forced to turn around and come home. We're on our way now. + +%s Station Mission Commander -- 2.51.2