diff --git a/docs/Development.pod b/docs/Development.pod index 15d09ecb..b93f68fa 100644 --- a/docs/Development.pod +++ b/docs/Development.pod @@ -126,9 +126,15 @@ A session ID, The ID of the development ministry. -=head3 scheduled_id (required) +=head3 scheduled_id (optional) + +The ID, or array of IDs, of the building(s) scheduled to be build/upgraded that you wish to cancel. + +=head3 cancel_all (optional) + +If set to a true value, cancels all builds currently scheduled. -The ID of the building scheduled to be build/upgraded that you wish to cancel. +One of C and C is required. =head3 RESPONSE diff --git a/lib/Lacuna/RPC/Building/Development.pm b/lib/Lacuna/RPC/Building/Development.pm index b009636c..448c55b0 100644 --- a/lib/Lacuna/RPC/Building/Development.pm +++ b/lib/Lacuna/RPC/Building/Development.pm @@ -90,6 +90,8 @@ sub subsidize_one_build { }; } +my %non_cancel = map { $_=>1 } ('Lacuna::DB::Result::Building::DeployedBleeder'); + sub cancel_build { my ($self, $args) = @_; @@ -99,21 +101,39 @@ sub cancel_build { my $session = $self->get_session({session_id => $args->{session_id}, building_id => $args->{building_id} }); my $empire = $session->current_empire; my $building = $session->current_building; - my $scheduled_building = $self->get_building($session,$args->{scheduled_id},nocheck_type=>1); - if (!$scheduled_building) { - confess [1003, "That building does not exist, or is not yours."]; - } - if ($scheduled_building->body_id != $building->body_id) { - confess [1003, "That building is not on the same planet as your development ministry."]; + + my $ids = $args->{scheduled_id}; + if ($ids && not ref $ids) { + $ids = [ $ids ]; } - if (not $scheduled_building->is_upgrading) { - confess [1000, "That building is not currently being ugraded."]; + + my @order; + if ($args->{cancel_all}) { + @order = reverse @{$building->body->builds}; } - my @non_cancel = ('Lacuna::DB::Result::Building::DeployedBleeder'); - if (grep { $scheduled_building->class eq "$_" } @non_cancel) { - confess [1003, "That building can not have an upgrade cancelled."]; + else { + @order = sort { $b->upgrade_ends cmp $a->upgrade_ends } map { + my $scheduled_id = $_; + my $scheduled_building = ref $scheduled_id ? + $scheduled_id : + $self->get_building($session,$scheduled_id,nocheck_type=>1); + + if (!$scheduled_building) { + confess [1003, "That building does not exist, or is not yours."]; + } + if ($scheduled_building->body_id != $building->body_id) { + confess [1003, "That building is not on the same planet as your development ministry."]; + } + if (not $scheduled_building->is_upgrading) { + confess [1000, "That building is not currently being ugraded."]; + } + if ($non_cancel{$scheduled_building->class}) { + confess [1003, "That building can not have an upgrade cancelled."]; + } + $scheduled_building; + } @$ids; } - $scheduled_building->cancel_upgrade; + $_->cancel_upgrade for @order; return $self->view($args->{session_id}, $args->{building_id}); diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index c490441b..e487ee5f 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -3,6 +3,8 @@ - Fix: Some of the numbers in the APIs are now returned as numbers instead of strings. - Mod: Add commas to total cargo in TM and SST. - Fix: Initialize date_created field for spies. + - Mod: Can cancel more than one build at a time via API. + - Add: Cancel All button to dev ministry. 3.0917: - Fix: Recalc stats when building 1+x plans.