diff --git a/docs/Body.pod b/docs/Body.pod index c8f4afae..2306c4f0 100644 --- a/docs/Body.pod +++ b/docs/Body.pod @@ -34,7 +34,13 @@ B You should probably B call this method directly, as it is a wast "name" : "Earthlings", "alignment" : "ally", # can be 'ally','self', or 'hostile' "is_isolationist" : 1 - } + }, + "station" : { # only shows up if this planet is under the influence of a space station + "id" : "id-goes-here", + "x" : 143, + "y" : -27, + "name" : "The Death Star" + }, --------- if you own the planet the data below will be included --------- @@ -67,13 +73,8 @@ B You should probably B call this method directly, as it is a wast }, ... ], - "station" : { # only shows up if this planet is under the influence of a space station - "id" : "id-goes-here", - "x" : 143, - "y" : -27, - "name" : "The Death Star" - }, - # ----- if the body is a station the follwing information will be included + + ----- if the body is a station the follwing information will be included "alliance" : { "id" : "id-goes-here", "name" : "Imperial Empire" diff --git a/lib/Lacuna/DB/Result/Laws.pm b/lib/Lacuna/DB/Result/Laws.pm index e9a8005f..6aa057ca 100644 --- a/lib/Lacuna/DB/Result/Laws.pm +++ b/lib/Lacuna/DB/Result/Laws.pm @@ -33,14 +33,41 @@ sub sqlt_deploy_hook { before delete => sub { my $self = shift; - # notify about repeal + $self->notify_about_law('parliament_law_repealed.txt'); }; after insert => sub { my $self = shift; - # notify about act + $self->notify_about_law('parliament_law_enacted.txt'); }; +sub notify_about_law { + my ($self, $filename) = @_; + if ($self->star_id) { + $self->notify_stellar_inhabitants($self->star, $filename); + } + else { + my $stars = $self->station->stars; + while (my $star = $stars->next) { + $self->notify_stellar_inhabitants($star, $filename); + } + } +} + +sub notify_stellar_inhabitants { + my ($self, $star, $filename) = @_; + my $planets = $star->bodies->search({empire_id => {'!=' => undef } }); + my $station = $self->station; + my $from = $station->alliance->leader; + while (my $planet = $planets->next) { + $planet->empire->send_predefined_message( + filename => $filename, + from => $from, + params => [$self->name, $station->name.'('.$station->x.','.$station->y.')', $planet->name, $self->description], + ); + } +} + sub get_status { my ($self, $empire) = @_; my $out = { diff --git a/lib/Lacuna/DB/Result/Laws/Jurisdiction.pm b/lib/Lacuna/DB/Result/Laws/Jurisdiction.pm new file mode 100644 index 00000000..140dca2f --- /dev/null +++ b/lib/Lacuna/DB/Result/Laws/Jurisdiction.pm @@ -0,0 +1,23 @@ +package Lacuna::DB::Result::Laws::Jurisdiction; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Laws'; + +before delete => sub { + my $self = shift; + my $star = $self->star; + $star->station_id(undef); + $star->update; +}; + +before insert => sub { + my $self = shift; + my $star = $self->star; + $star->station_id($self->station_id); + $star->update; +}; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Laws/Writ.pm b/lib/Lacuna/DB/Result/Laws/Writ.pm index 51d02a0d..acb777d9 100644 --- a/lib/Lacuna/DB/Result/Laws/Writ.pm +++ b/lib/Lacuna/DB/Result/Laws/Writ.pm @@ -5,6 +5,5 @@ use utf8; no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Laws'; - no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm index 006f0504..a6777aa4 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm @@ -144,8 +144,11 @@ has range_of_influence => ( ); sub in_range_of_influence { - my ($self, $target) = @_; - confess [1009, 'Target is not in the station\'s range of influence.']; + my ($self, $star) = @_; + if ($self->calculate_distance_to_target($star) > $self->range_of_influence) { + confess [1009, 'That star is not in the station\'s range of influence.']; + } + return 1; } diff --git a/lib/Lacuna/DB/Result/Propositions/SeizeStar.pm b/lib/Lacuna/DB/Result/Propositions/SeizeStar.pm new file mode 100644 index 00000000..1bf612cc --- /dev/null +++ b/lib/Lacuna/DB/Result/Propositions/SeizeStar.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Propositions::SeizeStar; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Propositions'; + +before pass => sub { + my ($self) = @_; + my $station = $self->station; + my $star = Lacuna->db->resultset('Lacuna::DB::Result::Map::Star')->find($self->scratch->{star_id}); + if (!$star->station_id) { + my $law = Lacuna->db->resultset('Lacuna::DB::Result::Laws')->new({ + name => $self->name, + description => $self->description, + type => 'Jurisdiction', + station_id => $self->station_id, + star_id => $star->id, + }); + $law->star($star); + $law->insert; + } + else { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the star was already controlled by another station, effectively nullifying the vote.'); + } +}; + +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 c6cb155e..3235d4ae 100644 --- a/lib/Lacuna/RPC/Building/Parliament.pm +++ b/lib/Lacuna/RPC/Building/Parliament.pm @@ -176,7 +176,48 @@ sub propose_transfer_station_ownership { }; } -__PACKAGE__->register_rpc_method_names(qw(propose_transfer_station_ownership view_propositions view_laws cast_vote propose_fire_bfg propose_writ)); +sub propose_seize_star { + my ($self, $session_id, $building_id, $star_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 >= 7) { + confess [1013, 'Parliament must be level 7 to transfer station ownership.',7]; + } + unless ($star_id) { + confess [1002, 'Must specify a star id to seize.']; + } + my $star = Lacuna->db->resultset('Lacuna::DB::Result::Map::Star')->find($star_id); + unless (defined $star) { + confess [1002, 'Could not find the star.']; + } + unless ($star->station_id) { + confess [1009, 'That star is already controlled by a station.']; + } + $building->body->in_range_of_influence($star); + unless ($building->body->influence_remaining > 0) { + confess [1009, 'You do not have enough influence to control another star.']; + } + my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ + type => 'SeizeStar', + name => 'Seize '.$star->name, + description => 'Seize control of '.$star->name.' ('.$star->x.','.$star->y.'), and apply all present laws to said star and its inhabitants.', + scratch => { star_id => $star->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(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 ef4fabd1..43403f36 100644 --- a/t/Parliament.t +++ b/t/Parliament.t @@ -59,6 +59,9 @@ is($result->{result}{laws}[0]{name}, 'Do the big thing.', 'writ enacted'); $result = $tester->post('parliament', 'propose_transfer_station_ownership', [$session_id, $par->id]); is($result->{error}{data}, 6, 'transfering ownership of station requires level 6 parliament'); +$result = $tester->post('parliament', 'propose_seize_star', [$session_id, $par->id]); +is($result->{error}{data}, 7, 'transfering ownership of station requires level 7 parliament'); + $result = $tester->post('parliament', 'propose_fire_bfg', [$session_id, $par->id]); is($result->{error}{data}, 30, 'firing bfg requires level 30 parliament'); diff --git a/var/messages/parliament_law_enacted.txt b/var/messages/parliament_law_enacted.txt new file mode 100644 index 00000000..1b21aa5c --- /dev/null +++ b/var/messages/parliament_law_enacted.txt @@ -0,0 +1,5 @@ +Law: %s +~~~ +A new law from the station %s has been passed which affects your planet %s. Here are the particulars: + +%s \ No newline at end of file diff --git a/var/messages/parliament_law_repealed.txt b/var/messages/parliament_law_repealed.txt new file mode 100644 index 00000000..587208d6 --- /dev/null +++ b/var/messages/parliament_law_repealed.txt @@ -0,0 +1,5 @@ +Repeal: %s +~~~ +A law from the station %s has been repealed, so it no longer affects your planet %s. Here were the particulars: + +%s \ No newline at end of file diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index a2a155e1..4a9c4782 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -5,7 +5,8 @@ - API: Added "station" element to the status of bodies and probed stars. - API: Added "alliance" and "influence" elements to the status of bodies that are space stations. - API: Added proposing enacting writs at Parliament level 4. - - API: Added transfering ownership of stations at Parliament level 5. + - API: Added transfering ownership of stations at Parliament level 6. + - API: Added seizing control of stars at Parliament level 7. - API: Added proposing firing the station's BFG at Parliament level 30. - API: Anyone can now view the laws passed by a space station, by simply calling view_laws() on the parliament. - API: The Mercenaries Guild API has been corrected.