diff --git a/lib/Lacuna/DB/Result/Ships.pm b/lib/Lacuna/DB/Result/Ships.pm index 65c3ef57..8bca9820 100644 --- a/lib/Lacuna/DB/Result/Ships.pm +++ b/lib/Lacuna/DB/Result/Ships.pm @@ -377,7 +377,19 @@ sub send { $self->roundtrip($options{roundtrip} || 0); $self->direction($options{direction} || 'out'); my $arrival = $options{arrival} || DateTime->now->add(seconds=>$self->calculate_travel_time($options{target})); + + my $five_minute = DateTime->now->add(minutes=>5); + if ($arrival < $five_minute) { + $arrival = $five_minute; + } + + my $two_months = DateTime->now->add(days=>60); + if ($arrival > $two_months) { + confess [1009, "Cannot set a speed that will take over 60 days."]; + } + $self->date_available($arrival); + if ($options{target}->isa('Lacuna::DB::Result::Map::Body')) { $self->foreign_body_id($options{target}->id); $self->foreign_body($options{target}); @@ -423,7 +435,7 @@ sub send { $ag_chk += $ships_rs->get_column('number_of_docks')->sum; } - if ($seconds2arrive > 300 && $ag_chk > 1) { # Only consolidate if ships take longer than 20 minutes + if ($seconds2arrive > 180 && $ag_chk > 1) { # Only consolidate if ships take longer than 20 minutes my $payload = $self->payload; # $payload->{debug} = { # old_type => $self->type, diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 2011e28d..6f29ca8c 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -1972,9 +1972,13 @@ sub steal_planet { (grep { $ship->type eq $_ } @{[ 'colony_ship', 'short_range_colony_ship', + 'space_station', ]})) { # Colony ships show from capitol. $ship->body_id($defender_capitol_id); + my $payload = $ship->payload; + $payload->{colony_cost} = 0; + $ship->payload($payload); $ship->update; } else { diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index d5fdfa84..95c7e185 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -222,8 +222,8 @@ sub send_ship { if ($ship->hostile_action) { $empire->current_session->check_captcha; } - $body->add_to_neutral_entry($ship->combat); $ship->send(target => $target); + $body->add_to_neutral_entry($ship->combat); return { ship => $ship->get_status, status => $self->format_status($empire), @@ -279,6 +279,18 @@ sub send_ship_types { my $target = $self->find_target($target_params); my $arrival = $self->find_arrival($arrival_params); + my $five_minute = DateTime->now->add(minutes=>5); + if ($arrival < $five_minute) { + $arrival = $five_minute; +# confess [1009, "Cannot set a speed that will take less than five minutes."]; + } + + my $two_months = DateTime->now->add(days=>60); + if ($arrival > $two_months) { + confess [1009, "Cannot set a speed that will take over 60 days."]; + } + + # calculate the total ships before the expense of any database operations. my $total_ships = 0; map {$total_ships += $_->{quantity}} @$type_params; @@ -334,10 +346,6 @@ sub send_ship_types { #Check speed of ship. If it can not make it to the target in time, fail #If time to target is longer than 60 days, fail. my $seconds_to_target = $ship->calculate_travel_time($target); - if ($seconds_to_target > 5184000) { - confess [1009, "Cannot set a speed that will take 60 days or more."]; - } - my $earliest = DateTime->now->add(seconds=>$seconds_to_target); if ($earliest > $arrival) { confess [1009, "Cannot set a speed earlier than possible arrival time."]; @@ -450,6 +458,11 @@ sub send_fleet { } my @fleet; my $speed = 999999999; + my $distance = $self->body->calculate_distance_to_target($target); + my $max_speed = $distance * 12; # Minimum time to arrive is five minutes + my $min_speed = int($distance/1440 + 0.5); # Max time to arrive is two months + $min_speed = 1 if $min_speed < 1; + my $excavator = 0; for my $ship_id (@$ship_ids) { my $ship = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->find($ship_id); @@ -474,8 +487,12 @@ sub send_fleet { unless ($set_speed >= 0) { confess [1009, 'Set speed cannot be less than zero.']; } + unless ($set_speed >= $min_speed) { + confess [1009, 'Set speed cannot be set so that ships arrive after 60 days.']; + } #If time to target is longer than 60 days, fail. $speed = $set_speed if ($set_speed > 0 && $set_speed < $speed); + $speed = $max_speed if ($speed > $max_speed); my @ret; my $captcha_check = 1; diff --git a/lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm b/lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm index b0547b50..79e8d71f 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm @@ -3,6 +3,7 @@ package Lacuna::Role::Ship::Arrive::DamageBuilding; use strict; use Moose::Role; use Lacuna::Util qw(randint); +use List::Util qw(shuffle); use DateTime; after handle_arrival_procedures => sub { @@ -144,21 +145,22 @@ after handle_arrival_procedures => sub { } } push @{$report}, (['Buildings', scalar @all_builds]); + push @{$report}, (['Name', '% Done']); my %treport; if ( $snarks{snarks}->{count}/4 > scalar @all_builds) { for my $building (@all_builds) { $building->spend_efficiency(100); $building->update; - $treport{"$building->name"} = 100; + my $hash_id = sprintf("%s:%2d/%2d", $building->name, $building->x, $building->y); + $treport{"$hash_id"} = 100; } } else { - my $building; for my $sn_type ("observatory_seeker", "security_ministry_seeker", "spaceport_seeker", "snarks") { my @tbuilds; - if ($snarks{$sn_type}->{count}) { + if (@{$snarks{$sn_type}->{target}}) { for my $tb ( @{$snarks{$sn_type}->{target}}) { my @temp = $body_attacked->get_buildings_of_class($tb); if (@temp) { @@ -170,27 +172,26 @@ after handle_arrival_procedures => sub { @tbuilds = @all_builds; } if ($snarks{$sn_type}->{count}/4 > scalar @tbuilds) { - for $building (@tbuilds) { + for my $building (@tbuilds) { $building->spend_efficiency(100)->update; - $treport{"$building->name"} = 100; + my $hash_id = sprintf("%s:%2d/%2d", $building->name, $building->x, $building->y); + $treport{"$hash_id"} = 100; } } else { - BOOM: for (1..$snarks{$sn_type}->{count}) { + BOOM: for my $cnt (1..$snarks{$sn_type}->{count}) { my $amount = randint(10,70); - ($building) = - sort { - $b->efficiency <=> $a->efficiency || - rand() <=> rand() - } + my ($building) = shuffle grep { ($_->efficiency > 0) } @tbuilds; if ($building) { $building->spend_efficiency($amount)->update; - $treport{"$building->name"} = 100 - $building->efficiency; + my $hash_id = sprintf("%s:%2d/%2d", $building->name, $building->x, $building->y); + $treport{"$hash_id"} = 100 - $building->efficiency; } else { + $treport{"ZZcnt"} = $cnt; last BOOM; } } diff --git a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm index 07242ada..5e3c759c 100644 --- a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm +++ b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm @@ -454,7 +454,8 @@ sub notify_battle_results { } } - $self->body->empire->send_predefined_message( + unless ($self->foreign_body->empire_id && $self->foreign_body->empire->skip_attack_messages) { + $self->foreign_body->empire->send_predefined_message( tags => ['Attack'], filename => 'attack_summary.txt', params => [$self->foreign_body->id, @@ -462,7 +463,17 @@ sub notify_battle_results { ], attachments => { table => $report }, ); -# Send an email to defender as well + } + unless ($self->body->empire_id && $self->body->empire->skip_attack_messages) { + $self->body->empire->send_predefined_message( + tags => ['Attack'], + filename => 'attack_summary.txt', + params => [$self->foreign_body->id, + $self->foreign_body->name, + ], + attachments => { table => $report }, + ); + } if ($self->foreign_body->empire) { $self->foreign_body->add_news(20, diff --git a/var/messages/saw_engaged.txt b/var/messages/saw_engaged.txt deleted file mode 100644 index 5daeaaec..00000000 --- a/var/messages/saw_engaged.txt +++ /dev/null @@ -1,7 +0,0 @@ -SAWs Engaged -~~~ -Our fleet have engaged the SAWs of the following empires while attacking {Planet %s %s}. - -Regards, - -Your Humble Assistant