diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 4d936e04..cd085240 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -675,6 +675,60 @@ sub found_colony { return $self; } +sub convert_to_station{ + my ($self, $empire) = @_; + $self->empire_id($empire->id); + $self->empire($empire); + $self->usable_as_starter_enabled(0); + $self->last_tick(DateTime->now); + $self->update; + + # award medal + my $type = ref $self; + $type =~ s/^.*::(\w\d+)$/$1/; + $empire->add_medal($type); + + # add command building + my $command = Lacuna->db->resultset('Lacuna::DB::Result::Building')->new({ + x => 0, + y => 0, + class => 'Lacuna::DB::Result::Building::Module::StationCommand', + }); + $self->build_building($command); + $command->finish_upgrade; + + # add parliament + my $parliament = Lacuna->db->resultset('Lacuna::DB::Result::Building')->new({ + x => -1, + y => 0, + class => 'Lacuna::DB::Result::Building::Module::Parliament', + }); + $self->build_building($parliament); + $command->finish_upgrade; + + # add warehouse + my $warehouse = Lacuna->db->resultset('Lacuna::DB::Result::Building')->new({ + x => 1, + y => 0, + class => 'Lacuna::DB::Result::Building::Module::Warehouse', + }); + $self->build_building($warehouse); + $command->finish_upgrade; + + # add starting resources + $self->tick; + $self->add_algae(2500); + $self->add_energy(2500); + $self->add_water(2500); + $self->add_ore(2500); + $self->update; + + # newsworthy + $self->add_news(100,'%s deployed a space station at %s.', $empire->name, $self->name); + + return $self; +} + has total_ore_concentration => ( is => 'ro', lazy => 1, diff --git a/lib/Lacuna/DB/Result/Ships/ColonyShip.pm b/lib/Lacuna/DB/Result/Ships/ColonyShip.pm index e2be787b..aa1732aa 100644 --- a/lib/Lacuna/DB/Result/Ships/ColonyShip.pm +++ b/lib/Lacuna/DB/Result/Ships/ColonyShip.pm @@ -21,6 +21,7 @@ use constant build_tags => ['Colonization']; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Uninhabited"; +with "Lacuna::Role::Ship::Send::SpendNextColonyCost"; with "Lacuna::Role::Ship::Arrive::TriggerDefense"; with "Lacuna::Role::Ship::Arrive::Colonize"; diff --git a/lib/Lacuna/DB/Result/Ships/ShortRangeColonyShip.pm b/lib/Lacuna/DB/Result/Ships/ShortRangeColonyShip.pm index 3814885a..6ef06450 100644 --- a/lib/Lacuna/DB/Result/Ships/ShortRangeColonyShip.pm +++ b/lib/Lacuna/DB/Result/Ships/ShortRangeColonyShip.pm @@ -21,6 +21,7 @@ use constant build_tags => ['Colonization']; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Uninhabited"; +with "Lacuna::Role::Ship::Send::SpendNextColonyCost"; with "Lacuna::Role::Ship::Arrive::TriggerDefense"; with "Lacuna::Role::Ship::Arrive::Colonize"; diff --git a/lib/Lacuna/DB/Result/Ships/SpaceStation.pm b/lib/Lacuna/DB/Result/Ships/SpaceStation.pm index fd6c3fc8..563e7794 100644 --- a/lib/Lacuna/DB/Result/Ships/SpaceStation.pm +++ b/lib/Lacuna/DB/Result/Ships/SpaceStation.pm @@ -20,8 +20,10 @@ use constant pilotable => 1; use constant build_tags => [qw(War Intelligence)]; use constant type_formatted => 'Space Station Hull'; -with 'Lacuna::Role::Ship::Send::NotAllowed'; +with "Lacuna::Role::Ship::Send::Planet"; with 'Lacuna::Role::Ship::Send::Uninhabited'; +with "Lacuna::Role::Ship::Send::SpendNextColonyCost"; +with "Lacuna::Role::Ship::Arrive::ConvertToStation"; no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/Role/Ship/Arrive/Colonize.pm b/lib/Lacuna/Role/Ship/Arrive/Colonize.pm index c9ee4352..be135be5 100644 --- a/lib/Lacuna/Role/Ship/Arrive/Colonize.pm +++ b/lib/Lacuna/Role/Ship/Arrive/Colonize.pm @@ -3,11 +3,6 @@ package Lacuna::Role::Ship::Arrive::Colonize; use strict; use Moose::Role; -after turn_around => sub { - my $self = shift; - $self->body->add_happiness($self->payload->{colony_cost})->update; -}; - after handle_arrival_procedures => sub { my ($self) = @_; @@ -56,18 +51,7 @@ after can_send_to_target => sub { my $empire = $self->body->empire; confess [1009, 'Can only be sent to habitable planets.'] if ($target->isa('Lacuna::DB::Result::Map::Body::Planet::GasGiant') && $empire->university_level < 19); confess [ 1009, 'Your species cannot survive on that planet.' ] if ($empire->university_level < 18 && ($target->orbit > $empire->max_orbit || $target->orbit < $empire->min_orbit)); - my $next_colony_cost = $empire->next_colony_cost; - confess [ 1011, 'You do not have enough happiness to colonize another planet. You need '.$next_colony_cost.' happiness.', [$next_colony_cost]] unless ( $self->body->happiness > $next_colony_cost); return 1; }; -after send => sub { - my $self = shift; - return if ($self->direction eq 'in'); - my $next_colony_cost = $self->body->empire->next_colony_cost(-1); - $self->body->spend_happiness($next_colony_cost)->update; - $self->payload({ colony_cost => $next_colony_cost }); - $self->update; -}; - 1; diff --git a/lib/Lacuna/Role/Ship/Arrive/ConvertToStation.pm b/lib/Lacuna/Role/Ship/Arrive/ConvertToStation.pm new file mode 100644 index 00000000..f9e15555 --- /dev/null +++ b/lib/Lacuna/Role/Ship/Arrive/ConvertToStation.pm @@ -0,0 +1,50 @@ +package Lacuna::Role::Ship::Arrive::ConvertToStation; + +use strict; +use Moose::Role; + +after handle_arrival_procedures => sub { + my ($self) = @_; + + # we're coming home + return if ($self->direction eq 'in'); + + # can't convert because it's already taken + my $empire = $self->body->empire; + my $planet = $self->foreign_body; + if ($planet->is_locked || $planet->empire_id) { + $empire->send_predefined_message( + tags => ['Alert'], + filename => 'cannot_convert_to_station.txt', + params => [$planet->x, $planet->y, $planet->name, $planet->name], + ); + } + + # can't convert because it's claimed + elsif ($planet->is_claimed && $planet->is_claimed != $empire->id) { + my $claimer = $planet->claimed_by; + $empire->send_predefined_message( + tags => ['Alert'], + filename => 'cannot_convert_to_station_staked.txt', + params => [$planet->x, $planet->y, $planet->name, $claimer->id, $claimer->name, $planet->name], + ); + } + + # let's claim this for our very own! + else { + $planet->lock; + $planet->convert_to_station($empire); + $empire->send_predefined_message( + tags => ['Alert'], + filename => 'station_founded.txt', + params => [$planet->id, $planet->name, $planet->name], + ); + $empire->is_isolationist(0); + $empire->update; + $self->delete; + confess [-1]; + } +}; + + +1; diff --git a/lib/Lacuna/Role/Ship/Send/SpendNextColonyCost.pm b/lib/Lacuna/Role/Ship/Send/SpendNextColonyCost.pm new file mode 100644 index 00000000..63fea3d1 --- /dev/null +++ b/lib/Lacuna/Role/Ship/Send/SpendNextColonyCost.pm @@ -0,0 +1,28 @@ +package Lacuna::Role::Ship::Send::SpendNextColonyCost; + +use strict; +use Moose::Role; + +after turn_around => sub { + my $self = shift; + $self->body->add_happiness($self->payload->{colony_cost})->update; +}; + +after can_send_to_target => sub { + my ($self, $target) = @_; + my $empire = $self->body->empire; + my $next_colony_cost = $empire->next_colony_cost; + confess [ 1011, 'You do not have enough happiness to colonize another planet. You need '.$next_colony_cost.' happiness.', [$next_colony_cost]] unless ( $self->body->happiness > $next_colony_cost); + return 1; +}; + +after send => sub { + my $self = shift; + return if ($self->direction eq 'in'); + my $next_colony_cost = $self->body->empire->next_colony_cost(-1); + $self->body->spend_happiness($next_colony_cost)->update; + $self->payload({ colony_cost => $next_colony_cost }); + $self->update; +}; + +1; diff --git a/var/messages/cannot_convert_to_station.txt b/var/messages/cannot_convert_to_station.txt new file mode 100644 index 00000000..9fd03e20 --- /dev/null +++ b/var/messages/cannot_convert_to_station.txt @@ -0,0 +1,5 @@ +Coming Home +~~~ +We arrived at {Starmap %s %s %s} and found that it had already been colonized. We were forced to turn around and come home. We're on our way now. + +%s Station Mission Commander diff --git a/var/messages/cannot_convert_to_station_staked.txt b/var/messages/cannot_convert_to_station_staked.txt new file mode 100644 index 00000000..38608bd5 --- /dev/null +++ b/var/messages/cannot_convert_to_station_staked.txt @@ -0,0 +1,7 @@ +Coming Home +~~~ +We arrived at {Starmap %s %s %s} and found that it had already been claimed by {Empire %s %s}. Their Stake prevented us from landing, so we had no choice but to turn back. + +Regards, + +%s Station Mission Commander diff --git a/var/messages/station_founded.txt b/var/messages/station_founded.txt new file mode 100644 index 00000000..0b92f60c --- /dev/null +++ b/var/messages/station_founded.txt @@ -0,0 +1,7 @@ +Station Operational +~~~ +We have established the station at {Planet %s %s} as you requested. Awaiting Parliamentary delegates. + +Regards, + +%s Station Mission Commander diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 997e0664..67ad8938 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -7,6 +7,7 @@ - API: Running spy missions require the new captchas. - API: Added send_fleet() to spaceport to allow sending multiple ships to a single target at once. This requires a valid captcha. - API: Added mission_count to spy status. + - Fix: Formatting problem with trade accepted. 2.4700 - Rule: Spies now have a minimum recovery time of 1 hour.