From 4b2d75755c65674c40514908e917691ef428c4b2 Mon Sep 17 00:00:00 2001 From: Matthew Musgrove Date: Wed, 23 Mar 2011 23:01:44 -0500 Subject: [PATCH] API: Added recall_all() to spaceport. --- docs/SpacePort.pod | 51 ++++++++++++++++++++++++++-- lib/Lacuna/RPC/Building/SpacePort.pm | 35 ++++++++++++++++++- t/SpacePort.t | 5 ++- var/www/public/changes.txt | 1 + 4 files changed, 88 insertions(+), 4 deletions(-) diff --git a/docs/SpacePort.pod b/docs/SpacePort.pod index cc59d354..9e881c83 100644 --- a/docs/SpacePort.pod +++ b/docs/SpacePort.pod @@ -480,7 +480,7 @@ A hash reference that can contain one of five items to identify a star or body. =head2 recall_ship ( session_id, building_id, ship_id ) -Recalls a ship from allied defense ('Defend' task) to the body of origin. +Recalls an orbiting ship (task of 'Defend' or 'Orbiting') to the body of origin. Throws 1002, 1010. @@ -511,7 +511,7 @@ Throws 1002, 1010. } } -Recalls an orbiting Spy Shuttle ('Orbiting' task) and also fetches as many idle spies as will fit from the planet it was orbiting. +Recalling an orbiting Spy Shuttle also fetches as many idle spies as will fit from the planet it was orbiting. Throws 1002, 1010, 1013. @@ -542,6 +542,53 @@ The unique id of a ship to recall. +=head2 recall_all ( session_id, building_id ) + +Recalls all of this planet's ships that are orbiting (task of 'Defend' or 'Orbiting') to their spaceport of origin. This behaves like C in all other aspects. + +Throws 1002, 1010. + + { + "status" : { ... }, + "ships" : [ + { + "id" : "id-goes-here", + "name" : "F13", + "type_human" : "Fighter", + "type" : "fighter", + "task" : "Travelling", + "speed" : "2000", + "stealth" : "0", + "hold_size" : "0", + "date_started" : "01 31 2010 13:09:05 +0600", + "date_available" : "02 01 2010 10:08:33 +0600", + "date_arrives" : "02 01 2010 10:08:33 +0600", + "from" : { + "id" : "id-goes-here", + "type" : "body", + "name" : "Earth" + }, + "to" : { + "id" : "id-goes-here", + "type" : "star", + "name" : "Sol" + } + }, + ... + ], + } + + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id for the space port. + + + =head2 name_ship ( session_id, building_id, ship_id, name ) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 21d09ffd..164a5694 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -215,6 +215,39 @@ sub recall_ship { } } +sub recall_all { + my ($self, $session_id, $building_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + my $building = $self->get_building($empire, $building_id); + my $ships = $body->ships_orbiting->search(undef)->all; + my @ret; + while(my $ship = $ships->next) { + unless (defined $ship) { + confess [1002, 'Could not locate that ship.']; + } + unless ($ship->body->empire_id == $empire->id) { + confess [1010, 'You do not own that ship.']; + } + my $body = $building->body; + $body->empire($empire); + $ship->can_recall(); + + my $target = $self->find_target({body_id => $ship->foreign_body_id}); + $ship->send( + target => $target, + direction => 'in', + ); + $ship->body->update; + push @ret, { + ship => $ship->get_status, + } + } + return { + ships => \@ret, + status => $self->format_status($empire), + } +} + sub prepare_send_spies { my ($self, $session_id, $on_body_id, $to_body_id) = @_; my $empire = $self->get_empire_by_session($session_id); @@ -681,7 +714,7 @@ around 'view' => sub { return $out; }; -__PACKAGE__->register_rpc_method_names(qw(view_foreign_ships get_ships_for send_ship send_fleet recall_ship recall_spies scuttle_ship name_ship prepare_fetch_spies fetch_spies prepare_send_spies send_spies view_ships_orbiting view_ships_travelling view_all_ships)); +__PACKAGE__->register_rpc_method_names(qw(view_foreign_ships get_ships_for send_ship send_fleet recall_ship recall_all recall_spies scuttle_ship name_ship prepare_fetch_spies fetch_spies prepare_send_spies send_spies view_ships_orbiting view_ships_travelling view_all_ships)); no Moose; diff --git a/t/SpacePort.t b/t/SpacePort.t index 97c9c777..ddb2a23d 100644 --- a/t/SpacePort.t +++ b/t/SpacePort.t @@ -1,5 +1,5 @@ use lib '../lib'; -use Test::More tests => 21; +use Test::More tests => 22; use Test::Deep; use Data::Dumper; use 5.010; @@ -71,6 +71,9 @@ is(ref $result->{result}{orbiting}, 'ARRAY', "can see what ships are orbiting"); $result = $tester->post('spaceport', 'view_ships_orbiting', [$session_id, $spaceport->id]); is(ref $result->{result}{ships_orbiting}, 'ARRAY', "can see orbiting ships"); +$result = $tester->post('spaceport', 'recall_all', [$session_id, $spaceport->id]); +is(ref $result->{result}{ships}, 'ARRAY', 'can call recall-all'); + my $shipyard = Lacuna::db->resultset('Lacuna::DB::Result::Building')->new({ x => 0, y => 2, diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 1c1773c9..c2750d4c 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -3,6 +3,7 @@ - Fix: Spies require 350 cargo space consistently through the API and docs. - API: Changed recallable to orbiting in the spaceport's get_ships_for results. - API: Added view_ships_orbiting() to spaceport to allow viewing the ships orbiting your planet. + - API: Added recall_all() to spaceport. 3.0201 - Add: Changed crater to dent when on space station. -- 2.51.2