diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 32df0717..95db5888 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -779,6 +779,17 @@ sub find_free_space { confess [1009, 'No free space found.']; } +sub has_outgoing_ships { + my ($self, $min) = @_; + my $ships = Lacuna->db->resultset('Ships')->search({ + body_id => $self->id, + task => 'Travelling', + }); + my $count = $ships->count; + return 1 if $count >= $min; + return 0; +} + sub check_for_available_build_space { my ($self, $unclean_x, $unclean_y) = @_; my $x = int( $unclean_x ); diff --git a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm index 15eb118b..e4447765 100644 --- a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm +++ b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm @@ -306,6 +306,10 @@ sub task_chance { if ($return->{throw} > 0) { return $return; } + ($return->{throw}, $return->{reason}) = check_neutral_violation($body, $target, $task); + if ($return->{throw} > 0) { + return $return; + } } unless ( grep { $target_type eq $_ } @{$task->{types}} ) { $return->{throw} = 1009; @@ -401,6 +405,43 @@ sub check_bhg_neutralized { return 0, ""; } +sub check_neutral_violation { + my ($body, $target, $task) = @_; + + my $throw; my $reason; + my $nz_param = Lacuna->config->get('neutral_area'); + return 0,"" unless $nz_param; + return 0 if $body->in_neutral_area; + my $target_in = 0; + if (ref $target eq 'HASH') { + my $tstar = $target->{star}; + $target_in = $tstar->in_neutral_area; + $target = $tstar; + } + else { + $target_in = $target->in_neutral_area; + } + return 0 unless $target_in; + if ($task->{name} eq "Jump Zone" or $task->{name} eq "Swap Places") { + if ( $body->has_outgoing_ships(100) ) { + $throw = 1009; + $reason = sprintf("Colony %s has travelling ships, disallowing a jump to the Neutral Area.", $body->name); + return $throw, $reason; + } + } + elsif ($task->{name} eq "Move System") { + my $bodies = Lacuna->db->resultset('Map::Body')->search({star_id => [ $body->star_id ]}); + while (my $obody = $bodies->next) { + if ( $obody->has_outgoing_ships(100) ) { + $throw = 1009; + $reason = sprintf("Colony %s has travelling ships, disallowing a jump to the Neutral Area.", $obody->name); + return $throw, $reason; + } + } + } + return 0; +} + sub check_starter_zone { my ($body, $target, $task) = @_; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 5931b60a..dd8c7016 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -11,7 +11,8 @@ - Mod: Update ChiselChat. - Mod: Plan list sorting now done more naturally. - Mod: Improve message handling speed (deleting, archiving). - - Mod: spy lists in intel min, merc guild, send-spy tab all use the same ordering. + - Mod: Spy lists in intel min, merc guild, send-spy tab all use the same ordering. + - Mod: Planets can't jump into the neutral zone when it has too many ships in transit. - Add: mass_abandon_excavator and mass_abandon_platform APIs. - Add: Inbox API call added: trash_messages_where. - Add: Add Highest Embassy in your empire to returned get_status.