diff --git a/docs/Parliament.pod b/docs/Parliament.pod index 3d6a72dc..cba8629c 100644 --- a/docs/Parliament.pod +++ b/docs/Parliament.pod @@ -91,12 +91,6 @@ Returns a list of the stars in the jurisdiction of this space station. "y" : -27, "name" : "The Death Star" }, - "bodies" : [ # only added if a probe is present - { - same data as get_status() on /body - }, - ... - ] }, ... ] @@ -112,6 +106,68 @@ The unique id of the parliament. +=head2 get_bodies_for_star_in_jurisdiction (session_id, building_id, star_id ) + +Returns a list of the bodies for a star in the jurisdiction of the space station. + + { + "status" : { ... }, + "bodies" : [ + { + same data as get_status() on /body + }, + ... + ] + } + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id of the parliament. + +=head3 star_id + +The unique id of a star in jurisdiction. See c. + + + + +=head2 get_mining_platforms_for_asteroid_in_jurisdiction (session_id, building_id, asteroid_id ) + +Returns a list of the platforms for an asteroid in the jurisdiction of the space station. + + { + "status" : { ... }, + "platforms" : [ + { + "id" : "id-goes-here", + "empire" : { + "id" : "id-goes-here", + "name" : "Klingons" + } + }, + ... + ] + } + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id of the parliament. + +=head3 asteroid_id + +The unique id of an asteroid in jurisdiction. See c. + + + + =head2 cast_vote ( session_id, building_id, proposition_id, vote ) @@ -465,6 +521,43 @@ The unique id of the parliament. +=head2 propose_evict_mining_platform ( session_id, building_id, platform_id ) + +Destroys a mining platform on an asteroid. Usable a parliament level 14. + + { + "status" : { ... }, + "proposition" : { + "id" : "id-goes-here", + "name" : "Evict Bjoran Mining Platform", + "description" : "Evict a mining platform on Big Rock that is controlled by Bjoran.", + "votes_needed" : 7, + "votes_yes" : 0, + "votes_no" : 0, + "status" : "Pending", + "date_ends" : "01 31 2010 13:09:05 +0600", + "proposed_by" : { + "id" : "id-goes-here", + "name" : "Klingons", + } + } + } + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id of the parliament. + +=head3 platform_id + +The unique id of a mining platform. See C. + + + + =head2 propose_fire_bfg ( session_id, building_id, target_x, target_y, reason ) diff --git a/lib/Lacuna/DB/Result/Propositions/EvictMiningPlatform.pm b/lib/Lacuna/DB/Result/Propositions/EvictMiningPlatform.pm new file mode 100644 index 00000000..04427246 --- /dev/null +++ b/lib/Lacuna/DB/Result/Propositions/EvictMiningPlatform.pm @@ -0,0 +1,32 @@ +package Lacuna::DB::Result::Propositions::EvictMiningPlatform; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Propositions'; + +before pass => sub { + my ($self) = @_; + my $platform = Lacuna->db->resultset('Lacuna::DB::Result::MiningPlatforms')->find($self->scratch->{platform_id}); + my $station = $self->station; + my $bodies = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body'); + my $asteroid = $bodies->find($self->scratch->{asteroid_id}); + my $name = $self->scratch->{name}; + if (! defined $platform) { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the platform had already been destroyed, effectively nullifying the vote.'); + } + elsif ($self->station_id == $platform->asteroid->star->station_id) { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the asteroid was no longer under the jurisdiction of this station, effectively nullifying the vote.'); + } + else { + $platform->planet->empire->send_predefined_message( + filename => 'parliament_evict_mining_platform.txt', + params => [$station->alliance->name, $platform->asteroid->x, $platform->asteroid->y, $platform->asteroid->name], + from => $station->alliance->leader, + ); + $platform->planet->get_building_of_class('Lacuna::DB::Result::Building::Ore::Ministry')->remove_platform($platform); + } +}; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/RPC/Building/Parliament.pm b/lib/Lacuna/RPC/Building/Parliament.pm index a8a17ee0..b17531b6 100644 --- a/lib/Lacuna/RPC/Building/Parliament.pm +++ b/lib/Lacuna/RPC/Building/Parliament.pm @@ -37,7 +37,7 @@ sub get_stars_in_jurisdiction { my @out; my $stars = $building->body->stars; while (my $star = $stars->next) { - push @out, $star->get_status($empire, 1); + push @out, $star->get_status; } return { status => $self->format_status($empire, $building->body), @@ -45,6 +45,57 @@ sub get_stars_in_jurisdiction { }; } +sub get_bodies_for_star_in_jurisdiction { + my ($self, $session_id, $building_id, $star_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + my $building = $self->get_building($empire, $building_id); + unless ($star_id) { + confess [1002, 'You have to specify a star id.']; + } + my $star = $building->body->stars->find($star_id); + my @out; + my $bodies = $star->bodies; + while (my $body = $bodies->next) { + push @out, $body->get_status($empire); + } + return { + status => $self->format_status($empire, $building->body), + bodies => \@out, + }; +} + +sub get_mining_platforms_for_asteroid_in_jurisdiction { + my ($self, $session_id, $building_id, $asteroid_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + my $building = $self->get_building($empire, $building_id); + my @out; + my @star_ids = $building->body->stars->get_column('id')->all; + unless ($asteroid_id) { + confess [1002, 'You must specify an asteroid id.']; + } + my $asteroid = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->search({ id => $asteroid_id }); + unless (defined $asteroid) { + confess [1002, 'Asteroid not found.']; + } + unless ($asteroid->star->station_id == $building->body_id) { + confess [1009, 'That asteroid is not in your jurisdiction.']; + } + my $platforms = Lacuna->db->resultset('Lacuna::DB::Result::MiningPlatforms')->search({asteroid_id => $asteroid->id}); + while (my $platform = $platforms->next) { + push @out, { + id => $platform->id, + empire => { + name => $platform->planet->empire->name, + id => $platform->planet->empire->id, + } + }; + } + return { + status => $self->format_status($empire, $building->body), + platforms => \@out, + }; +} + sub view_laws { my ($self, $session_id, $body_id) = @_; my $empire = $self->get_empire_by_session($session_id); @@ -407,7 +458,43 @@ sub propose_members_only_mining_rights { }; } -__PACKAGE__->register_rpc_method_names(qw(propose_members_only_mining_rights propose_rename_asteroid propose_broadcast_on_network19 get_stars_in_jurisdiction propose_rename_star propose_repeal_law propose_seize_star propose_transfer_station_ownership view_propositions view_laws cast_vote propose_fire_bfg propose_writ)); +sub propose_evict_mining_platform { + my ($self, $session_id, $building_id, $platform_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + if ($empire->current_session->is_sitter) { + confess [1015, 'Sitters cannot create propositions.']; + } + my $building = $self->get_building($empire, $building_id); + unless ($building->level >= 14) { + confess [1013, 'Parliament must be level 14 to evict a mining platform.',14]; + } + unless ($platform_id) { + confess [1002, 'You must specify a mining platform id.']; + } + my $platform = Lacuna->db->resultset('Lacuna::DB::Result::MiningPlatforms')->find($platform_id); + unless (defined $platform) { + confess [1002, 'Platform not found.']; + } + unless ($platform->asteroid->star->station_id == $building->body_id) { + confess [1009, 'That platform is not in your jurisdiction.']; + } + my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ + type => 'EvictMiningPlatform', + name => 'Evict '.$platform->planet->empire->name.' Mining Platform', + description => 'Evict a mining platform on '.$platform->asteroid->name.' controlled by '.$platform->planet->empire->name.'.', + scratch => { platform_id => $platform_id }, + proposed_by_id => $empire->id, + }); + $proposition->station($building->body); + $proposition->proposed_by($empire); + $proposition->insert; + return { + status => $self->format_status($empire, $building->body), + proposition => $proposition->get_status($empire), + }; +} + +__PACKAGE__->register_rpc_method_names(qw(get_bodies_for_star_in_jurisdiction get_mining_platforms_for_asteroid_in_jurisdiction propose_evict_mining_platform propose_members_only_mining_rights propose_rename_asteroid propose_broadcast_on_network19 get_stars_in_jurisdiction propose_rename_star propose_repeal_law propose_seize_star propose_transfer_station_ownership view_propositions view_laws cast_vote propose_fire_bfg propose_writ)); no Moose; __PACKAGE__->meta->make_immutable; diff --git a/t/Parliament.t b/t/Parliament.t index d81b0623..3a87a8b2 100644 --- a/t/Parliament.t +++ b/t/Parliament.t @@ -80,6 +80,9 @@ is($result->{error}{data}, 12, 'renaming asteroid requires level 12 parliament') $result = $tester->post('parliament', 'propose_members_only_mining_rights', [$session_id, $par->id]); is($result->{error}{data}, 13, 'members mining rights requires level 13 parliament'); +$result = $tester->post('parliament', 'propose_evict_mining_platform', [$session_id, $par->id]); +is($result->{error}{data}, 14, 'evict mining platform requires level 14 parliament'); + $result = $tester->post('parliament', 'propose_fire_bfg', [$session_id, $par->id]); is($result->{error}{data}, 25, 'firing bfg requires level 25 parliament'); diff --git a/var/messages/parliament_evict_mining_platform.txt b/var/messages/parliament_evict_mining_platform.txt new file mode 100644 index 00000000..3f16c324 --- /dev/null +++ b/var/messages/parliament_evict_mining_platform.txt @@ -0,0 +1,3 @@ +Mining Platform Evicted +~~~ +%s has voted to evict your mining platform from {Starmap %s %s %s}. \ No newline at end of file diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index aee4d20d..bfc7322e 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -22,6 +22,7 @@ - API: Added broadcasting on Network 19 at parliament level 9. - API: Added renaming asteroids at parliament level 12. - API: Added members only mining rights at parliament level 13. + - API: Added evicting mining platforms at parliament level 14. - API: Added proposing firing the station's BFG at Parliament level 25. - API: Anyone can now view the laws passed by a space station, by simply calling view_laws() on the parliament. - API: The stations list is now populated in the /alliance.view_profile() method.