diff --git a/docs/Parliament.pod b/docs/Parliament.pod index c268c876..f74d7c03 100644 --- a/docs/Parliament.pod +++ b/docs/Parliament.pod @@ -446,6 +446,43 @@ A 140 character string that cannot contain special characters or profanity. +=head2 propose_elect_new_leader ( session_id, building_id, to_empire_id ) + +Elect a new leader of the alliance. Only works with Parliament 11 and higher. + + { + "status" : { ... }, + "proposition" : { + "id" : "id-goes-here", + "name" : "Elect New Leader", + "description" : "Elect The Klingon Empire as the new leader of The Federation.", + "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" : "Romulus", + } + } + } + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id of the parliament. + +=head3 to_empire_id + +The unique id of an empire proposed as the new leader of the alliance. The empire must already be a member of the alliance. + + + + =head2 propose_rename_asteroid ( session_id, building_id, asteroid_id, name ) Rename any asteroid in the station's jurisdiction. Usable at parliament level 12. diff --git a/lib/Lacuna/DB/Result/Propositions.pm b/lib/Lacuna/DB/Result/Propositions.pm index 0a736ed2..fc262957 100644 --- a/lib/Lacuna/DB/Result/Propositions.pm +++ b/lib/Lacuna/DB/Result/Propositions.pm @@ -29,6 +29,7 @@ __PACKAGE__->typecast_map(type => { DemolishModule => 'Lacuna::DB::Result::Propositions::DemolishModule', DowngradeModule => 'Lacuna::DB::Result::Propositions::DowngradeModule', EnactWrit => 'Lacuna::DB::Result::Propositions::EnactWrit', + ElectNewLeader => 'Lacuna::DB::Result::Propositions::ElectNewLeader', EvictMiningPlatform => 'Lacuna::DB::Result::Propositions::EvictMiningPlatform', FireBfg => 'Lacuna::DB::Result::Propositions::FireBfg', InstallModule => 'Lacuna::DB::Result::Propositions::InstallModule', diff --git a/lib/Lacuna/DB/Result/Propositions/ElectNewLeader.pm b/lib/Lacuna/DB/Result/Propositions/ElectNewLeader.pm new file mode 100644 index 00000000..5c7828c3 --- /dev/null +++ b/lib/Lacuna/DB/Result/Propositions/ElectNewLeader.pm @@ -0,0 +1,28 @@ +package Lacuna::DB::Result::Propositions::ElectNewLeader; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Propositions'; + +before pass => sub { + my ($self) = @_; + my $station = $self->station; + my $alliance = $station->alliance; + my $new_leader = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->find($self->scratch->{empire_id}); + if (defined $new_leader) { + if ($new_leader->alliance_id == $alliance->id) { + $alliance->leader_id($new_leader->id); + $alliance->update; + } + else { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the elected empire was no longer a member of the alliance, effectively nullifying the vote.'); + } + } + else { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the elected empire no longer existed, 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 986ae81c..3ed9f5c4 100644 --- a/lib/Lacuna/RPC/Building/Parliament.pm +++ b/lib/Lacuna/RPC/Building/Parliament.pm @@ -568,7 +568,44 @@ sub propose_evict_mining_platform { }; } -__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_members_only_colonization propose_rename_asteroid propose_rename_uninhabited 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_elect_new_leader { + my ($self, $session_id, $building_id, $to_empire_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 >= 11) { + confess [1013, 'Parliament must be level 11 to elect a new alliance leader.',11]; + } + unless ($to_empire_id) { + confess [1002, 'Must specify an empire id to elect a new alliance leader.']; + } + my $to_empire = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->find($to_empire_id); + unless (defined $to_empire) { + confess [1002, 'Could not find the empire of the proposed new leader.']; + } + unless ($to_empire->alliance_id == $empire->alliance_id) { + confess [1009, 'That empire is not a member of your alliance.']; + } + my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ + type => 'ElectNewLeader', + name => 'Elect New Leader', + description => 'Elect {Empire '.$to_empire->id.' '.$to_empire->name.'} as the new leader of {Alliance '.$building->body->alliance_id.' '.$building->body->alliance->name.'}.', + scratch => { empire_id => $to_empire->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_members_only_colonization propose_rename_asteroid propose_rename_uninhabited 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 propose_elect_new_leader)); no Moose; __PACKAGE__->meta->make_immutable; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 0c219f00..e6232f57 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,4 +1,5 @@ 3.0500 + - API: Added proposing election of a new alliance leader at Parliament level 11. - API: Added proposing renaming uninhabited planets at Parliament level 17. - API: Added proposing members only colonization at Parliament level 18. - Fix: Police Station docs now show up under Modules instead of Buildings.