diff --git a/Fleet-Action-Status.txt b/Fleet-Action-Status.txt new file mode 100644 index 00000000..d62942fe --- /dev/null +++ b/Fleet-Action-Status.txt @@ -0,0 +1,11 @@ +Current status of fleet-action code in the API + +Shipyard: + - I am fairly sure that all APIs for the shipyard are complete + +Spaceport: + - All API calls to the Spaceport are working and at least return something sensible + - look at 460_fleet_spaceport.t for example calls to the API + - there are a few minor issues, but these will be easier to test once the UI is working + + diff --git a/docs/SpacePort.pod b/docs/SpacePort.pod index cfa1ac8e..46f17871 100644 --- a/docs/SpacePort.pod +++ b/docs/SpacePort.pod @@ -291,7 +291,8 @@ See above for these options. =head3 RESPONSE { - "number_of_incoming" : 26, + "number_of_incoming_fleets" : 3, + "number_of_incoming_ships" : 25, "incoming" : [ { "id" : "id-goes-here", @@ -815,7 +816,7 @@ that report the B status of '1'. Accepts either fixed arguments or a hash of named parameters - ( session_id, building_id ) + ( session_id, building_id, fleet_id, quantity ) ( parameter_hash ) =head3 session_id (required) @@ -920,7 +921,7 @@ The unique id of the planet that the spies are on and ship will be dispatched fr =head3 to_body_id The unique id of the planet that the spies should be sent to. This is a required parameter -if using fixed arguments. With named arguments you can use either C or C +if using fixed arguments. With named arguments you can use either C or C =head3 to_body @@ -989,16 +990,14 @@ if using fixed arguments. With named arguments you can use either C =head3 fleet_id (required) -The unique ID of the fleet. +The unique ID of the fleet. The number of ships from the fleet actually sent will depend +upon the number of spies and the number of passengers each ship can carry. The minimum number +of ships required will be sent. The rest of the fleet will stay at home. =head3 spy_ids (required) An array reference of spy ids to send -=head3 ship_quantity - -The number of ships to send from the fleet (defaults to 1) - =head3 to_body The planet where you want to send spies to. This can be used instead of C if @@ -1015,11 +1014,16 @@ May only be specified with the named arguments calling convention. "fleet" : { "id" : "id-goes-here", "quantity" : 1, - "name" : "CS4", - "hold_size" : 1100, - "speed" : 400, - "type" : "cargo_ship", - "date_arrives" : "01 31 2010 13:09:05 +0600", + "task" : "Travelling", + "date_arrives" : "02 12 2012 12:08:33 +0000", + "details" : { + "name" : "CS4", + "can_recall" : 0, + "hold_size" : 1100, + "speed" : 400, + "type" : "cargo_ship", + "date_available" : "01 31 2010 13:09:05 +0600", + ... ... }, "spies_sent" : ["id-goes-here","id-goes-here","id-goes-here"], # should be identical to "spy_ids" diff --git a/lib/Lacuna/DB/Result/Fleet.pm b/lib/Lacuna/DB/Result/Fleet.pm index 0ec48507..bc53da6f 100644 --- a/lib/Lacuna/DB/Result/Fleet.pm +++ b/lib/Lacuna/DB/Result/Fleet.pm @@ -21,7 +21,7 @@ has 'hostile_action' => ( sub has_that_quantity { my ($self, $qty) = @_; - if ($qty < 0 or int($qty) != $qty) { + if (not defined $qty or $qty < 0 or int($qty) != $qty) { confess [1009, 'Quantity must be a positive integer']; } if ($qty > $self->quantity) { diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 195df561..97d30267 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -133,7 +133,7 @@ sub _view_available_fleets { my %out = ( status => $self->format_status($empire), - available => $option eq 'available' ? \@available : \@unavailable, + $option => $option eq 'available' ? \@available : \@unavailable, ); return \%out; @@ -188,7 +188,7 @@ sub send_fleet { $new_fleet->send(target => $target, arrival => $arrival_date); } return { - fleet => $fleet->get_status, + fleet => $new_fleet->get_status, status => $self->format_status($empire), }; } @@ -359,7 +359,6 @@ sub send_spies { spy_ids => shift, }; } - $args->{ship_quantity} = $args->{ship_quantity} || 1; $args->{arrival_date} = {soonest => 1} if not defined $args->{arrival_date}; my $empire = $self->get_empire_by_session($args->{session_id}); @@ -378,7 +377,7 @@ sub send_spies { confess [ 1013, sprintf('%s is an isolationist empire, and must be left alone.',$to_body->empire->name)]; } - unless ($on_body->empire_id == $to_body->empire_id) { + if ($on_body->empire_id != $to_body->empire_id) { $empire->current_session->check_captcha; } @@ -394,9 +393,6 @@ sub send_spies { if ($fleet->berth_level > $max_berth) { confess [1010, "Your spaceport level is not high enough to support a fleet with a Berth Level of ".$fleet->berth_level."."]; } - if ($fleet->quantity < $args->{ship_quantity}) { - confess [1009, "That fleet does not have ".$args->{ship_quantity}." ships in it."]; - } # check size my $spies_to_send = scalar(@{$args->{spy_ids}}); @@ -405,10 +401,6 @@ sub send_spies { confess [1013, "You can't send a fleet with no spies."]; } - if ($fleet->max_occupants * $args->{ship_quantity} < $spies_to_send) { - confess [1010, "That number of ships cannot hold the spies selected."]; - } - # get the spies my @ids_sent; my @ids_not_sent; @@ -437,9 +429,13 @@ sub send_spies { push @ids_not_sent, $spy->id; } } + my $qty = ceil(scalar(@ids_sent) / $fleet->max_occupants); + if ($fleet->quantity < $qty) { + confess [1010, "That fleet is not big enough to hold the spies selected."]; + } if (scalar @ids_sent) { # send it - my $fleet = $fleet->split($args->{ship_quantity}); + $fleet = $fleet->split($qty); $fleet->send( target => $to_body, payload => {spies => \@ids_sent }, # add the spies to the payload when we send, otherwise they'll get added again @@ -784,6 +780,7 @@ sub view_incoming_fleets { } $args->{task} = 'travelling'; + $args->{task_title} = 'incoming'; return $self->_view_fleets($args); } @@ -802,6 +799,7 @@ sub view_orbiting_fleets { } $args->{task} = 'orbiting'; + $args->{task_title} = 'orbiting'; return $self->_view_fleets($args); } @@ -845,7 +843,7 @@ sub view_mining_platforms { sub _view_fleets { my ($self, $args) = @_; - my $empire = $self->get_empire_by_session($args->{session_id}); + my $empire = $self->get_empire_by_session($args->{session_id}); # see all incoming ships from own empire, or from any alliance member # if the target is an allied colony, see all incoming ships dependent upon the highest # level of space-port on the target @@ -858,14 +856,14 @@ sub _view_fleets { task => 'Travelling', direction => 'out', },{ - join => 'body', + prefetch => 'body', }); } if ($args->{task} eq 'orbiting') { $fleet_rs = $fleet_rs->search({ task => ['Orbit','Defend'], },{ - join => 'body', + prefetch => 'body', }); } @@ -893,13 +891,19 @@ sub _view_fleets { $fleet_rs = $fleet_rs->search({ 'body.empire_id' => \@ally_ids }); } my @fleets; + my $no_ships = 0; while (my $fleet = $fleet_rs->next) { push @fleets, $fleet->get_status($target, $status_args); + $no_ships += $fleet->quantity; } my %out = ( status => $self->format_status($empire), - $args->{task} => \@fleets, + $args->{task_title} => \@fleets, ); + if ($args->{task_title} eq 'incoming') { + $out{number_of_incoming_fleets} = scalar(@fleets); + $out{number_of_incoming_ships} = $no_ships; + } return \%out; } diff --git a/t/460_fleet_spaceport.t b/t/460_fleet_spaceport.t index 775e6e76..aab90cb5 100644 --- a/t/460_fleet_spaceport.t +++ b/t/460_fleet_spaceport.t @@ -11,8 +11,8 @@ use DateTime; use TestHelper; -TestHelper->clear_all_test_empires; -diag("Cleared all test empires"); +#TestHelper->clear_all_test_empires; +#diag("Cleared all test empires"); my $tester = TestHelper->new->use_existing_test_empire; my $enemy = TestHelper->new({empire_name => 'TLE Test Enemy'})->use_existing_test_empire; @@ -47,18 +47,30 @@ foreach my $ship (sort keys %{$result->{result}{docked_ships}} ) { ## spaceport - view_all_fleets ## +$result = $tester->post('spaceport','view', [{ + session_id => $test_session_id, + building_id => $test_spaceport->id, +}]); +ok($result->{result}{docked_ships}, "Has docked ships"); +ok($result->{result}{docked_ships}{sweeper} > 1000, "Has sweepers"); + $result = $tester->post('spaceport','view_all_fleets', [{ session_id => $test_session_id, building_id => $test_spaceport->id, paging => {no_paging => 1}, no_status => 1, }]); + +my ($sweepers) = grep {$_->{details}{type} eq 'sweeper'} @{$result->{result}{fleets}}; +ok($sweepers->{quantity} > 1000, "view_all_fleets sweepers"); + $result = $tester->post('spaceport','view_incoming_fleets', [{ session_id => $test_session_id, paging => {no_paging => 1}, target => { body_id => $test_home->id}, no_status => 1, }]); +ok($result->{result}{incoming}, "Has incoming"); $result = $tester->post('spaceport','view_available_fleets', [{ session_id => $test_session_id, @@ -82,22 +94,20 @@ $result = $tester->post('spaceport','send_fleet', [{ quantity => 1, target => { body_id => $test_home->id}, arrival_date => { - month => 12, - date => 25, - hour => 8, + month => 1, + date => 1, + hour => 0, minute => 0, second => 0, }, no_status => 1, }]); -$result = $tester->post('spaceport','view_fleets_travelling', [{ +$result = $tester->post('spaceport','view_travelling_fleets', [{ session_id => $test_session_id, building_id => $test_spaceport->id, no_status => 1, }]); -exit; - $fleets = $test_home->fleets->search({ task => 'Defend', @@ -110,12 +120,9 @@ while (my $fleet = $fleets->next) { quantity => 1, no_status => 1, }]); - exit; - + last; } -exit; - $result = $tester->post('spaceport','view_unavailable_fleets', [{ session_id => $test_session_id, body_id => $test_home->id, @@ -123,13 +130,52 @@ $result = $tester->post('spaceport','view_unavailable_fleets', [{ no_status => 1, }]); -diag Dumper $result; my @unavailable = @{$result->{result}{unavailable}}; for my $fleet (@unavailable) { diag "Unavailable [".$fleet->{id}."][".$fleet->{details}{type}."][".$fleet->{quantity}."][".$fleet->{reason}."]\n"; #diag Dumper $fleet; } +$result = $tester->post('spaceport','view_orbiting_fleets', [{ + session_id => $test_session_id, + target => { body_id => $test_home->id}, +}]); + +$result = $tester->post('spaceport','view_all_fleets', [{ + session_id => $test_session_id, + building_id => $test_spaceport->id, + no_status => 1, +}]); +my @fleets = @{$result->{result}{fleets}}; +($fleet) = grep {$_->{details}{can_scuttle}} @fleets; + +diag "Can scuttle [".$fleet->{details}{type}."]"; + +$result = $tester->post('spaceport','scuttle_fleet', [{ + session_id => $test_session_id, + building_id => $test_spaceport->id, + fleet_id => $fleet->{id}, +}]); + +$result = $tester->post('spaceport', 'prepare_send_spies', [{ + session_id => $test_session_id, + on_body_id => $test_home->id, + to_body => { body_id => $test_home->id}, +}]); + +my $spy = $result->{result}{spies}[0]; +$fleet = $result->{result}{fleets}[0]; + +diag(Dumper($spy)); +diag(Dumper($fleet)); + +$result = $tester->post('spaceport', 'send_spies', [{ + session_id => $test_session_id, + on_body_id => $test_home->id, + to_body_id => $test_home->id, + fleet_id => $fleet->{id}, + spy_ids => [$spy->{id}], +}]); exit; diff --git a/t/TestHelper.pm b/t/TestHelper.pm index 79767704..6bef95c4 100644 --- a/t/TestHelper.pm +++ b/t/TestHelper.pm @@ -242,7 +242,7 @@ sub post { Content => to_json($content), Accept => 'application/json', ); - my $response = from_json($response->content); + $response = from_json($response->content); say "RESPONSE: ".Dumper($response); # sleep 2; return $response; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 4c010840..87372b8f 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,9 +1,9 @@ 4.0001: - Add: Major reworking of ships into fleets. - Mod: Most API calls involving ships have changed, if you use external scripts these will most likely need to be modified. - - Mod: Most other API calls now have the option of named arguments as well as supporting the existing scheme for backwards compatibility + - Mod: Most API calls now have the option of named arguments as well as supporting the existing scheme for backwards compatibility - Mod: A fleet is a collection of ships all having the same attributes and task - - Mod: Where previously you referred to a single ship, you now refer to a fleet + - Mod: Where previously you referred to a single ship, you now refer to a fleet (and perhaps a quantity of ships) - Mod: The maximum level of Shipyard on a colony is now used in calculating a new ships attributes, not the current Shipyard - Mod: 'own' and 'ally' on the incoming report for a Space Station now are in relation to your own empire. - Fix: Fleets sort correctly in type/name order in Space Port view tab @@ -14,6 +14,7 @@ - Fix: UI - Number of docks available now decrements correctly when building multiple ships in Shipyard - Fix: Added description of new ship types in Shipyard - Mod: When sending a fleet you now specify the arrival date/time not the speed + - Mod: Spaceport, when sending spies, you can specify the arrival date/time - Mod: The limit of sending no more than 20 ships in a fleet has been removed. - Mod: Travelling ships not involved in a trade or an attack can be recalled - Mod: Travelling ships not involved in an attack can be scuttled @@ -43,7 +44,12 @@ - done: When ships arrive (fighters to Defend) set their available date to null - done: Travelling ships should be sorted in arrival date order - + +KNOWN BUGS: + - bug: Fleet format currently shows 'Foreign' for all fleets + + + 3.0873: - Mod: Observatory can only abandon a probe it controls. - Add: New Observatory abandon_all_probes API method.